在角度为 5 的 *ngFor 循环中使用 angular i18n

Gat*_*het 3 internationalization angular

我想在模板中的 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>
Run Code Online (Sandbox Code Playgroud)

angular 5 i18e(国际化)的当前板载工具有没有办法动态转换这个枚举值?

正如我所读到的,在 Angular 6.1 或更高版本中,将有一种方法可以转换 .ts 中的值。但是,如果我现在想使用它呢?任何解决方法?

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

Gat*_*het 5

我也用 .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>
Run Code Online (Sandbox Code Playgroud)

我的 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>
Run Code Online (Sandbox Code Playgroud)