【问题标题】:ngxtranslate to translate popup from Javascript can't workngxtranslate 无法从 Javascript 翻译弹出窗口
【发布时间】:2020-07-01 10:09:41
【问题描述】:

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

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里面的东西

【问题讨论】:

标签: javascript angular translation ngx-translate


【解决方案1】:

你需要传递一个参数来翻译js文件中的管道。

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

【讨论】:

  • 试过了,不行,打印出完整的原始行如上
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 2015-08-22
    • 2014-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    相关资源
    最近更新 更多