Thursday, June 14, 2012

Internationalization(i18n) in Spring 3.0


Entries in your application context xml file:

<bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
          
    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource" p:basename="messages" />

Entry in messages.properties files that you will put in src folder:
Password = Password

For English use messages_en.properties
For French use messages_fr.properties

It will automatically pick the property file corresponding to the language set in you browser language option.

Entries in JSP:

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>

Your text:
<spring:message code="Password"/>

No comments:

Post a Comment