This configures the web application for internationalized messages that can then be displayed in a JSP page using the JSTL message format tag.
The basenames property of ResourceBundleMessageSource
is set to 'messages' which will then look for
the default message resource of messages.properties. Based on different locales, other property files can be defined like messages_es.properties for Spanish.
The LocaleChangeInterceptor
is configured to look for the parameter name 'locale' to indicate a change of the user's locale,
and is registered as an interceptor using the Spring MVC Namespace. The Spring MVC Namespace is new in Spring 3.0.
For example, adding 'locale=es' to a URL would change the locale to Spanish. The SessionLocaleResolver
keeps
the user's currently configured locale in session scope.
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource" p:basenames="messages" /> <!-- Declare the Interceptor --> <mvc:interceptors> <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" p:paramName="locale" /> </mvc:interceptors> <!-- Declare the Resolver --> <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" />