Angular i18n 如何翻译 select 选项
Angular i18n how to translate select options
我正在 Angular 7 上开发一个反应式表单,我需要使用 制作一个下拉列表,并且我需要将选项从英语翻译成法语。选项在我的 Ts 文件中设置。我听说过 ICU 表达式,我已经阅读了文档,但我不明白它如何适合我的情况。有人可以帮我吗?
我的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>
我的 Ts:
materials_tab = [{ name: 'Wood' }, { name: 'Cardboard' }, { name: 'Plastic' }, { name: 'Paper' }, { name: 'Glass' }, { name: 'Metal' }, { name: 'Other' }];
提前致谢。
抱歉回答晚了,我终于做到了。
我的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>
我的老师:
materials_tab = ['Wood', 'Cardboard', 'Plastic', 'Paper', 'Glass', 'Metal', 'Other'];
并在 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>
此解决方案的唯一问题是,如果您要翻译的列表很长,它将变得不可读...
我希望这会对某人有所帮助。
我正在 Angular 7 上开发一个反应式表单,我需要使用 制作一个下拉列表,并且我需要将选项从英语翻译成法语。选项在我的 Ts 文件中设置。我听说过 ICU 表达式,我已经阅读了文档,但我不明白它如何适合我的情况。有人可以帮我吗?
我的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>
我的 Ts:
materials_tab = [{ name: 'Wood' }, { name: 'Cardboard' }, { name: 'Plastic' }, { name: 'Paper' }, { name: 'Glass' }, { name: 'Metal' }, { name: 'Other' }];
提前致谢。
抱歉回答晚了,我终于做到了。
我的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>
我的老师:
materials_tab = ['Wood', 'Cardboard', 'Plastic', 'Paper', 'Glass', 'Metal', 'Other'];
并在 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>
此解决方案的唯一问题是,如果您要翻译的列表很长,它将变得不可读...
我希望这会对某人有所帮助。