[英]Translate dynamic values with angular 5
I have a json translation file for english and one for german. 我有一个用于英语的json翻译文件,一个用于德语的json翻译文件。
They look like this 他们看起来像这样
en.json en.json
"COLORS": {
"BLUE": "Blue",
"RED": "Red",
"GREEN": "Green"
}
same for the german one. 德国人也一样。
I have a person object and this has an array colors []. 我有一个person对象,它有一个数组颜色[]。 A person could have the colors blue and red.
一个人可能有蓝色和红色。 Then it would look like this:
然后看起来像这样:
person.colors[0] = "BLUE";
person.colors[1] = "RED";
As you can see, I saved the keys of the translations in the array and not the values. 如您所见,我将转换键保存在数组中,而不是值中。
Now I'm looping through the person's colors like: 现在,我遍历该人的颜色,例如:
<div *ngFor="let color of person.colors">
<p>{{'COLORS.color' | translate}}</p>
</div>
But I'm getting no output. 但是我没有输出。 What could be the problem?
可能是什么问题呢?
I already looked at this post angular-translate: Translate dynamic value but it didn't help me. 我已经看过这篇有关angular-translate的文章:翻译动态值,但对我没有帮助。
Try This way 尝试这种方式
<div *ngFor="let color of person.colors">
<p>{{'COLORS.'+color | translate}}</p>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.