globalizejs / globalize

A JavaScript library for internationalization and localization that leverages the official Unicode CLDR JSON data
https://globalizejs.com
MIT License
4.8k stars 603 forks source link

How to bundle? #797

Closed sunsande closed 6 years ago

sunsande commented 6 years ago

Hello,

me and many others (from what I've read ...) are trying to figure out how to bundle the cldr data. Assume we have a web app where the user can change the language directly from the web-interface. She is on page X and selects another language so on the page reload one has to have something like:

$.when(
            $.getJSON("/Scripts/cldr/main/@(Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName)/ca-gregorian.json"),
            $.getJSON("/Scripts/cldr/main/@(Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName)/numbers.json"),
            ...
            $.getJSON("/Scripts/cldr/supplemental/likelySubtags.json"),
            $.getJSON("/Scripts/cldr/supplemental/timeData.json"),
            ...
        ).then(function () {
            return [].slice.apply(arguments, [0]).map(function (result) {
                return result[0];
            })
        }).then(
            Globalize.load
        ).then(
            function() {

If this web-app supports N languages it would be nice if one could pre-bundle all of the JSON files into a single JSON file per language and then load it with a single call. Something like: $.when( $.getJSON("Scripts/cldr/bundled_en.json")).then (Globalize.load).then( ...

Is this possible and what would be the best way to achieve that? (or what would be the best way to handle this situation?)

Best regards, Alex

rxaviers commented 6 years ago

This is better suited as a stack overflow question, sorry, but note there are various ways to solve this, including globalize-compiler, and their tool is better for Q/A than gh issues.