3lite
Dec 10th, 2007, 09:08 AM
I would like to localization without forcing the user to enable cookies. I thought that allowing a request parameter like ?lang=en would be nice because it would also allow the users to bookmark the page to display in their desired language.
However, I cannot find any reasonable documentation on how to do this on either the online Spring documentation or in the book Pro Spring, both of which have a mere 1-sentence to describe that SessionLocaleResolver exists, but without actually saying how to use it.
As far as I can make it out, I have added the following entries to the dispatcher-servlet.xml file:
<bean
class="org.springframework.web.servlet.handler.SimpleUrlH andlerMapping">
<property name="interceptors">
<list>
<ref bean="langChangeInterceptor" />
</list>
</property>
<property name="mappings">
<value>
/**/*.html=defaultController
/=defaultController
</value>
</property>
</bean>
<bean id="langChangeInterceptor"
class="org.springframework.web.servlet.i18n.LocaleChangeI nterceptor">
<property name="paramName" value="lang" />
</bean>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.SessionLocale Resolver" />
<bean id="messageSource"
class="org.springframework.context.support.ReloadableReso urceBundleMessageSource">
<property name="basename" value="messages" />
</bean>
I also have a pair of messages files:
messages.properties
messages_de.properties
I have done nothing else. Is this really all that is needed for session localization in Spring or do I also need to programatically do something to enable it?
Strangely enough, I get by default the German messages despite the fact that I am running on en_US Windows XP with a local en_US installation of Tomcat 6, an en_US installation of Java 6 and calling the webapp in an en_US version of Firefox 2! I have no idea where it is getting the German language/locale from and have even placed debugging output in my controller class where request.getLocale() returns en_US as expected.
So... why is it localizing to German by default and why doesn't it change the localization even when I give ?lang=en in the request as a parameter in the URL?
However, I cannot find any reasonable documentation on how to do this on either the online Spring documentation or in the book Pro Spring, both of which have a mere 1-sentence to describe that SessionLocaleResolver exists, but without actually saying how to use it.
As far as I can make it out, I have added the following entries to the dispatcher-servlet.xml file:
<bean
class="org.springframework.web.servlet.handler.SimpleUrlH andlerMapping">
<property name="interceptors">
<list>
<ref bean="langChangeInterceptor" />
</list>
</property>
<property name="mappings">
<value>
/**/*.html=defaultController
/=defaultController
</value>
</property>
</bean>
<bean id="langChangeInterceptor"
class="org.springframework.web.servlet.i18n.LocaleChangeI nterceptor">
<property name="paramName" value="lang" />
</bean>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.SessionLocale Resolver" />
<bean id="messageSource"
class="org.springframework.context.support.ReloadableReso urceBundleMessageSource">
<property name="basename" value="messages" />
</bean>
I also have a pair of messages files:
messages.properties
messages_de.properties
I have done nothing else. Is this really all that is needed for session localization in Spring or do I also need to programatically do something to enable it?
Strangely enough, I get by default the German messages despite the fact that I am running on en_US Windows XP with a local en_US installation of Tomcat 6, an en_US installation of Java 6 and calling the webapp in an en_US version of Firefox 2! I have no idea where it is getting the German language/locale from and have even placed debugging output in my controller class where request.getLocale() returns en_US as expected.
So... why is it localizing to German by default and why doesn't it change the localization even when I give ?lang=en in the request as a parameter in the URL?