使用areIntlLocalesSupported和Browserify/webpack添加本地程序的正确方法是什么
What is the correct way to add locals using areIntlLocalesSupported and Browerify/webpack?
我正在尝试使用Browserify国际化React JS应用程序,并遵循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');
}
我们刚刚发现,我需要在内部if块中添加带有区域设置的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');
}
相关文章:
- 在AngularJS应用程序中使用封装指令和路由的推荐方式是什么
- 在这个使用hasOwnProperty的对象扩展程序中有一个错误,I'我不确定那个bug是什么,也不确定这个扩展
- 将Rails后端添加到JS/HTML/CSS应用程序时,正确的文件位置是什么
- 在企业应用程序框架中包含js/css文件的最佳实践是什么
- 当用户允许使用mic Javascript时,事件处理程序是什么
- 直接在DOM事件处理程序中调用作用域函数的最短方法是什么
- 是什么触发了浏览器中的弹出窗口阻止程序
- 展示纯js应用程序前端的最佳架构是什么
- 此程序中按位运算的目的是什么
- Json在应用程序电话间隙!路径是什么
- Windows 8 HTML5 JavaScript 应用程序中向左滑动的事件名称是什么
- 在单页应用程序上进行客户端路由的正确方法是什么
- 在angular js中,每次应用程序进入状态时,重新加载状态的最佳方式是什么
- Chrome应用程序中AJAX请求的限制是什么
- 淘汰js应用程序的正确文件结构是什么
- 在同构的React web应用程序中,选择服务器渲染的最佳方式是什么
- 是什么处理Hello,Lungo应用程序中的导航
- 运行电子应用程序的最低系统要求是什么
- 网络应用程序是用什么语言编写的
- 调用jQuery.on()的纯Javascript等效程序是什么?