首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >符号翻译中的翻译

符号翻译中的翻译
EN

Stack Overflow用户
提问于 2014-05-21 01:28:12
回答 1查看 734关注 0票数 1

我的语言文件中有以下PHP翻译字符串:

代码语言:javascript
复制
'string.month'                         => '1 month',
'string.months'                        => '%month% months',

我用这个在我的Twig文件里:

代码语言:javascript
复制
{% 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至无穷)。

我该怎么做?

谢谢

EN

回答 1

Stack Overflow用户

发布于 2014-05-30 16:01:49

解决问题的最简单的方法是

翻译文件代码:

代码语言:javascript
复制
'string.months':       'one month|%count% months'

细枝文件代码:

代码语言:javascript
复制
{% set count = data.frequencyInMonths() %}
{{ "string.months"|transchoice(count) }}

如果您需要一条特殊的0月份消息(无一个月),则使用复杂方式

翻译文件代码:

代码语言:javascript
复制
'string.months': '{0} none months|{1} one month|]1,Inf] %count% months'

小枝文件代码与上次相同:

代码语言:javascript
复制
{% set count = data.frequencyInMonths() %}
{{ "string.months"|transchoice(count) }}

备注:您没有在翻译的第一个值处使用“字符”,所以您可以随时使用:

代码语言:javascript
复制
string.month: 'something about month'

如果您的翻译(第二个值)是简单字符串。因此,如果"something“字符串不包含任何特殊字符,则可以使用:

代码语言:javascript
复制
string.month: something about month
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23772580

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档