From 98211a7ecf575deadf73a960bd225026aaaee43c Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Fri, 20 May 2016 07:22:19 +0300 Subject: [PATCH] #75: intl polyfill for safari and old ie --- package.json | 1 + src/services/i18n.js | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 75700ca..b4a2639 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "babel-polyfill": "^6.3.14", "classnames": "^2.1.3", "history": "^1.17.0", + "intl": "^1.2.2", "intl-format-cache": "^2.0.4", "intl-messageformat": "^1.1.0", "react": "^15.0.0", diff --git a/src/services/i18n.js b/src/services/i18n.js index 53a301b..3d73b2a 100644 --- a/src/services/i18n.js +++ b/src/services/i18n.js @@ -8,6 +8,9 @@ addLocaleData(ruLocaleData); const SUPPORTED_LANGUAGES = ['ru', 'en']; const DEFAULT_LANGUAGE = 'en'; + +const needPolyfill = !window.Intl; + function getUserLanguages(userSelectedLang = []) { return [].concat(userSelectedLang || []) .concat(navigator.languages || []) @@ -27,7 +30,20 @@ export default { }, require(locale) { - return new Promise(require(`bundle!i18n/${locale}.json`)) - .then((messages) => ({locale, messages})); + const promises = [ + 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})); } };