ngxtranslate不能翻译Javascript弹出窗口

时间:2020-07-01 10:09:41

标签: javascript angular translation ngx-translate

点击我的请求,内容确定吗?没有更改为所需的语言。

list.component.html

<button type="button" (click)="myrequest(item.Id)">Request View</button>

list.component.ts

myrequest((Id: number));
{
  this.notificationService.smartMessageBox(
    {
      title: "Warning",
      content: "{{ 'Are you sure?' | translate }}",
      buttons: "[No][Yes]"
    },
    ButtonPressed => {
      if (ButtonPressed === "Yes") {
        this.loading = true;
        this.FurtherRequest(projectId).subscribe((data: any) => {
          this.loading = false;
          if (data.Success) {
            this.notificationService.successMessage("request submitted");
          } else {
            this.notificationService.errorMessage(data.Message);
          }
        });
      }
      if (ButtonPressed === "No") {
      }
    }
  );
}

list.module.ts

import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
    
imports: [
  TranslateModule],

exports: [
  TranslateModule],

无法在js中翻译内容

2 个答案:

答案 0 :(得分:1)

您需要传递一个参数来转换js文件中的管道。

{{  'Are you sure?' | translate :param }}

答案 1 :(得分:0)

管道不能像这样工作。您需要使用translateService.gettranslateService.instant来以编程方式获取翻译。