Symfony4 翻译复数化不起作用

Symfony4 pluralization on translation not working

当我对消息使用新的 ICU 格式时,复数化在 Symfony4.3 中部分起作用。

预期行为:One item found

当前行为:{1, plural, =0 {No items found.} one {One item found.} other {# items found.} }

翻译文件适用于其他翻译,所以配置我认为是正确的。在translations/messagges.en.yaml

msg:
    photos:
        uploaded: >
            {photos, plural,
                =0 {No items found.}
                one {One item found.}
                other {# items found.}
            }

并且在模板中有以下行:

{{ 'msg.photos.uploaded'|trans({'photos': 1}) }}

我相信,要使 ICU 消息格式起作用,文件名必须正确(更准确地说,域必须附加 +intl-icu):

https://symfony.com/doc/current/translation/message_format.html#using-the-icu-message-format

在你的例子中,文件名应该是:translations/messages+intl-icu.en.yaml 根据上面的来源。