I'm sure this is a silly configuration problem but I cannot seem to figure it out. I'm using the globalize package within nodejs installed this way:
npm install --save globalize cldr-data
Which looking at my package.json installed:
"globalize": "^1.1.1",
"cldr-data": "^29.0.1",
Then I created a nodeunit test:
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();
};
The first test passes but the 2nd fails with this error:
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
Anyone have any ideas on how I'm misconfiguring this?
Figured it out immediately AFTER making this post.
It turns out if I add the "es-MX" to the list of locales to load in entireMainFor
this works as exepcted:
Globalize.load( require( "cldr-data" ).entireMainFor( "es", "es-MX") );
Hope this helps someone else! For whatever reason I thought all locales under a given language were loaded in this function. I've submitted an issue to 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.