Search code examples
springinternationalizationlocaleinterceptor

problem with i18n (internationalization) with Spring and Velocity


I am having a problem in setting up internationalization with Spring. Here is my config.

    <bean id="messageSource"
            class="org.springframework.context.support.ResourceBundleMessageSource">
            <property name="basename" value="localization" />
    </bean>
    <!-- declare the resolver -->
    <bean id="localeResolver"
            class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
            <property name="defaultLocale" value="sv" />
    </bean>
    <mvc:interceptors>
            <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
    </mvc:interceptors>
    <mvc:annotation-driven />

It always showing me English even when I request with ?locale=sv (Swedish).

I am using Spring with Velocity.

any idea? thanks


Solution

  • This is how I did:

    • First copied messages_xx.properties in src/main/resources I could not get it to work with name messages_xx_xx (messages_en_us)

    • Then just added following configs to xxxx_servlet.xml context

      <bean id="messageSource"
              class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
              <property name="basename" value="classpath:messages" />
              <property name="defaultEncoding" value="UTF-8" />
      </bean>
      

        <mvc:interceptors>
        <bean id="localeChangeInterceptor"
            class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
            <property name="paramName" value="lang"/>
        </bean>
        </mvc:interceptors>
    
        <mvc:annotation-driven/>
    
    • Used #springMessages('message.title') in my *.vm

    that was it.