Internationalization 带i18n翻译的angular2通知

Internationalization 带i18n翻译的angular2通知,internationalization,angular5,Internationalization,Angular5,我用这个软件包来获得通知,它工作得很好,但它在ts文件中工作得很好 saveUser(user){ //some process then notification will work. this.notif.success( 'Yeahhh successfull create notification', { timeOut: 3000, showProgressBar: true, pauseO

我用这个软件包来获得通知,它工作得很好,但它在ts文件中工作得很好

saveUser(user){
      //some process then notification will work.
      this.notif.success(
      'Yeahhh successfull create notification',
      {
        timeOut: 3000,
        showProgressBar: true,
        pauseOnHover: false,
        clickToClose: true,
        maxLength: 50
      }
   )
}
工作正常,但我正在使用translate i18n,并希望通过语言提供这些参数。软件包说它有一个html函数,但我尝试了,但无法做到这一点

多谢各位

我猜img是看不见的,它是html的代码

this.notif.html(`<p translate > {{ 'City' | translate }}  Success</p>`)

您可以使用TranslateService获取翻译值

首先导入服务

import {TranslateService} from '@ngx-translate/core';
然后像这样注入和使用它:

export class YourComponent {
  constructor(translate: TranslateService) {
    translate.get('CITY').subscribe((res: string) => {
      console.log(res);
      //=> 'Whatever your translation is for "city"'
    });
  }
}

可以找到进一步的文档。

您使用的i18n库是什么?他们可能会在翻译管道中提供一个可注入的服务,在这种情况下,您必须手动获取翻译。如果您正在使用,ngx translate有一个服务可供使用。是的,我正在使用ngx translate,让我检查一下谢谢!!这就是我想要的最好的问候。