Internationalization using Spring ResourceBundleMessageSource and FMT

Related searches

We are trying to implement internationalization using Spring ResourceBundleMessageSource and FMT. But when we use it in the JSP, pages are displaying value as ???message.key???. Can you please help us in resolving this behavior? Really appreciate your answers.

Below are the configuration:

spring-servlet.xml entry

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

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

 <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver"/>


<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping">
    <property name="interceptors">
        <list>             
            <ref bean="localeChangeInterceptor" />                          
        </list>
    </property> 
</bean>

IN the JSP we have added the imported

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<fmt:message key="message.key"/>

Also in the war created we have the msgs.properties file under WEB-INF/messages folder.

Really appreciate help in identifying the mistake we are making. Thank you.

I am using the same as you and I am able to retrieve the messages from the properties file with fmt:message. Can you try to change the resource bundle for this:

<bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basenames">
            <list>
                <value>classpath:messages</value>
            </list>
        </property>
        <property name="defaultEncoding" value="UTF-8" />
        <property name="fallbackToSystemLocale" value="false"></property>
    </bean>

The properties are stored in src/main/resources.

Hope it helps.

Quick Introduction to Spring MVC Internationalization, We are trying to implement internationalization using Spring ResourceBundleMessageSource and FMT. But when we use it in the JSP, pages are displaying� In an interview if difference between BeanFactory and ApplicationContext is asked one of the reason given by people to use ApplicationContext is the support for internationalization provided by ApplicationContext. This post shows the same thing; how Internationalization (i18n) using ApplicationContext and MessageSource can be provided in Spring.

Using FMT taglibraries we could not solve the issue. I believe it has got some thing to do with the jstl jar and taglibs which we are using with JBoss 7.1.1 server.

We started using spring tlds for displaying the messages. All is working fine now. Thanks for the help.

Spring Resource bundle with ResourceBundleMessageSource , Learn how to set up the Spring MVC internationalization and localization at runtime, we can consider using the ReloadableResourceBundleMessageSource instead. taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%>. Learn how to set up the Spring MVC internationalization and localization support for your web application. We will go through the basic Spring MVC configuration. We will add necessary resources to support localization. We will explore the possibility of choosing a preferred language for displaying a page.

Use /WEB-INF/messages/msgs instead of WEB-INF/messages/msgs

Simply, add '/' at the beginning of path.

Internationalizing Your Application with Spring Framework i18n , How can I use the messages defined in the resource bundle in a JSP file? What tag should I use? fmt:message or spring:message? How to pass� Spring is a popular Java application framework for creating enterprise applications.. Spring MessageSource. MessageSource is used for resolving messages, with support for the parameterization and internationalization of the messages.

5.13. Internationalization — TERASOLUNA Server Framework for , In addition to this, you can use Spring's i18n support throughout your code rather than A ResourceBundle is a collection (not a Collection) of message keys that are mapped to If the basenames you specify in the javax.servlet.jsp.jstl.fmt. This page will provide Spring MVC internationalization (i18n) and localization (l10n) annotation example. Here internalization (i18n) is creating our website in more than one languages and Localization (l10) is accessing website in any specific language by setting the locale.

In Spring MVC application, comes with few “LocaleResolver” to support the internationalization or multiple languages features.In this tutorial, it shows a simple welcome page, display the message from properties file, and change the locale based on the selected language link.

public class ResourceBundleMessageSource extends AbstractMessageSource. MessageSource that accesses the ResourceBundles with the specified basenames. This class relies on the underlying JDK's java.util.ResourceBundle implementation. Unfortunately, java.util.ResourceBundle caches loaded bundles indefinitely.

Comments
  • Thanks for your reply. But still not resolving the issue. We have multiple spring contexts with one web app contexts. We are defining this messageSource as part of web application context. is it right? do we have dependency on the page encoding type in the JSPs? We are using 3.1.2 release version of spring. Let me know your thoughts.
  • Will it have any dependencies on the version of JSTL ? We are using the one provided by JBoss 7.1.1.