在Grails应用程序中检索活动语言环境 [英] Retrieve active locale in Grails application

查看:83
本文介绍了在Grails应用程序中检索活动语言环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以使用lang参数自动更改当前的语言环境,如 docs ,但是如何跟踪这些更改,例如更新存储在当前用户域对象中的语言?

request.locale 不起作用,因为它不反映通过?lang = xx 完成的更改

解决方案

在您的控制器中,您可以使用 RequestContextUtils 获取语言环境。

  import org.springframework.web.servlet.support.RequestContextUtils as RCU 

然后解决请求的语言环境:

  RCU.getLocale请求)


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 does not work, since it does not reflect the changes done via "?lang=xx"

解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆