Angular 应用程序中的 TS 文件:如何使用 i18next 和 angular-i18next 翻译来自 toastlify 的文本?

TS file in Angular app: how to translate text from toastlify with i18next & angular-i18next?

我已经拿到了所有国际化申请 运行 i18next 和 angular-i18next。 我想使用 angular-toastify 翻译弹出窗口,但必须翻译的代码是 ts.file ?

我该怎么做| i18下一个翻译 ?

这是我的package.lock,下面是我想翻译的代码:

    "@angular/animations": "~10.1.6",
    "@angular/cdk": "^10.2.7",
    "@angular/common": "~10.1.6",
    "@angular/compiler": "~10.1.6",
    "@angular/core": "~10.1.6",
    "@angular/forms": "~10.1.6",
    "@angular/material": "^10.2.7",
    "@angular/platform-browser": "~10.1.6",
    "@angular/platform-browser-dynamic": "~10.1.6",
    "@angular/router": "~10.1.6",
    "angular-i18next": "^10.3.0",
    "angular-toastify": "^1.0.4",
    "component": "^1.1.0",
    "i18next": "^21.6.10",
    "i18next-browser-languagedetector": "^6.1.3",
    "i18next-http-backend": "^1.3.2",
    "mat-select-filter": "^2.3.7",
    "mat-table-filter": "^9.1.0",
    "ng-i18next": "^1.0.7",
    "rxjs": "~6.6.0",
    "tslib": "^2.0.0",
    "uuid": "^8.3.2",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.1001.7",
    "@angular/cli": "~10.1.7",
    "@angular/compiler-cli": "~10.1.6",
    "@types/jasmine": "~3.5.0",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^12.11.1",
    "codelyzer": "^6.0.0",
    "jasmine-core": "~3.6.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~5.0.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~3.0.2",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "protractor": "~7.0.0",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~4.0.2",
    "video.js": "^7.10.2"
  }

go.ts文件如下

    if (state === true)
      this._toastService.success("Let's gooo");
    else {
      this._toastService.warn("warning - must be checked");
    }

谢谢你

尝试这样的事情:

import { I18NextPipe } from 'angular-i18next';
...
constructor(
   ...
   private i18nextPipe: I18NextPipe,
   ...
) {...}


  if (state === true) {
    const translatedText = this.i18nextPipe.transform("Let's gooo");
    this._toastService.success(translatedText);
  } else {
    const translatedText = this.i18nextPipe.transform("warning - must be checked");
    this._toastService.warn(translatedText);
    }