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
.Then to resolve the locale for the request:
Grails uses Spring internally. You can get the current locale from Spring's RequestContextUtils: http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/web/servlet/support/RequestContextUtils.html#getLocale(javax.servlet.http.HttpServletRequest)
Check <g:message> tag source for more info:
http://grails.org/doc/latest/ref/Tags/message.html
If you display
properties
ofRequestContextUtils.getLocale(request)
, you will find the following :You can also use the
LocaleContextHolder
which doesn't need a request as a parameter