Dojo custom language variants

那年仲夏 提交于 2019-12-11 06:33:22

问题


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
});

回答1:


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.



来源:https://stackoverflow.com/questions/16095430/dojo-custom-language-variants

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!