[英]use ngx-translate in .ts file
I want to use a translation in sidemenu titles, I read this tutorial and I solve it as: 我想在sidemenu标题中使用翻译,我阅读本教程并将其解决为:
translate.get('HOME').subscribe(res => {
this.pages= [
{title: res , component: HomePage},
{title: 'My Account', component: MyAccountPage},
{title: 'Changer Pass' , component: ChangePasswordPage}
]
It works, but the problem is that I want t get many title from the translation file to set them as sidemenu titles. 它有效,但问题是我想从翻译文件中获得许多标题,将它们设置为sidemenu标题。
Please do not use the forkJoin
operator in this case. 在这种情况下请不要使用
forkJoin
运算符。 ngx-translate supports fetching multiple translations at once by passing an array of keys to the get()
method like this: ngx-translate支持通过将一组键传递给
get()
方法一次获取多个转换,如下所示:
translate.get(['HOME', 'MY_ACCOUNT', 'CHANGE_PASSWORD']).subscribe(translations => {
this.pages= [
{ title: translations.HOME, component: HomePage},
{ title: translations.MY_ACCOUNT, component: MyAccountPage},
{ title: translations.CHANGE_PASSWORD, component: ChangePasswordPage}
];
})
Edit : 编辑 :
Here you can find all supported methods and their signature. 在这里,您可以找到所有支持的方法及其签名。
@David thank you for your inspiration. @David感谢您的灵感。
also you can use something like this: 你也可以使用这样的东西:
translate.get(['Home', 'My Account', 'Change Password']).subscribe(translations => {
this.pages= [
{ title: translations['Home'], component: HomePage},
{ title: translations['My Account'], component: MyAccountPage},
{ title: translations['Change Password'], component: ChangePasswordPage}
];
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.