#75: intl polyfill for safari and old ie

This commit is contained in:
SleepWalker 2016-05-20 07:22:19 +03:00
parent 26cb65f653
commit 98211a7ecf
2 changed files with 19 additions and 2 deletions

View File

@ -19,6 +19,7 @@
"babel-polyfill": "^6.3.14", "babel-polyfill": "^6.3.14",
"classnames": "^2.1.3", "classnames": "^2.1.3",
"history": "^1.17.0", "history": "^1.17.0",
"intl": "^1.2.2",
"intl-format-cache": "^2.0.4", "intl-format-cache": "^2.0.4",
"intl-messageformat": "^1.1.0", "intl-messageformat": "^1.1.0",
"react": "^15.0.0", "react": "^15.0.0",

View File

@ -8,6 +8,9 @@ addLocaleData(ruLocaleData);
const SUPPORTED_LANGUAGES = ['ru', 'en']; const SUPPORTED_LANGUAGES = ['ru', 'en'];
const DEFAULT_LANGUAGE = 'en'; const DEFAULT_LANGUAGE = 'en';
const needPolyfill = !window.Intl;
function getUserLanguages(userSelectedLang = []) { function getUserLanguages(userSelectedLang = []) {
return [].concat(userSelectedLang || []) return [].concat(userSelectedLang || [])
.concat(navigator.languages || []) .concat(navigator.languages || [])
@ -27,7 +30,20 @@ export default {
}, },
require(locale) { require(locale) {
return new Promise(require(`bundle!i18n/${locale}.json`)) const promises = [
.then((messages) => ({locale, messages})); new Promise(require(`bundle!i18n/${locale}.json`))
];
if (needPolyfill) {
promises.push(new Promise((resolve) => {
require.ensure([], () => {
require('intl');
require(`bundle!intl/locale-data/jsonp/${locale}.js`)(resolve);
});
}));
}
return Promise.all(promises)
.then(([messages]) => ({locale, messages}));
} }
}; };