Does Dojo support creation of custom language variants to be used for with Dojo's locale and i18n
Does anyone know if I am able to create a custom language variant for Dojo's locale that works with i18n?.
Example
define({
root: {
greeting: "Hello, world!"
}
"de-myVariant" : true
});
Yes, it can be done. If you have nls/SampleApp.js
as:
define({
root: {
greeting: "Hello!"
}
"de" : true,
"de-at": true,
"de-x-mundl": true
});
then there would be three sub-directories under nls
:
nls/de
nls/de-at
nls/de-x-mundl
for nls/de/SampleApp.js
:
define(({
greeting: "Hallo!"
}));
for nls/de-at/SampleApp.js
:
define(({
greeting: "Gruß Gott!"
}));
and for nls/de-x-mundl/SampleApp.js
:
define(({
greeting: "Servus, Mundi!"
}));
Then if you config Dojo to get the locale as a URL parameter:
<script src="./dojo/1.8.3/dojo/dojo.js"
data-dojo-config="locale: location.search.substring(1).toLowerCase()">
</script>
you can switch the language easily by passing the locale tag as that parameter:
.../app.html?de-DE
.../app.html?de-at
.../app.html?de-x-Mundl
Note that Dojo considers locale tags as case-sensitive and that's why the input is toLowerCase()
ed and internally all the tags are kept in lower-case.