Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Spring框架中实现i18n(带有gTLDs的子目录)?_Java_Spring_Spring Mvc_Internationalization - Fatal编程技术网

Java 如何在Spring框架中实现i18n(带有gTLDs的子目录)?

Java 如何在Spring框架中实现i18n(带有gTLDs的子目录)?,java,spring,spring-mvc,internationalization,Java,Spring,Spring Mvc,Internationalization,我正在开发一个使用Spring框架、Spring(MVC)、Spring安全性等的web应用程序。。。 Spring文档显示了在URL中添加参数的国际化过程(例如) 但我读过谷歌的这篇文章,其中指出不推荐这种做法 因此,我决定以这种方式实施: ->默认语言环境(英语) ->语言环境 ->locale fr 我的问题是:在Spring框架中实现i18n(带有gtld的子目录)的最佳方法是什么?欢迎提供想法、文章和示例 <!-- Defines interceptors for Loca

我正在开发一个使用Spring框架、Spring(MVC)、Spring安全性等的web应用程序。。。 Spring文档显示了在URL中添加参数的国际化过程(例如) 但我读过谷歌的这篇文章,其中指出不推荐这种做法

因此,我决定以这种方式实施:

->默认语言环境(英语)

->语言环境

->locale fr

我的问题是:在Spring框架中实现i18n(带有gtld的子目录)的最佳方法是什么?欢迎提供想法、文章和示例


  <!-- Defines interceptors for Locale change and Theme change before the request goes to DispatcherServlet for further operation. -->


     <mvc:interceptors>
        <ref bean="localeChangeInterceptor"/>
        <ref bean="themeChangeInterceptor" />
        <!-- <ref bean="conversionServiceExposingInterceptor"/> -->
        </mvc:interceptors>

    <!-- Interceptor for change in Locale -->
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="language"/>
</bean>

    <!-- LocaleResolver configuration for internationalization. Here cookie resolver used. Stores and reads the locale value from cookie. -->
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="1"/>
<property name="cookiePath" value="/WEBPORTAL/" />
<property name="cookieName" value="locale"/>
<property name="cookieMaxAge" value="86400"/>
<property name="cookieHttpOnly" value="true"/>
<property name="cookieSecure" value="true"/>
</bean>

    <!-- Provides the list of base location for Localized property files. Default encoding must be UTF-8 to support multilingual text. -->
    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basenames">
        <list>
        <value>/WEB-INF/i18n/labels</value>
        <value>/WEB-INF/i18n/messages</value>
        <value>/WEB-INF/i18n/mailBox</value>
        <value>/project</value>
        </list>
    </property>
    <property name="defaultEncoding" value="UTF-8"/>
    </bean>
/WEB-INF/i18n/labels /WEB-INF/i18n/messages /WEB-INF/i18n/邮箱 /计划
下面是一些帮助您实现国际化的代码 您只需要将这几行代码添加到dispatcher-servlet.xml文件中,然后根据需要进行更改


希望我的回答能引导您……

实现您自己的拦截器。默认实现是使用请求参数,您可以自由实现自己的请求参数。您也可以使用url重写,但这感觉太过分了。