Wednesday, January 11, 2012

Internationlization in Spring

  1. Add the follwoing bean definitions in "{project}-sevlet.xml"
        <!-- Add for Internationlization -->
        <bean id="localeChangeInterceptor"
            class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
            <property name="paramName" value="lang" />
        </bean>

        <bean id="localeResolver"
            class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
        </bean>
  2. Use the following "<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> from "ResourceBundleMessageSource" to "ReloadableResourceBundleMessageSource".
  3. Add "classpath:" prefix to all the messages in the "basenames" property.
  4. Add the "<ref bean="localeChangeInterceptor"/>" as an interceptor to "urlMapping" bean.
  5. Create sepearte "{Messsage}_{lang}.properties file.
  6. Change the language by submitting "?lang={lang}" and appropriately the messages will be loaded from the language.

No comments: