2014-05-21 59 views
1

我在語言文件有這些PHP翻譯字符串:Transchoice在Symfony的翻譯

'string.month'       => '1 month', 
'string.months'      => '%month% months', 

而且我在我的枝條文件中使用這樣的:

{% 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() == 1string.months與注入數字的其他所有(即0和2無窮大)。

我該怎麼做?

感謝

回答

1

爲您解決問題的最簡單的方法是在這裏:

翻譯文件代碼:

'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' 

如果你的翻譯(第二個值)是簡單的字符串。所以如果「有關月份的東西」字符串不包含任何特殊字符,那麼你可以使用:

string.month: something about month