문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top