Click here to Skip to main content
15,891,785 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi all,

I am new in spring mvc 2.5 framework, I want to develop internationalization in my web application.

please help me

thanks in advance

=========web.xml=========
<web>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
</web>


// dispatcher-servlet.xml //

<bean id="beanValidator" class="org.springmodules.validation.commons.DefaultBeanValidator" p:validatorFactory-ref="validatorFactory"/>
<bean id="validatorFactory" class="org.springmodules.validation.commons.DefaultValidatorFactory">
<property name="validationConfigLocations" >
<list>
<value>/WEB-INF/validator-rules.xml</value>
<value>/WEB-INF/validation.xml</value>
</list>
</property>
</bean>

<bean id="urlMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
<property name="interceptors">
<list>
<ref bean="localeChangeInterceptor" />
</list>
</property>
<property name="order" value="1" />
</bean>
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />
</bean>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="cookieMaxAge">
<value>3600</value>
</property>
<property name="defaultLocale" value="en" />
</bean>
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource" p:basename="messages" />

<bean name="/Login.htm" class="controller.LoginController" p:sessionForm="true" p:commandName="loginCommand"
p:commandClass="bean.LoginCommand" p:formView="Login" p:validator-ref="beanValidator"/>

//jsp file ///
</b><a href="?lang=en_US">English</a><b>
user name-- text box
password -- text box
submit button

Login.jsp name


please advice me but when I click on submit there is some validation which show messages from messages.properties file
thanks in advance
Posted

check this: i18n Tutorial for Spring Framework[^]

a self developed attempt could look something like this:

Java
public final class MultiLanguageSupport {
 
    public static ResourceBundle    oMap        = ResourceBundle.getBundle("resource/language/language");
    private static Logger           oLogger     = Logger.getLogger(MultiLanguageSupport.class);

    static {
        // load oMap with key/values according to selected language
    }

    public static final String getString(final String strKey) {
        final String strReturn = MultiLanguageSupport.oMap.getString(strKey);
        if ((null == strReturn) || (strReturn.length() == 0)) {
            // error logging - string not found
        }
        return strReturn;
    }

}


The Map is filled as soon as this class is called. you can then get your Strings with MultiLanguageSupport.getString(KEY).

You should also check out this tool: http://sourceforge.net/projects/eclipse-rbe/
Works fine for me and gives you better control on the language files.
 
Share this answer
 
v2
thanks for your reply

I have found my mistake the above code is right but there is problem with my LoginController which have formbackingobject method and controller extends SimpleFormController class...

when I used this method it will work properly -handleRequestInternal(req,res)
but I want to use i18n in my existing application there is LoginController which have extends SimpleFormController Class and have onSubmit() method , formbacking method and various logic so how I can applied i18n in existing web application using Spring mvc 2.5

thanks in advance
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900