在.ts文件中使用ngx-translate [英] use ngx-translate in .ts file

查看:349
本文介绍了在.ts文件中使用ngx-translate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在sidemenu标题中使用翻译,我读了本教程我将其解决为:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆