在 Grails 应用程序中检索活动区域设置 [英] Retrieve active locale in Grails application
本文介绍了在 Grails 应用程序中检索活动区域设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我可以使用lang"参数自动更改当前区域设置,如 docs,但我如何跟踪这些更改,例如更新存储在当前用户域对象中的语言?
I know I can use the "lang" parameter to automatically change the current locale as described in the docs, but how do I track those changes, for example to update the language stored in the current user domain object?
request.locale
不起作用,因为它没有反映通过?lang=xx
"
request.locale
does not work, since it does not reflect the changes done via "?lang=xx
"
推荐答案
在您的控制器中,您可以使用 RequestContextUtils
获取区域设置.
Within your controller you can obtain the locale using the RequestContextUtils
.
import org.springframework.web.servlet.support.RequestContextUtils as RCU
然后解析请求的语言环境:
Then to resolve the locale for the request:
RCU.getLocale(request)
这篇关于在 Grails 应用程序中检索活动区域设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文