如何在Spring MVC中使用国际化

时间:2016-03-15 05:58:21

标签: jsp spring-mvc

我希望我的应用程序支持多种语言环境,我有特定于语言环境的属性,

messages_en.properties:

var element = document.querySelector('.username'); // username div wrapper

//if {

element.addEventListener('DOMSubtreeModified', function() { // detect if div element changes
  var date = new Date();
  var month = date.getUTCMonth() + 1;
  var day = date.getUTCDate();
  var year = date.getUTCFullYear();

  var time = date.toLocaleTimeString();
  var formattedDate = month + '/' + day + '/' + year;

  console.log(time); // 7:01:21 PM
  console.log(formattedDate); // 3/15/2016
}, false);

// change something on element
setTimeout(function() {
  element.dataset.username = 'bar';
}, 3000);

// json object with captured data fields

var NewUserSession = [{ 

    currentusername: $('.username').text(),
    referrer: document.referrer,
    loggedintime: $(formattedDate),

}];

//}
//
//else { 
//
//
//}

messages_fr.properties:

login.username=User Name: 

下面是我的servlet-context.xml

login.username=Nom d'utilisateur:

的login.jsp:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <context:component-scan base-package="com.mobistar.eidsar.controller" />
    <context:property-placeholder location="classpath:validation.properties"/>
    <mvc:annotation-driven />
    <mvc:resources mapping="/images/**" location="/WEB-INF/images/" />
    <mvc:resources mapping="/css/**" location="/WEB-INF/css/" />

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

    <bean id="localeResolver"
        class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
        <property name="defaultLocale" value="en" />
    </bean>

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

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

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/views/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>
</beans>    

但是当我从EN导航到FR时,我没有在FR中获取UserName,

任何人都可以帮助我,我做错了什么?任何帮助都将受到高度赞赏。

0 个答案:

没有答案