Internationalization 如何使用Twig和i18n扩展名创建复数翻译?

Internationalization 如何使用Twig和i18n扩展名创建复数翻译?,internationalization,twig,slim,gettext,twig-extension,Internationalization,Twig,Slim,Gettext,Twig Extension,我正在使用带有Twig和Twig扩展i18n的Slim PHP框架。我需要创建一个复数翻译来显示数组中的消息数。我正在使用文本编辑器创建.po文件,并使用Poedit将其编译为.mo文件 这是我的模板: {% set count=messages|length %} {% trans %} Showing the last message. {% plural count %} Showing the

我正在使用带有Twig和Twig扩展i18n的Slim PHP框架。我需要创建一个复数翻译来显示数组中的消息数。我正在使用文本编辑器创建
.po
文件,并使用Poedit将其编译为
.mo
文件

这是我的模板:

        {% set count=messages|length %}
        {% trans %}
            Showing the last message.
        {% plural count %}
            Showing the last {{count}} messages.
        {% endtrans %}<br>
这不管用,它给了我

Visar de %count senaste meddelandena.
即使
计数
为16

我哪里做错了

提出以下用法

{% transchoice count %}
    {1} Showing the last message.|]1,Inf[ Showing the %count% messages.
{% endtranschoice %}
一个更复杂的例子:

{% transchoice count with {'%name%': 'Fabien'} from 'app' %}
    {0} %name%, there are no apples|{1} %name%, there is one apple|]1,Inf[ %name%, there are %count% apples
{% endtranschoice %}

%count
应该是
%count%
。政府有以下例子:

在gettext查找过程中,这些占位符将被转换
{{name}
变为
%name%
,因此此字符串的gettext
msgid
将是
Hello%name%


应该是
%count%
而不是
%count
?例如:“在gettext查找过程中,这些占位符被转换。
{{name}
变成了
%name%
,所以这个字符串的gettext
msgid
将是
Hello%name%!
“@martias你说得对,用
%count%
替换
%count
就行了!我错过了文档中的那一段,我使用的模板是某个在线po编辑站点的演示,该站点在示例中使用了
%s
,因此我假设这是正确的语法。
{% transchoice count with {'%name%': 'Fabien'} from 'app' %}
    {0} %name%, there are no apples|{1} %name%, there is one apple|]1,Inf[ %name%, there are %count% apples
{% endtranschoice %}
{% trans %}
    Hello {{ name }}!
{% endtrans %}