【发布时间】:2017-06-20 19:44:24
【问题描述】:
我遵循 angular.io 国际化食谱 (https://angular.io/docs/ts/latest/cookbook/i18n.html#!#angular-i18n)。 一切正常,如果我在 index.html 文件中更改我的语言环境:
document.locale = 'en';
但我希望动态地改变它,就像我们过去在 AngularJS 中所做的那样。我找到了几种解决方案,例如:
//mycomponent.component.ts
changeLang(){
localStorage.setItem('localeId', "es");
location.reload(true);
} //I hardcoded the locale, but you get the idea
有没有办法随时随地翻译文档?因为这种解决方案不实用,并且重新加载时间很长。谢谢您的帮助!
【问题讨论】:
标签: javascript angular typescript internationalization