在我的Grails 2.4.4应用程序中,我使用messages.properties进行国际化,具有以下值:
my.app.thing.allowance(s)={0} Allowance(s)
Run Code Online (Sandbox Code Playgroud)
它正在使用像这样的gsp:
<g:message code="my.app.thing.allowance(s)" args="${item.allowances.size()}"/>
Run Code Online (Sandbox Code Playgroud)
对于任何大于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()}"/>
Run Code Online (Sandbox Code Playgroud)
我调试过的东西,我确信item.allowances.size() == 0
但由于某种原因,它无法正确处理值0.将一个int值为0的参数传递给messages.properties的正确方法是什么?
在g.message
参数中总是作为一个传递List
.
来自:http://docs.grails.org/3.0.17/ref/Tags/message.html
args(可选) - 使用代码时应用于消息的参数值列表.
请尝试使用此代码:
<g:message code="my.app.thing.allowance(s)" args="[item.allowances.size()]"/>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
95 次 |
最近记录: |