Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Enhanced example to make it clear that a new LocaleResolver bean is required.


Enabling locale change persistance via a cookie is done by defining the CookieLocaleResolver bean and optionally changing it's defaults:


Here we changed the cookiename to be lang instead. Now you can set a cookie called lang to be any locale your IDP supports, e.g. en_GB . This can be done via Javascript e.g. or use the LocaleChangeInterceptor below.

URL query string based locale changing

To change the locale via an URL query string parameter you have to enable it via an interceptor:define two beans: a LocaleChangeInterceptor that will inspect request parameters and a LocaleResolver that will remember the locale change, like the CookieLocaleResolver above or SessionLocaleResolver (the present-by-default AcceptHeaderLocaleResolver does not allow locale changes).

Code Block
title LocaleChangeInterceptor configuration
  <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
    <property name="paramName" value="lang"/>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
  <property name="defaultLocale" value="en"/>

Here we enabled changing the locale based on the URL query string parameter lang. This will be persisted to the cookie, if you configured it above and set a fallback locale of "en".


See documentation for: