Use ngx-translate in .ts file

I want to use the translation in the 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}
]

This works, but the problem is that I want to get many titles from the translation file in order to set them as sidemenu names.

+4
source share
1 answer

Please do not use an operator in this case forkJoin. ngx-translate supports fetching multiple translations at once, passing an array of keys to the method get()as follows:

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.

+4
source

Source: https://habr.com/ru/post/1685515/


All Articles