I have a problem with the latest version of globalize.js
.
To work with it I had to load the cldr modules
and language definitions.
Now I had this example from the globalize docs:
// loading needed modules
$.get('/Scripts/cldr/supplemental/likelySubtags.json', Globalize.load);
$.get('/Scripts/cldr/main/en/numbers.json', Globalize.load);
$.get('/Scripts/cldr/main/de/numbers.json', Globalize.load);
// set current language
lobalize.locale('de-de');
My problem now is that the local json files are loaded async. That means at the moment where my script is try to set the current language, the modules are not yet loaded.
Now I tried to be smart and made this:
$.get('/Scripts/cldr/supplemental/likelySubtags.json', function (data) {
Globalize.load(data);
Globalize.locale('de-de');
});
$.get('/Scripts/cldr/main/en/numbers.json', Globalize.load);
$.get('/Scripts/cldr/main/de/numbers.json', Globalize.load);
This will work until I really used globalize format methode. Inside my HTML I use globalize inside a knockout binding like this:
<span data-bind="text: Globalize.formatNumber(SomeNumber, { maximumFractionDigits: 0 })"></span>
Now the "formatNumber" method is throwing an error because not all module are loaded at the moment the binding is happend.
My question is now, how can I sync up my JavaScript?