Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I read locale property of Require.js config?

From http://requirejs.org/docs/api.html#i18n I found how to set the current locale, which is:

requirejs.config({
    config: {
        i18n: {
            locale: 'fr-fr'
        }
    }
});

But then, how can I read configuration inside some module to see the value of the current locale?

like image 426
Igor G. Avatar asked Oct 20 '22 23:10

Igor G.


1 Answers

It's been a few months so I'm guessing you've already figured this out (or found a workaround), but I'll answer the question for the sake of future users who might stumble across this page. Inside any require module, you can always access the "require" and "reuirejs" globals. So, inside your module, you can do this:

//Module defition
define(function (['abcd', 'efgh'], abcd, efgh) {
    //Note: if you gave your context a name in the config, then replace "_" with that name
    var globalConfigs = requirejs.s.contexts._.config;
    console.log(globalConfigs.i18n.locale); // > fr-fr
});
like image 166
AlexZ Avatar answered Oct 23 '22 16:10

AlexZ