gpt4 book ai didi

angular6 - Angular i18n - 插值

转载 作者:行者123 更新时间:2023-12-05 03:04:37 24 4
gpt4 key购买 nike

我正在关注 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>

我试过很多东西。我让它工作的唯一方法是通过硬编码值分钟改变节奏 strong> 变量直接在 中。但是,如果我这样做,我将无法在另一个页面中重复使用相同的翻译。

是否可以插入一个字符串 + 复数

最佳答案

Angular 将“字符串 + 复数”表达式拆分为 2 个更简单的表达式。

复数内部表达式获得一个随机标识符,它应该匹配 messages.xlf 文件中的跨单元“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"

关于angular6 - Angular i18n - 插值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52745049/

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