问题描述
在dojo加载之前,需要在data-dojo-config中设置区域设置,以便dojo.i18n可以与此区域设置一起工作。是否有任何解决方法,我们可以在dojo加载后,在Dojo / _base / config中更改此区域设置,以便任何进一步的dojo.i18n调用将与此新区域设置配合使用?
We need set locale in data-dojo-config before dojo loaded so that dojo.i18n will work with this locale. Is there any workaround that we can change this locale in dojo/_base/config after dojo loaded so that any further dojo.i18n call will work with this new locale?
I有一个单一的页面应用程序,通过仔细设计,我已经能够动态地重新创建我的所有UI小部件。我想添加一个选择某处,以便用户可以即时更改语言。目前我唯一的解决方案是在Url上放置一个queryString locale ='newLocale'并强制浏览器刷新。这是有用的,但是所有用户都失去了,并开始了新的一天。这不是我想要的。
I have a single page application, by carefully design, I already be able to recreate all my UI widgets dynamically anytime. I want to add a Select somewhere so that user can change languages on the fly. Currently the only solution I have is put a queryString locale='newLocale' at Url and force browser refresh. That works but everything User have done lost and with a fresh start. That's not what I want.
任何想法?我不怕Dojo发生一些变化,因为我的应用程序将被构建为一个单一层并部署到客户端。
Any idea? I don't afraid some changes of dojo to make this happen since my application will be built as a single layer and deploy to customers.
推荐答案
根据dojo的文档,加载后不能更改区域设置。请参阅从他们的文档,相关行是:
According to dojo's documentation, you cannot change the locale once it's loaded. See this page from their documentation, the relevant line is:
您在添加新参数的描述是我在这种情况下所做的,可以指定 locale
属性 dojoConfig
对象来覆盖默认语言环境。
Your description of adding a new parameter is what I've done in this situation, you can specify the locale
property on the dojoConfig
object to override the default locale.
编辑:这个用例有一个开放的错误,请参阅。在那张票中,似乎还有一个解决方法,基本上包括手动加载要使用的语言的资源文件,并更新任何文本。
There is an open bug for this use case, see https://bugs.dojotoolkit.org/ticket/17196. In that ticket there also appears to be a workaround that basically involves manually loading the resource file of the language you want to use and updating any text.
所以,调整他们的例子(),这将在您启动更改区域设置操作后运行:
So, adapting their example (http://jsbin.com/aquviq/1/edit), this would run after you initiate a change locale action:
require(['dojo/i18n!dojo/nls/' + resourceModuleWithLocale], function (resource) {
/* in here, you must set all of the text manually to the values in the resource object */
});
它似乎还有很多工作,但我想这是一种可能的方式来实现这一点。
It still seems like a lot of work, but I suppose that's one possible way to accomplish this.
这篇关于dojo加载后如何更改dojo区域设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!