小编And*_*sne的帖子

Angular 2 i18n动态/即时翻译

我已经按照angular.io食谱进行了国际化(https://angular.io/docs/ts/latest/cookbook/i18n.html#!#angular-i18n).一切正常,如果我在index.html文件中更改我的语言环境:

document.locale = 'en';
Run Code Online (Sandbox Code Playgroud)

但我希望动态地改变它,就像我们在AngularJS中所做的那样.我找到了几个解决方案,例如:

//mycomponent.component.ts
changeLang(){
localStorage.setItem('localeId', "es");
location.reload(true);

} //I hardcoded the locale, but you get the idea
Run Code Online (Sandbox Code Playgroud)

有没有办法在旅途中翻译文件?因为这种解决方案不实用,并且具有较长的重载时间.谢谢您的帮助!

javascript internationalization typescript angular

7
推荐指数
2
解决办法
2万
查看次数