Как перевести уведомление с параметром, используя Angular 5? - PullRequest
0 голосов
/ 15 февраля 2019

Я не могу перевести уведомление при получении параметров, используя ngx-translate / core

ОБРАЗЕЦ КОДА

en.json :
   "message": {
        "Successfully removed account": "Successfully removed account"
        }

Выше приведен перевод json

constructor(private translate: TranslateService,
private userService : userService)

async deleteAccount(account) {
try {
  await this.userService.removeuserAccount(account.id);
  this.notificationService.sendSuccess(this.translate.instant(`message.Successfully removed account ${account.id}`));
} catch (err) {
  this.notificationService.sendError(this.translate.instant(`message.Unable to delete account: ${err.message}`));
    }
  }

Пожалуйста, помогите мне решить эту проблему

нам нужно исправить аналогичную проблему в ссылке в компонентах https://github.com/ngx-translate/core/pull/990

Ответы [ 2 ]

0 голосов
/ 15 февраля 2019

Попробуйте этот ответ.Переведите его и добавьте к переменной.

    constructor(private translate: TranslateService,
    private userService : userService)

    async deleteAccount(account) {
    try {
      await this.userService.removeuserAccount(account.id);
      var status = this.translate.instant('message.Successfully  removed account');
this.notificationService.sendSuccess(this.translate.instant(status + `${account.id}`));
    } catch (err) {
var statuserr = this.translate.instant(`message.Unable to delete account:');
      this.notificationService.sendError(this.translate.instant(statuserr +` ${err.message}`));
        }
      }
0 голосов
/ 15 февраля 2019

ОБНОВЛЕНИЕ:

Поскольку сообщение приходит из JSON, вам необходимо использовать

this.translate.instant(message['Successfully removed account'] + account.id)

ПРЕДЫДУЩИЙ ОТВЕТ:

Если message.Successfully также является компонентной переменной, такой как ENUM или что-то еще,

использует ${message.Successfully} removed account ${account.id} в качестве аргумента метода внутри обратных кавычек (`)

Если обратные кавычки не являютсяподдерживается и message.Successfully это просто строка, используйте

this.translate.instant("message.Successfully removed account " + account.id) 

, если message.Successfully не строка и если это переменная, тогда используйте

this.translate.instant(message.Successfully + "removed account " + account.id) 
...