Selva
Selva

Reputation: 1670

spring3 internationalization not working properly

I am newbie to spring.I used spring internationalization in my project.Below is my configuration

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

<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
    <property name="defaultLocale" value="en"/>
</bean>

    <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
    <property name="paramName" value="lang" />
   </bean>


<bean id="handlerMapping"
    class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
    <property name="interceptors">
        <ref bean="localeChangeInterceptor" />
    </property>
</bean>

In the properties folder i have three files. messages.properties

label.username=user

messages_en.properties

label.username=hddhd

messages_es.properties

label.username=lalal

i display the message using <spring:message code="label.username" /> this tag.

But this one always prints the value from messages.properties. It always prints user.

even i give the url like below

[http://localhost:8080/Project/?lang=en
http://localhost:8080/Project/?lang=es][1]

why values not taken from the files messages_en and messages_es

Any help will be greatly appreciated!!!

Upvotes: 1

Views: 344

Answers (2)

paulos
paulos

Reputation: 32

Don't forget to add this line

<%@ page contentType="text/html;charset=UTF-8" %>

Upvotes: 0

M. Deinum
M. Deinum

Reputation: 125242

When using <mvc:annotation-driven /> configuring the DefaultAnnotationHandlerMapping will not work. You should use the <mvc:interceptors /> element to register the interceptors.

<mvc:interceptors>
    <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
        <property name="paramName" value="lang" />
    </bean>
</mvc:interceptors>

Next to that it doesn't work in newer versions of Spring (everything after 2.5) doesn't use the DefaultAnnotationHandlerMapping anymore in case of <mvc:annotation-driven />.

Upvotes: 2

Related Questions