0

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.

Community
  • 1
  • 1
Frank
  • 63
  • 8

2 Answers2

1

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.

Community
  • 1
  • 1
Frank
  • 63
  • 8
1

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.

g00glen00b
  • 41,995
  • 13
  • 95
  • 133
  • I have to implement switch language buttons. You know the flags on some sites, changing the language. Besides I want to save the selected language if the user stores the actual URL in a bookmark. Reloading the bookmark, the language would be loaded according to the saved bookmark, because the language is saved in an URL-Parameter. – Frank Mar 19 '14 at 07:08