n00b n00b - 1 year ago 71
Java Question

Locale only getting values for default locale while other locale is not displaying

hi I am working on spring locale but it is still getting values from one locale not from other here is my code so far

<mvc:annotation-driven enable-matrix-variables="true" />
<context:component-scan base-package="com.*" />
<bean id="messageSource"
<property name="basenames">
<property name="defaultEncoding" value="UTF-8" />
<bean id="localeResolver"
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="language" />

and this is I am using in my page.jsp

<%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<a href="?language=en">English</a>| <a href="?language=nl">Dutch</a>
<spring:message code="tagline"></spring:message>

For English, everything works fine but while clicking on
its also showing English too, how to resolve that?

this is only data in my files :

1 message_en.properties
tagline=This is English

2 message_nl.properties
tagline=This is dutch

Please Help

Answer Source

Do you have <mvc:annotation-driven /> in you config. Also your <mvc:interceptors> should be like below.

        <mvc:mapping path="/**" />
          <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
              <property name="paramName" value="language" />

And MessageSource bean

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
   <property name="basename" value="messages" />

Your properties file should be like below.


Check this post.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download