gpt4 book ai didi

angular - 在 *ngFor 循环内使用 Angular i18n 和 Angular 5

转载 作者:行者123 更新时间:2023-12-02 16:30:01 28 4
gpt4 key购买 nike

我想在模板的 ngFor-Loop 内使用动态翻译,如下所示:

<mat-card *ngFor="let user of usersList">
<mat-card-title>
<span>{{user.name}}</span>
</mat-card-title>
<mat-card-content>
<!--This is the enum i would like to translate dynamic -->
<span i18n="Role@@role">{{user.role}}</span>
</mat-card-content>
</mat-card>

有没有办法使用 Angular 5 i18e(国际化)当前的板载工具来动态转换此枚举值?

据我所知,在 Angular 6.1 或更高版本中,将有一种方法可以转换 .ts 中的值。但是,如果我现在想使用它怎么办?有什么解决方法吗?

使用替代文本消息可能不是一个好方法,因为如果枚举中有数百个值怎么办?我不会在 html 代码中重复我的枚举。

最佳答案

我还使用.xlf进行了测试

这现在对我有用:

<mat-card *ngFor="let user of usersList">
<mat-card-title>
<span>{{user.name}}</span>
</mat-card-title>
<mat-card-content>
<span i18n="@@roleKey">{user.roles, select, role {role}}</span>
</mat-card-content>
</mat-card>

我的messeges.de.xlf中的翻译部分现在是

<trans-unit id="roleKey" datatype="html">
<source>{VAR_SELECT, select, role {role}}</source>
<target>{VAR_SELECT, select, SUPER_ADMIN {Super Admin} LIZENZ_MANAGER {Lizenz Manager} RECHTLICHE_EXPERT {Rechtliche-Expert} INFRASTRUKTRELLE_EXPERT {Infrastruktrelle-Expert} SPORTLICHE_EXPERT {Sportliche Expert} ADMINISTRATIVES_EXPERT {Administratives-Expert} FINANZIELLE_EXPERT {Finanzielle-Expert} LIZENZ_BEWERBER {Lizenz-Bewerber} }</target>
<context-group purpose="location">
<context context-type="sourcefile">app/locallogin/locallogin.component.ts</context>
<context context-type="linenumber">18</context>
</context-group>
</trans-unit>

关于angular - 在 *ngFor 循环内使用 Angular i18n 和 Angular 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49645841/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com