[英]Angular i18n how to translate select options
I'm working on a reactive form on Angular 7, and I need to make a dropdown list with , and I need to translate options from english to french.我正在 Angular 7 上开发一个响应式表单,我需要用 制作一个下拉列表,我需要将选项从英语翻译成法语。 Options are set in my Ts file.
选项在我的 Ts 文件中设置。 I've heard about ICU expressions, I've read the documentation but I don't understand how it could fit my case.
我听说过 ICU 表达式,我已经阅读了文档,但我不明白它如何适合我的情况。 Could someone help me ?
有人可以帮助我吗?
My HTML :我的 HTML :
<select name="material" class="form-control input-underline input-lg" formControlName="material"
[(ngModel)]="portal.material" type="text" required i18n>
<option selected disabled value=undefined [ngValue]="null">Select a material</option>
<option *ngFor="let item of material_tab" [ngValue]="item">{{item.name}}</option>
</select>
My Ts :我的 T :
materials_tab = [{ name: 'Wood' }, { name: 'Cardboard' }, { name: 'Plastic' }, { name: 'Paper' }, { name: 'Glass' }, { name: 'Metal' }, { name: 'Other' }];
Thanks in advance.提前致谢。
Sorry for late answer, I finally managed to do it.抱歉回复晚了,我终于设法做到了。
My HTML :我的 HTML :
<option *ngFor="let item of materials_tab" [ngValue]="item" i18n>{item, select, Wood {Wood} Cardboard {Cardboard} Plastic {Plastic} Paper {Paper} Glass {Glass} Metal {Metal} Other {Other}}</option>
My TS :我的 TS :
materials_tab = ['Wood', 'Cardboard', 'Plastic', 'Paper', 'Glass', 'Metal', 'Other'];
And the translation appears after i18n execution (French here):并且在 i18n 执行后出现翻译(这里是法语):
<source>{VAR_SELECT, select, Wood {Wood} Cardboard {Cardboard} Plastic {Plastic} Paper {Paper} Glass {Glass} Metal {Metal} Other {Other} }</source><target state="new">{VAR_SELECT, select, Wood {Bois} Cardboard {Carton} Plastic {Plastique} Paper {Papier} Glass {Verre} Metal {Métal} Other {Autre} }</target>
The only problem with this solution is that if you have a long list to translate, it becomes unreadable...这个解决方案的唯一问题是,如果你有一个很长的列表要翻译,它就会变得不可读......
I hope this will help someone.我希望这会帮助某人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.