2013-06-03 52 views
1

我试图根据客户机的操作系统语言环境让我的应用程序工作。目前它适用于服务器机器的语言环境。我正在使用字符串frmae工作。 Apache Tomcat 7被用作服务器。这是我使用的配置。任何帮助将被appriciated。使用i18n的客户端机器语言环境

 <bean id="localeResolver" 
     class="org.springframework.web.servlet.i18n.SessionLocaleResolver"> 
     <property name="defaultLocale" value="en" /> 
    </bean> 

    <bean id="localeChangeInterceptor" 
     class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"> 
     <property name="paramName" value="language" /> 
    </bean> 


    <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" > 
     <property name="interceptors"> 
      <list> 
       <ref bean="localeChangeInterceptor" /> 
      </list> 
     </property> 
    </bean> 


<!--  Register the welcome.properties --> 
    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> 
     <property name="basenames"> 
        <list> 
         <value>i18n.api/api</value> 
         <value>i18n.exceptions/exceptions</value> 
         <value>i18n.common/common</value> 
         <value>i18n.login/login</value> 
         <value>i18n.plan/plan</value> 
         <value>i18n.customer/customer</value> 
         <value>org.springframework.security.messages</value> 
         <value>org.hibernate.validator.ValidationMessages</value> 
        </list> 
       </property> 
    </bean> 
+0

您的意思是“根据客户端机器的操作系统区域设置让我的应用程序工作”是什么意思?什么行为应该是特定于(任何?)客户端的? – 2013-06-03 06:44:54

回答

0

请参阅supported handler method argument types on Spring doc。您可以像这样在您的处理程序方法中注入用户的语言环境:

@RequestMapping("/home") 
public String home(Locale userLocale) { 
    // do something with userLocale 

    return "home"; 
} 

语言环境的类型为java.util.Locale。

也看看getLocale()方法ServletRequest。客户端必须在其请求中提供Accept-Language头,否则将使用服务器的语言环境。我假设Spring的行为与此相同

相关问题