Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve active locale in Grails application

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"

like image 322
thomers Avatar asked Aug 30 '11 14:08

thomers


2 Answers

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)
like image 167
Joshua Moore Avatar answered Oct 04 '22 05:10

Joshua Moore


You can also use the LocaleContextHolder which doesn't need a request as a parameter

import org.springframework.context.i18n.LocaleContextHolder;

LocaleContextHolder.getLocale();
like image 24
Topera Avatar answered Oct 04 '22 06:10

Topera