Skip to content

Instantly share code, notes, and snippets.

View fulopdaniel's full-sized avatar

Daniel Fulop fulopdaniel

View GitHub Profile
import { intlShape, injectIntl, defineMessages } from 'react-intl';
const translations = defineMessages({
hello: {
id: 'app.hello_world',
defaultMessage: 'Hello World!',
},
});
class TestComponent extends React.Component {
import { intlShape, injectIntl, defineMessages } from 'react-intl';
const translations = defineMessages({
hello: {
id: 'app.hello_world',
defaultMessage: 'Hello World!',
},
});
class TestComponent extends React.Component {
import { FormattedMessage } from 'react-intl';
class TestComponent extends React.Component {
render() {
return(
<FormattedMessage
id="app.hello_world"
defaultMessage="Hello World!"
/>
import React from 'react';
import ReactDOM from 'react-dom';
import { addLocaleData, IntlProvider } from 'react-intl';
import en from 'react-intl/locale-data/en';
import hu from 'react-intl/locale-data/hu';
import messagesHu from './translations/hu.json';
import messagesEn from './translations/en.json';
addLocaleData([...en, ...hu]);
import { parse } from 'intl-messageformat-parser';
import * as fs from 'fs';
import { sync as globSync } from 'glob';
import { sync as mkdirpSync } from 'mkdirp';
const MESSAGES_PATTERN = './build/messages/**/*.json';
const LANG_DIR = './src/translations/temp/';
const ESCAPED_CHARS = {
'\\' : '\\\\',
"scripts": {
"build:translations": "react-intl-cra './src/**/*.js' -o ./build/messages/messages.json && babel scripts/translate.js | node",
}
import axios from 'axios';
import messagesEn from './src/translations/temp/en.json'; // Import the extracted tokens
const messageKeys = [];
const API_URL = "YOUR API URL HERE";
Object.keys(messagesEn).forEach((message) => {
messageKeys.push(message); // I only send the tokens, not the default messages
});
"scripts": {
"build:translations": "react-intl-cra './src/**/*.js' -o ./build/messages/messages.json && babel scripts/translate.js | node && babel scripts/copyTranslationsToDB.js | node",
},
import axios from 'axios';
import * as fs from 'fs';
import { sync as mkdirpSync } from 'mkdirp';
const supportedLanguages = ['en', 'hu'];
const API_URL = "YOUR API URL";
const LANG_DIR = './src/translations/';
axios.get(API_URL).then(() => {
"scripts": {
"build:translations": "react-intl-cra './src/**/*.js' -o ./build/messages/messages.json && babel scripts/translate.js | node && babel scripts/copyTranslationsToDB.js | node",
"fetch:translations": "babel scripts/fetchTranslationsFromDB.js | node",
}