【发布时间】:2011-11-26 18:44:39
【问题描述】:
我刚刚阅读了很多内容并在 Google 上搜索过,但我现在很沮丧。
我有一个 Country 域模型
class Country{
String countryCode //maybe EN, DE, CH...
}
现在我想在 .我在documentation(和google)中读到,可以使用“id”从翻译消息属性文件中选择它。比如:
country.code.1=America
country.code.2=England
country.code.3=Germany
但这不是我想要的。我想要类似的东西:
country.code.US=America
country.code.EN=England
country.code.DE=Germany
所以,我从 stackoverflow 中找到了一个可能的解决方案:translate a HTML select element in Grails 这对我来说意味着我必须这样说:
<g:select name="country"
from="${allCountries}"
value="${country}"
optionKey="id"
optionValue="${ {countryCode->g.message(code:'country.code.'+countryCode)} }"/>
但我的结果在下拉列表中:“country.code.grails.Country : 1”(每个国家/地区以此类推)
如果我将 gsp-g:select 实现的最后一行更改为:
[...]optionValue="${ {countryCode->g.message(code:'country.code.US')}
如您所见,硬编码!这很有效:-D
希望你能得到我并能帮助我,非常感谢!
【问题讨论】:
标签: grails select internationalization