spring i18n

2023-11-04

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>

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

spring i18n 的相关文章

随机推荐