国际化资源命名规则
基名_en.properties :所有英文语言的资源基名_en_US.properties:针对美国地区、英文语言的资源基名_zh.properties:所有的中文语言的资源基名_zh_CN.properties:针对中国大陆的、中文语言的资源基名_zh_HK.properties:针对中国香港的、中文语言的资源基名.properties: 默认资源文件。如果请求相应语言的资源文件不存在,将使用此资源文件。例如,若是中国大陆地区用户,应该访问“基名_zh_CN.properties”,而如果不存在此文件,就会去访问默认的“基名.properties”。
添加国际化资源文件
配置springmvc.xml文件
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="com.znsd.spring.i18/message"></property>
</bean>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver"></bean>
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
</mvc:interceptors>
<mvc:annotation-driven />
<mvc:default-servlet-handler/>
<%@ page language
="java" contentType
="text/html; charset=UTF-8"
pageEncoding
="UTF-8"%>
<%@taglib prefix
="from" uri
="http://www.springframework.org/tags/form"%>
<%@taglib prefix
="tag" uri
="http://www.springframework.org/tags" %>
<!DOCTYPE html
>
<html>
<head>
<meta charset
="UTF-8">
<title>登录
</title
>
</head
>
<body>
<from
:form action
="login" method
="post" commandName
="user">
<tag
:message code
="login.name" />:
<from
:input path
="name"/>
<br
/>
<tag
:message code
="login.pass"/>:
<from
:password path
="pass"/>
<br
/>
<input type
="submit" value
="<tag:message code="login
.submit
"/>"/>
</from
:form
>
<a href
="login?locale=zh_CN">中文
</a
>
<a href
="login?locale=en_US">英文
</a
>
</body
>
</html
>
转载请注明原文地址: https://win8.8miu.com/read-1487932.html