Question

In the Dojo Toolkit, the locale (language) has to be defined in the configuration used at loading time.

E.g.

<script data-dojo-config="async: 1, isDebug: 1, locale: 'es'" src="dojo/dojo.js"></script>

I want to specify the locale by an URL-Parameter like this:

../myapp/index.html?lang=es

I use the boilerplate for Dojo: Dojo Boilerplate

One idea was to load the dojo.js this way:

<script data-dojo-config="async: 1, isDebug: 1, locale: function(){//Code returning the value of the language URL-Parameter}" src="dojo/dojo.js"></script>

But this is not working.

Thank you!

PS: A solution is presented in Custom language variants. But this works only, if you have only one URL-Parameter.

Was it helpful?

Solution

This seems to work: URL-Parameters with JS.

Resulting in

<script data-dojo-config="async: 1, isDebug: 1, locale: decodeURIComponent((new RegExp('[?|&]' + 'lang' + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,''])[1].replace(/\+/g, '%20'))||null" src="dojo/dojo.js"></script>

Where 'lang' is the name of my Language URL-Parameter.

OTHER TIPS

I noticed that you already have a (valid) answer. But if your goal is to test a website using a specific locale, then you could just remove the locale property from your Dojo config and use the browser locale as an alternative.

The browser locale depends on the language you have configured in your browser.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top