Springによる国際化
1646 ワード
<!-- Spring begin -->
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="defaultEncoding" value="UTF-8" />
<property name="basenames">
<list>
<value>classpath:valid/validation</value>
<value>classpath:local/message</value>
</list>
</property>
</bean>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<property name="defaultLocale" value="zh" />
</bean>
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
</mvc:interceptors>
以上はSpring国際化に必要な配置です.interceptorsがあったら、controllerは設置しなくてもいいです.下のようです.
Locall locale=null; locale=new Locale(「zh」、「CN」); //中国語 //locale=new Locale(「en」、「US」); //英語 request.get Session().set Attribute(Session Localle Resolaver.LOCALE_SESSIONUATTRIBUTENAME,locale);
ページの設定は以下の通りです.
<%@taglib prefix=「spring」uri=「http://www.springframework.org/tags」%
現在参照されているのはSpringタグです.fmtも使えます.
中国語English
以上が国際化を実現しました.