使用 Ts 文件中的 ngx 翻译服务翻译甜蜜警报标题和消息

Translate sweet alert title and messages using ngx translate service in the Ts file

如何使用 Ts 文件中的翻译服务翻译标题和文本。 服务名称是 translate

   // Delete Address Confirmation
  onDeleteConfirm(address) {
    swal.fire({
      title: 'Are you sure?',
      // title: "'are-you-sure' | translate",
      text: "You won't be able to revert this!",
      type: 'warning',
      showCancelButton: true,
      allowOutsideClick: false,
      confirmButtonColor: this.baseService.storeTheme,
      // cancelButtonColor: '#d33',
      confirmButtonText: 'Yes, delete it!',
      customClass: {
        confirmButton: 'confirm-button-class',
        cancelButton: 'cancel-button-class'
      },
    }).then((result) => {
      if (result.value) {
        this.deleteAddress(address);
      }
    })
  }

你先导入你的servive,即

constructor(private translate: TranslateService) { ... }

然后调用instant方法使用服务,即

this.translate.instant('property-key');

有关详细信息,请参阅 the official documentation