-
Notifications
You must be signed in to change notification settings - Fork 11
/
i18n.js
35 lines (30 loc) · 1.12 KB
/
i18n.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* i18n.js
*
* This will setup the i18n language files and locale data for your app.
*
* IMPORTANT: This file is used by the internal build
* script `extract-intl`, and must use CommonJS module syntax
* You CANNOT use import/export in this file.
*/
//eslint-disable-line
import '@formatjs/intl-relativetimeformat/polyfill';
const enTranslationMessages = require('./lang/en.json');
export const DEFAULT_LOCALE = 'en';
// prettier-ignore
export const appLocales = [
'en',
];
export const formatTranslationMessages = (locale, messages) => {
const defaultFormattedMessages =
locale !== DEFAULT_LOCALE ? formatTranslationMessages(DEFAULT_LOCALE, enTranslationMessages) : {};
const flattenFormattedMessages = (formattedMessages, key) => {
const formattedMessage =
!messages[key] && locale !== DEFAULT_LOCALE ? defaultFormattedMessages[key] : messages[key];
return Object.assign(formattedMessages, { [key]: formattedMessage });
};
return Object.keys(messages).reduce(flattenFormattedMessages, {});
};
export const translationMessages = {
en: formatTranslationMessages('en', enTranslationMessages)
};