I am working on one web app project which supports multiple languages.
I am using Spring framework. Spring has option to support multiple language by adding the following beans in dispatcher servlet.
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<property name="defaultLocale" value="en" />
</bean>
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**" />
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="language" />
</bean>
</mvc:interceptor>
</mvc:interceptors>
<!-- Register the messages.properties -->
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="UTF-8" />
</bean>
The localization works only if I pass language parameter in every URL.
Is there any option to set locale based on the client's browser language?
SessionLocaleResolverwithAcceptHeaderLocaleResolverand remove theLocaleChangeInterceptor(as you won't be able to change it then). It would also work if you remove thedefaultLocaleproperty from theSessionLocaleResolverbecause when not set it will use the one received from the browser.