我的语言文件中有以下PHP翻译字符串:
'string.month' => '1 month',
'string.months' => '%month% months',我用这个在我的Twig文件里:
{% transchoice data.frequencyInMonths() with {'%month%': data.frequencyInMonths()} from "strings" %}
{0,[2,Inf]} string.months|trans({'%month%' : data.frequencyInMonths()})|{1} string.month|raw
{% endtranschoice %}很明显这不管用。我只想让string.month使用data.frequencyInMonths() == 1,把string.months的数字注入到其他任何东西(即。0和2至无穷)。
我该怎么做?
谢谢
发布于 2014-05-30 16:01:49
解决问题的最简单的方法是:
翻译文件代码:
'string.months': 'one month|%count% months'细枝文件代码:
{% set count = data.frequencyInMonths() %}
{{ "string.months"|transchoice(count) }}如果您需要一条特殊的0月份消息(无一个月),则使用复杂方式:
翻译文件代码:
'string.months': '{0} none months|{1} one month|]1,Inf] %count% months'小枝文件代码与上次相同:
{% set count = data.frequencyInMonths() %}
{{ "string.months"|transchoice(count) }}备注:您没有在翻译的第一个值处使用“字符”,所以您可以随时使用:
string.month: 'something about month'如果您的翻译(第二个值)是简单字符串。因此,如果"something“字符串不包含任何特殊字符,则可以使用:
string.month: something about monthhttps://stackoverflow.com/questions/23772580
复制相似问题