我正在处理Grails i18n消息。我在resources.groovy
中添加了代码localeChangeInterceptor(ParamsAwareLocaleChangeInterceptor) {
paramName = "locale"
}
localeResolver(org.springframework.web.servlet.i18n.SessionLocaleResolver) {
defaultLocale = new Locale("en")
java.util.Locale.setDefault(defaultLocale)
}
在messages_he.properties
_appNav.apps.show-label-button.title = הצג תוויות
但它没有被选中,
session.'org.springframework.web.servlet.i18n.SessionLocaleResolver.LOCALE'
上面的代码给出了"iw"
答案 0 :(得分:0)
我使用这种更复杂的方式工作,params.lang = he_IL
收到此信息然后查找
import org.springframework.web.servlet.support.RequestContextUtils as RCU
Locale = getLocaleForLanguage(params.lang)
session.'org.springframework.web.servlet.i18n.SessionLocaleResolver.LOCALE' = locale
session.language = locale.language
session.locale = locale
session.langConfirmed=true
if (updateReq) {
RCU.getLocaleResolver(request).setLocale(request, response, locale)
}
static Locale getLocaleForLanguage(String language) {
if (language.contains('_')) {
def splitLang=language.split('_')
return
Locale.getInstance(splitLang[0].toLowerCase(),splitLang[1].toUpperCase(),'')
}
return Locale.getInstance(language,'','')
}
然后是一个名为messages_iw.properties