Load locales data dynamically

This commit is contained in:
ErickSkrauch 2019-05-11 01:23:20 +03:00
parent 22651a7b26
commit bc950a31bc
2 changed files with 6 additions and 34 deletions

View File

@ -3,40 +3,6 @@ import PropTypes from 'prop-types';
import { IntlProvider, addLocaleData } from 'react-intl';
import beLocaleData from 'react-intl/locale-data/be';
import elLocaleData from 'react-intl/locale-data/el';
import enLocaleData from 'react-intl/locale-data/en';
import filLocaleData from 'react-intl/locale-data/fil';
import frLocaleData from 'react-intl/locale-data/fr';
import idLocaleData from 'react-intl/locale-data/id';
import ltLocaleData from 'react-intl/locale-data/lt';
import plLocaleData from 'react-intl/locale-data/pl';
import roLocaleData from 'react-intl/locale-data/ro';
import ruLocaleData from 'react-intl/locale-data/ru';
import slLocaleData from 'react-intl/locale-data/sl';
import srLocaleData from 'react-intl/locale-data/sr';
import ptLocaleData from 'react-intl/locale-data/pt';
import ukLocaleData from 'react-intl/locale-data/uk';
import viLocaleData from 'react-intl/locale-data/vi';
import zhLocaleData from 'react-intl/locale-data/zh';
addLocaleData(beLocaleData);
addLocaleData(elLocaleData);
addLocaleData(enLocaleData);
addLocaleData(filLocaleData);
addLocaleData(frLocaleData);
addLocaleData(idLocaleData);
addLocaleData(ltLocaleData);
addLocaleData(plLocaleData);
addLocaleData(roLocaleData);
addLocaleData(ruLocaleData);
addLocaleData(slLocaleData);
addLocaleData(srLocaleData);
addLocaleData(ptLocaleData);
addLocaleData(ukLocaleData);
addLocaleData(viLocaleData);
addLocaleData(zhLocaleData);
import { SUPPORTED_LANGUAGES, DEFAULT_LANGUAGE } from './params';
import BaseLayout from 'components/BaseLayout';
@ -49,6 +15,9 @@ export default function App({type, payload = {}}) {
}
const { default: messages } = require(`!extended-translations-loader!i18n/${locale}.json`);
const localeData = require(`react-intl/locale-data/${locale}.js`);
addLocaleData(localeData);
const { default: Email } = require(`emails/${type}/index`);
return (

View File

@ -52,6 +52,9 @@ module.exports = (env, { mode = 'development' }) => {
new ContextReplacementPlugin(
/i18n/, new RegExp(`/(${SUPPORTED_LANGUAGES.join('|')})\\.json`)
),
new ContextReplacementPlugin(
/locale-data/, new RegExp(`/(${SUPPORTED_LANGUAGES.join('|')})\\.js`)
),
new HtmlWebpackPlugin({
template: 'src/index.ejs',
favicon: 'src/favicon.ico',