2016-08-18 11:41:13 +02:00
|
|
|
/**
|
|
|
|
* i18n.js
|
|
|
|
*
|
2016-10-13 20:53:33 +02:00
|
|
|
* This will setup the i18n language files and locale data for your plugin.
|
2016-08-18 11:41:13 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-08-14 15:22:42 +02:00
|
|
|
import { addLocaleData } from 'react-intl';
|
|
|
|
import { reduce } from 'lodash';
|
2016-08-18 11:41:13 +02:00
|
|
|
|
2019-04-25 12:19:41 +02:00
|
|
|
// We need to manually import the locales here
|
|
|
|
// because dynamic imports causes webpack to build all the locales
|
|
|
|
// see https://github.com/yahoo/react-intl/issues/1225
|
|
|
|
import ar from 'react-intl/locale-data/ar';
|
2019-12-15 17:57:16 +01:00
|
|
|
import cs from 'react-intl/locale-data/cs';
|
2019-04-25 12:19:41 +02:00
|
|
|
import de from 'react-intl/locale-data/de';
|
|
|
|
import en from 'react-intl/locale-data/en';
|
|
|
|
import es from 'react-intl/locale-data/es';
|
|
|
|
import fr from 'react-intl/locale-data/fr';
|
|
|
|
import it from 'react-intl/locale-data/it';
|
|
|
|
import ja from 'react-intl/locale-data/ja';
|
|
|
|
import ko from 'react-intl/locale-data/ko';
|
|
|
|
import nl from 'react-intl/locale-data/nl';
|
|
|
|
import pl from 'react-intl/locale-data/pl';
|
|
|
|
import pt from 'react-intl/locale-data/pt';
|
|
|
|
import ru from 'react-intl/locale-data/ru';
|
|
|
|
import tr from 'react-intl/locale-data/tr';
|
2019-11-20 17:58:35 +07:00
|
|
|
import vi from 'react-intl/locale-data/vi';
|
2019-04-25 12:19:41 +02:00
|
|
|
import zh from 'react-intl/locale-data/zh';
|
2019-12-30 16:22:25 +01:00
|
|
|
import sk from 'react-intl/locale-data/sk';
|
2016-08-18 11:41:13 +02:00
|
|
|
|
2019-04-25 12:19:41 +02:00
|
|
|
import trads from './translations';
|
2016-08-18 11:41:13 +02:00
|
|
|
|
2019-04-25 12:19:41 +02:00
|
|
|
// We dismiss pt-BR and zh-Hans locales since they are not supported by react-intl
|
|
|
|
const locales = {
|
|
|
|
ar,
|
2019-12-15 17:57:16 +01:00
|
|
|
cs,
|
2019-04-25 12:19:41 +02:00
|
|
|
de,
|
|
|
|
en,
|
|
|
|
es,
|
|
|
|
fr,
|
|
|
|
it,
|
|
|
|
ja,
|
|
|
|
ko,
|
|
|
|
nl,
|
|
|
|
pl,
|
|
|
|
pt,
|
|
|
|
ru,
|
|
|
|
tr,
|
2019-11-20 17:58:35 +07:00
|
|
|
vi,
|
2019-04-25 12:19:41 +02:00
|
|
|
zh,
|
2019-12-30 16:22:25 +01:00
|
|
|
sk,
|
2016-10-13 19:31:29 +02:00
|
|
|
};
|
2019-04-25 12:19:41 +02:00
|
|
|
const languages = Object.keys(trads);
|
2016-10-13 19:31:29 +02:00
|
|
|
|
2017-08-14 15:22:42 +02:00
|
|
|
/**
|
|
|
|
* Dynamically generate `translationsMessages object`.
|
|
|
|
*/
|
2019-04-24 14:32:20 +02:00
|
|
|
const translationMessages = reduce(
|
2017-08-14 15:22:42 +02:00
|
|
|
languages,
|
2019-04-24 14:32:20 +02:00
|
|
|
(result, language) => {
|
|
|
|
const obj = result;
|
2019-04-25 12:19:41 +02:00
|
|
|
obj[language] = trads[language];
|
|
|
|
|
|
|
|
if (locales[language]) {
|
|
|
|
addLocaleData(locales[language]);
|
|
|
|
}
|
|
|
|
|
2019-04-24 14:32:20 +02:00
|
|
|
return obj;
|
|
|
|
},
|
2019-11-20 17:58:35 +07:00
|
|
|
{}
|
2019-04-24 14:32:20 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
export { languages, translationMessages };
|