symfony2 transchoice翻译

时间:2012-06-05 00:18:42

标签: symfony translation yaml twig pluralize

我正在翻译activity.fr.yml

中的以下密钥
user.list.link: '{1}et %count% autre|]1,Inf[voir les %count% autres'

使用tranchoice

<a href="{{ moreLink }}" >{% transchoice count from "activity" %}user.list.link{% endtranschoice %}</a>

我收到以下错误

An exception has been thrown during the rendering of a template ("Unable to choose a translation.")

我认为翻译已被发现,否则我不会收到关于无法选择翻译而是关键本身的错误。

同样的yaml甚至其他杂志的所有其他键都被很好地翻译了。

我关注doc并尝试添加with {'%count%': count}但没有成功。

有人知道这里有什么问题吗? 提前致谢

2 个答案:

答案 0 :(得分:6)

语法很好但是%count%的值传递不能为负,也不能等于0,因为复数字符串中没有{0}定义。 所以我进行了一项测试,以确保该值为&gt; = 0并修改了这样的字符串并修复了它。

user.list.link: '{0}|{1}et %count% autre|]1,Inf[voir les %count% autres'

答案 1 :(得分:2)

您需要传递用于确定将要选择的翻译的参数。

查看以下示例in the doc

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

改编自您的示例:

{% transchoice count with {'%count%': count} from "activity" %}
    user.list.link
{% endtranschoice %}

如果它不起作用,可能找不到您的翻译。因此,symfony使用您的密钥作为后备,并且无法确定有效选择,因为您的密钥不支持此功能。

要检查这一点,请尝试使用以下密钥:

user.list.link | user.list.link.many

不要忘记在活动目录中使用相同的密钥。

相关问题