Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile all locales #8

Open
GinoPane opened this issue Dec 17, 2015 · 1 comment
Open

Compile all locales #8

GinoPane opened this issue Dec 17, 2015 · 1 comment

Comments

@GinoPane
Copy link

I failed to run basic-globalize-compiler example (it seems that some points are missed from readme), but nevertheless I have a question: what about compiling data for all locales?

Example shows a situation when we know the locale (en), but what if locale is defined dynamically in runtime and we do not know it before?

@franktroia
Copy link

You can iterate over the list of all locales from the cldr-data module and compile formatters for all locales. I did this using the grunt task below. Then during runtime you will need to use a script loader to load the right formatter when the locale is changed.

    grunt.registerTask('generate:formatters', function() {
        var globalizeCompiler = require('globalize-compiler');
        var fs = require('fs');
        var cldr = require('cldr-data');

        var extracts = ['app/formatters/formatters-template.js'].map(function(input) {
            return globalizeCompiler.extract(input);
        });

        for (var i = 0; i < cldr.availableLocales.length; i++) {
            var locale = cldr.availableLocales[i];
            var bundle = globalizeCompiler.compileExtracts({
                defaultLocale: locale,
                extracts: extracts
            });
            fs.writeFileSync('app/formatters/generated/formatters-' + locale + '.js', bundle);
        }
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants