[英]how to remember ember-i18n language choice on browser refresh
I tried first something like this in my application controller: 我首先在应用程序控制器中尝试了类似的方法:
init123: function() {
var locale;
if (this.session.get('lang') === null || this.session.get('lang') === undefined)
locale = ENV.i18n.defaultLocale;
else
locale = this.session.get('lang');
this.get('i18n').set('locale', locale);
}.on('init'),
but this only works when the user is logged in. If not, always the default is set. 但这仅在用户登录时有效。否则,将始终设置默认值。
Then I tried stuff with the initalizer like on this answer. 然后,我像这样的答案尝试了initalizer的东西。
How to set the i18n.locale from within an initializer from Artych 如何从Artych 的初始化程序中设置 i18n.locale
But how do I remember the last choice done in the browser? 但是,我如何记住在浏览器中所做的最后选择?
Thx 谢谢
You need to persist the preference somewhere. 您需要将偏好保留在某个地方。 Take a look at the ember-localforage-adapter or ember-local-storage packages. 看一下ember-localforage-adapter或ember-local-storage软件包。
如果您使用的是ember-simple-auth ,则可以将其保存到会话中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.