我已经按照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)
有没有办法在旅途中翻译文件?因为这种解决方案不实用,并且具有较长的重载时间.谢谢您的帮助!