例如,你有:2語言
messages_ch_CN.properties /*in the property file lang=Chinese*/
messages_en_EN.properties /*in the property file lang=English*/
messages.properties /*in the property file lang=English default*/
messages.properties
這是默認的屬性,它總是包含在整個應用程序使用的每個關鍵。
和NAME-servlet.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<context:component-scan base-package="com.example.controller"/>
<mvc:annotation-driven/>
<mvc:resources mapping="/resources/**" location="/resources/"/>
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:com/example/i18n/messages"/>
<property name="fallbackToSystemLocale" value="false"/>
<property name="defaultEncoding" value="UTF-8"/>
</bean>
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang"/>
</bean>
</mvc:interceptors>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="en"/>
</bean>
</beans>
<property name="fallbackToSystemLocale" value="false"/>
- 說的是,如果你沒有財產messages_ch_CN.properties
或messages_en_EN.properties
或在這些財產的一個沒有必要的密鑰,例如:標題,春天將使用messages.properties
默認爲
if <property name="fallbackToSystemLocale" value="true"/>
- spring使用用戶本地化的部署環境,但它不好,因爲用戶的部署環境可能與我們提供的語言不同。如果用戶的語言環境與我們提供的語言不同,則彈簧使用messages.properties
。
非常感謝...它工作正常 – Dineshkumar 2014-04-03 12:29:07