[英]EmberJS : Translation using i18n library is not working?
My project need to support 3 different languages. 我的项目需要支持3种不同的语言。 We used Emberjs for development.
我们使用Emberjs进行开发。
So for implementation of translation , I followed the tutorial provided in the following URL 因此,对于翻译的实现,我遵循了以下URL中提供的教程
http://eviltrout.com/2013/11/24/i18n-in-ember.html http://eviltrout.com/2013/11/24/i18n-in-ember.html
I have included the i18n.js from the following url 我已经从以下网址中包含了i18n.js
https://github.com/fnando/i18n-js/blob/master/vendor/assets/javascripts/i18n.js https://github.com/fnando/i18n-js/blob/master/vendor/assets/javascripts/i18n.js
into my project Then i created a file named translation.js with contents of 到我的项目中,然后我创建了一个名为translation.js的文件,其内容为
I18n.translations = {
en: {
savingquote: 'savings made simple'
},
hi: {
savingquote: 'बचत सरल बनाया'
},
es : {
savingquote:'ahorros de forma sencilla'
}
};
And in my project am view page am referring it as {{i18n savingquote}}
. 在我的项目中,视图页面将其称为
{{i18n savingquote}}
。 And added a helper to my app.js with following code 并使用以下代码将助手添加到我的app.js中
Ember.Handlebars.registerHelper('i18n', function(property, options) {
var params = options.hash,
self = this;
// Support variable interpolation for our string
Object.keys(params).forEach(function (key) {
params[key] = Em.Handlebars.get(self, params[key], options);
});
return I18n.t(property, params);
});
Now my requirement is to change language of my project without reloading . 现在,我的要求是不重新加载就更改项目语言。 So in my language change function am adding
I18n.locale = 'hi';
因此,在我的语言更改函数中,添加了
I18n.locale = 'hi';
. 。 But handlebars appearing in default language english.
但是车把以默认语言英语出现。
Your comments are welcome. 欢迎您发表评论。
I think it is not necessary to reload the page but you will need to refresh/rerender the active ember view
since translations are not meant to be bound properties. 我认为没有必要重新加载页面,但是您将需要刷新/重新渲染活动的余烬
view
因为翻译并不意味着要绑定属性。
DISCLAIMER: have not used the specific implementation, but have implemented a similar functionality supporting ember apps (in code and templates) and html parts (out of templates). 免责声明:尚未使用特定的实现,但是实现了类似的功能,支持ember应用程序(在代码和模板中)和html部分(在模板之外)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.