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)
You can also use the LocaleContextHolder
which doesn't need a request as a parameter
import org.springframework.context.i18n.LocaleContextHolder;
LocaleContextHolder.getLocale();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With