1

我正在关注 Angular i18n 指南:https ://angular.io/guide/i18n

我知道如何正确插入“字符串+变量”。

<trans-unit id="interpolated-persons" datatype="html">
        <source>Persons: <x id="INTERPOLATION" equiv-text="{{number-of-people}}"/></source>
        <target>Personas: <x id="INTERPOLATION" equiv-text="{{number-of-people}}"/></target>
</trans-unit>

<span i18n="@@interpolated-persons">Persons: {{persons}}</span>

但是,我不知道如何插入“ String + Plural ”。

<trans-unit id="interpolated-time" datatype="html">
        <source>Time: <x id="ICU" equiv-text="{tempo, plural, other {...}}"/></source>
        <target>Tiempo: {tempo, plural, =60 {una hora} =1440 {un día} =10080 {una semana} other {mucho tiempo}}</target>
</trans-unit>

<span i18n="@@interpolated-time">Time: {minutes, plural, other {{{minutes}} elapsed}}</span><br>

我已经尝试了几件事。我让它工作的唯一方法是通过硬编码值或直接在 <target> 中的分钟变量来改变速度。但是,如果我这样做,我将无法在另一个页面中重复使用相同的翻译。

是否可以插入String + Plural

4

1 回答 1

2

Angular 将“String + Plural”表达式拆分为 2 个更简单的表达式。

复数内部表达式获得一个随机标识符,它应该与 messages.xlf 文件中的 trans-unit "id" 匹配才能工作。

https://angular.io/guide/i18n中的精确翻译嵌套表达式示例应该是这样的:

<trans-unit id="interpolated-time" datatype="html">
    <source>Updated: <x id="ICU" equiv-text="{minutes, plural, =0 {...} =1 {...} other {...}}"/></source>
    <target>Actualizado: <x id="ICU" equiv-text="{minutes, plural, =0 {...} =1 {...} other {...}}"/></target>
  </trans-unit>
  <trans-unit id="7151c2e67748b726f0864fc443861d45df21d706" datatype="html">
    <source>{VAR_PLURAL, plural, =0 {just now} =1 {one minute ago} other {<x id="INTERPOLATION" equiv-text="{{minutes}}"/> minutes ago by {VAR_SELECT, select, male {male} female {female} other {other} }} }</source>
    <target>{VAR_PLURAL, plural, =0 {justo ahora} =1 {hace 1 minuto} other {hace <x id="INTERPOLATION" equiv-text="{{minutes}}"/> minutos por {VAR_SELECT, select, male {un hombre} female {una dama} other {otro} }} }</target>
  </trans-unit>

id 7151c2e67748b726f0864fc443861d45df21d706应该从编译输出中获得:

Missing translation for message "7151c2e67748b726f0864fc443861d45df21d706"
于 2018-10-11T09:17:09.717 回答