在 .ts 文件中使用 ngx-translate [英] use ngx-translate in .ts file
本文介绍了在 .ts 文件中使用 ngx-translate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在侧边菜单标题中使用翻译,我阅读了 本教程 我将其解决为:
I want to use a translation in sidemenu titles, I read this tutorial and I solve it as:
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.
推荐答案
在这种情况下请不要使用 forkJoin
运算符.ngx-translate 支持通过将一组键传递给 get()
方法一次获取多个翻译,如下所示:
Please do not use the forkJoin
operator in this case. ngx-translate supports fetching multiple translations at once by passing an array of keys to the get()
method 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}
];
})
编辑:
这里您可以找到所有支持的方法及其签名.
Here you can find all supported methods and their signature.
这篇关于在 .ts 文件中使用 ngx-translate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文