[英]Translate array with ngx translate in Angular 9
I am declaring an Array in TS and I want to be able to translate them.我在 TS 中声明一个数组,我希望能够翻译它们。 It is possible to translate an Array with different languages.
可以用不同的语言翻译一个数组。 I do have something like this.
我确实有这样的东西。 The others variables are changing but only the Arrays not.
其他变量正在改变,但只有 Arrays 没有。 Can someone help me there or at least any idea.
有人可以在那里帮助我,或者至少有任何想法。
HTML. HTML。
<div class="col-md-4 text-left flex-column">
<select class="col-md-12">
<option *ngFor="let language of languages"
[value]="language">
{{language.description | translate}}
</option>
</select>
</div>
TS TS
public housingTypeOptions = [];
this.languages = [
{name: Status.Mr, description: this.translateService.instant("data.mr")},
{name: Status.Mrs, description: this.translateService.instant("data.mrs")},
];
JSON. JSON。
"status": {
"single": "Single",
"married": "Married",
"nk": "Not Known"
}
And this is the change with Languages.这就是语言的变化。
<select
class="form-control"
#selectedLang
(change)="switchLang(selectedLang.value)">
<option *ngFor="let language of translate.getLangs()"
[value]="language"
[selected]="language === translate.currentLang">
{{ language }}
</option>
</select>
translate.addLangs(["de", "en", "al"]);
I have found the solution, I need only to pass the id in the description from array and then in html to write like this.我找到了解决方案,我只需要从数组中传递描述中的id,然后在html中这样写。
<select class="form-control">
<option *ngFor="let status of statusObject"
[value]="status">
{{status.description | translate}}
</option>
</select>
And in TS only like this, call direct the ID.而在TS里只有这样,直接调用ID。
public statusLanguages = [
{name: Languages.AL, description: "language.al"},
{name: Languages.EN, description: "language.en"},
{name: Languages.DE, description: "language.de"}
];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.