我正在尝试使用Browserify将React应用程序国际化,并遵循https://github.com/andyearnshaw/Intl.js/的示例。当我试图加载浏览器不支持Intl时应用程序将支持的区域设置时,我尝试这样做:
// Intl polyfill
var areIntlLocalesSupported = require('intl-locales-supported');
var localesMyAppSupports = [
/* list locales here */
'en-US',
'bg-BG',
'zh-Hans-CN',
'ha-Arab',
'fr-FR',
'ru-RU',
'de-DE',
'eu-ES'
];
是否有其他方法来添加将被支持的区域设置?文档中没有更多的例子。事实证明,我不想使用的地区不受支持。
下面是代码的其余部分:
if (global.Intl) {
// Determine if the built-in `Intl` has the locale data we need.
if (!areIntlLocalesSupported(localesMyAppSupports)) {
// `Intl` exists, but it doesn't have the data we need, so load the
// polyfill and replace the constructors with need with the polyfill's.
global.Intl = require('intl');
Intl.NumberFormat = IntlPolyfill.NumberFormat;
Intl.DateTimeFormat = IntlPolyfill.DateTimeFormat;
}
} else {
// No `Intl`, so use and load the polyfill.
global.Intl = require('intl');
require('intl/locale-data/jsonp/en-US.js');
require('intl/locale-data/jsonp/bg-BG.js');
//"zh-Hans-CN": Chinese written in simplified characters as used in China.
require('intl/locale-data/jsonp/zh-Hans-CN.js');
require('intl/locale-data/jsonp/ha-Arab.js');
require('intl/locale-data/jsonp/fr-FR.js');
require('intl/locale-data/jsonp/ru-RU.js');
require('intl/locale-data/jsonp/de-DE.js');
require('intl/locale-data/jsonp/eu-ES.js');
}
发布于 2015-12-17 03:35:26
我们刚刚发现,我需要在内部if块中添加带有locales的require语句,如下所示:
if (!areIntlLocalesSupported(localesMyAppSupports)) {
// `Intl` exists, but it doesn't have the data we need, so load the
// polyfill and replace the constructors with need with the polyfill's.
global.Intl = require('intl');
Intl.NumberFormat = IntlPolyfill.NumberFormat;
Intl.DateTimeFormat = IntlPolyfill.DateTimeFormat;
require('intl/locale-data/jsonp/en-US.js');
require('intl/locale-data/jsonp/bg-BG.js');
//"zh-Hans-CN": Chinese written in simplified characters as used in China.
require('intl/locale-data/jsonp/zh-Hans-CN.js');
require('intl/locale-data/jsonp/ha-Arab.js');
require('intl/locale-data/jsonp/fr-FR.js');
require('intl/locale-data/jsonp/ru-RU.js');
require('intl/locale-data/jsonp/de-DE.js');
require('intl/locale-data/jsonp/eu-ES.js');
}
https://stackoverflow.com/questions/34285852
复制相似问题