即时参数的翻译

问题描述 投票:0回答:1

我正在使用ngx-translate并且在HTML组件中翻译字符串值没有问题,但是我如何翻译这样的内容:

  <input matInput tabindex="-1" required placeholder="{{j == 0 ? ('Where') : ( j == passatControlGroup.controls.length - 1 ? 'Time' : 'Via')}}"

我的翻译是在JSON文件中,我想用key:value,就像我为HTML字符串做的那样。

<mat-icon>{{'passatCarComponent.Clear'|translate}}</mat-icon>

要翻译的语法是什么('Where'),如果我想将其写入JSON文件:

{
"passatCarComponent": "translation for Where"
}

谢谢

angular ngx-translate
1个回答
0
投票

如果您想在Where属性中翻译TimeViaplaceholder文本,您需要:

  • 将文本更改为转换键的名称
  • 将这些键和翻译添加到您的翻译文件中
  • 在你的translate属性placeholder逻辑中添加{{ ... }}管道

您的模板看起来像这样:

<input matInput tabindex="-1" required placeholder="{{ (j == 0 ? ('passatCarComponent.Where') : ( j == passatControlGroup.controls.length - 1 ? 'passatCarComponent.Time' : 'passatCarComponent.Via')) | translate }}">
© www.soinside.com 2019 - 2024. All rights reserved.