npm 安装全球化 - E_MISSING_BUNDLE

npm install globalize - E_MISSING_BUNDLE

我确定这是一个愚蠢的配置问题,但我似乎无法弄清楚。我正在以这种方式安装的 nodejs 中使用 globalize 包:

npm install --save globalize cldr-data

看我的 package.json 安装:

"globalize": "^1.1.1",
"cldr-data": "^29.0.1",

然后我创建了一个nodeunit测试:

var Globalize = require( "globalize" );
Globalize.load( require( "cldr-data" ).entireSupplemental() );
Globalize.load( require( "cldr-data" ).entireMainFor( "es") );
Globalize.loadMessages({
    en: {
        hello: "Hello, {0} {1} {2}",
        hey: "Hey, {first} {middle} {last}"
    }
});
exports['test message translation'] = function (test) {
    var enFormatter = Globalize( "es-MX" ).messageFormatter( "hello" );
    testString = enFormatter([ "Wolfgang", "Amadeus", "Mozart" ]);
    test.equal(testString, "Hello, Wolfgang Amadeus Mozart");
    test.done();
};
exports['test date localization'] = function (test) {
    test.equals("18/4/2016", Globalize( "es-MX" ).dateFormatter()( new Date()));
    test.done();
};

第一个测试通过,但第二个测试失败并出现此错误:

Error: E_MISSING_BUNDLE: {"locale":"es-MX"}
    at createError (/Users/darrin/src/tot/commons/node_modules/globalize/node_modules/cldrjs/dist/cldr.js:341:11)
    at validate (/Users/darrin/src/tot/commons/node_modules/globalize/node_modules/cldrjs/dist/cldr.js:357:10)
    at Cldr.main (/Users/darrin/src/tot/commons/node_modules/globalize/node_modules/cldrjs/dist/cldr.js:663:3)
    at dateExpandPattern (/Users/darrin/src/tot/commons/node_modules/globalize/dist/globalize/date.js:110:18)
    at Globalize.dateFormatter.Globalize.dateFormatter [as dateFormatter] (/Users/darrin/src/tot/commons/node_modules/globalize/dist/globalize/date.js:1828:12)
    at Object.exports.test date localization (/Users/darrin/src/tot/commons/tests/globalize/globalize.test.js:43:40)
    at Object.<anonymous> (/Users/darrin/src/tot/commons/node_modules/nodeunit/lib/core.js:236:16)
    at /Users/darrin/src/tot/commons/node_modules/nodeunit/lib/core.js:236:16
    at Object.exports.runTest (/Users/darrin/src/tot/commons/node_modules/nodeunit/lib/core.js:70:9)
    at /Users/darrin/src/tot/commons/node_modules/nodeunit/lib/core.js:118:25

有人知道我是如何配置错误的吗?

在制作这个 post 后立即想通了。

事实证明,如果我将 "es-MX" 添加到语言环境列表中以在 entireMainFor 中加载,这将按预期工作:

Globalize.load( require( "cldr-data" ).entireMainFor( "es", "es-MX") );

希望这对其他人有帮助!无论出于何种原因,我认为给定语言下的所有语言环境都已加载到此函数中。我已经向 globalize on the hunch that others might make the same assumptions and a slight change to documentation could clarify - it's here: jquery / globalize #610.

提交了一个问题