在我的Grails 2.4.4应用程序中,我正在使用messages.properties进行国际化,其值如下:
my.app.thing.allowance(s)={0} Allowance(s)
它正在像这样的gsp中使用:
<g:message code="my.app.thing.allowance(s)" args="${item.allowances.size()}"/>
正确显示任何大于0的值的消息,例如
item.allowances.size() == 4
,则显示的消息为4 Allowances(s)
问题是,如果是
item.allowances.size() == 0
,那么显示的消息就是{0} Allowance(s)
我试图以几种不同的方式编写args,例如:
<g:message code="my.app.thing.allowance(s)" args="${item.allowances.isEmpty() ? 0.intValue() : item.allowances.size()}"/>
我已经调试了一些东西,并且我确定
item.allowances.size() == 0
但是由于某种原因它不能正确处理0值。将int值为0的参数传递给messages.properties的正确方法是什么?
最佳答案
在g.message
中,参数始终作为List
传递。
来自:http://docs.grails.org/3.0.17/ref/Tags/message.html
args (optional) - A list of argument values to apply to the message when code is used.
请尝试以下代码:
<g:message code="my.app.thing.allowance(s)" args="[item.allowances.size()]"/>
关于grails - 与messages.properties的参数有关的问题,除零以外的所有数字均可正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51561726/