Twig Symfony 5 中的复数

Plurals in Twig Symfony 5

从 Twig 3.x 开始,过滤器 transchoice 已弃用,我试图弄清楚 Twig 的正确语法是怎样的,如 docs are centered in php语法。

这是我的 messages.en.yml 文件:

client: >-
            {number, plural,
                one {Client}
                other {Clients}
            }

这是我的树枝模板,试图根据 this doc:

弄清楚它应该是什么
{{"client"|trans({'number': 2})}}

结果是这个字符串,也就是变量number没有被处理:

{2, plural, one {Client} other {Clients} }

那么,根据数字只看到 ClientClients 的正确语法是什么?

以这种方式构建您的翻译是使用 ICU 消息格式。为了使用 ICU 消息格式,消息域文件必须以 +intl-icu.

为后缀

确保你 name your file correctly:

translations/messages+intl-icu.en.yaml