spring i18n

来源:互联网 发布:cr2打开软件 编辑:程序博客网 时间:2024/06/06 00:27

1Spring config

 

<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" />

<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">

       <property name="order" value="0" />

       <property name="interceptors" ref="localeChangeInterceptor" />   

</bean>

 

 

2All scope change header

<%

java.util.Locale _currentLocale = org.springframework.web.servlet.support.RequestContextUtils.getLocale(request);

 

String _localeAsString = _currentLocale.toString();

%>

 

<c:set var="localeAsString" value="<%=_localeAsString%>"/>

<c:set var="localeSwitchingUrlSc" value="?locale=zh_CN"/>

<c:set var="localeSwitchingUrlTc" value="?locale=zh_HK"/>

<c:set var="localeSwitchingUrlEn" value="?locale=en_US"/>

 

 

<c:choose>

    <c:when test="${localeAsString eq 'zh_CN'}">

       <a href="${localeSwitchingUrlEn}">

           go to english

       </a>

    </c:when>

    <c:otherwise>

       <a href="${localeSwitchingUrlSc}">

           goto chinese

       </a>

    </c:otherwise>          

</c:choose>

 

3Display content

<spring:message code="i18n.testing.key.one" text="default value">

</spring:message>

原创粉丝点击