使用 areIntlLocalesSupported 和 Browerify/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');
 }