4

我有一个多语言的 struts 应用程序,最近我将 struts 从 2.3.20 升级到了 2.3.29。升级后,泰米尔语无法使用,即即使我们选择泰米尔语,文本仍以英语显示。

当我们选择泰米尔语时,我检查了语言环境设置,它是正确的,即request_locale=ta_IN

我尝试在我的自定义拦截器类中扩展 I18nInterceptor ,然后覆盖getLocaleFromParam()下面的方法。这也没有奏效。

所以请让我知道你们是否有解决这个问题的方法。

泰米尔语在 Struts 2.3.20 中运行良好

protected Locale getLocaleFromParam(Object requestedLocale) 
{
        Locale locale = null;
        if (requestedLocale != null) {
            locale = (requestedLocale instanceof Locale) ?
                    (Locale) requestedLocale :
                  LocalizedTextUtil.localeFromString   
                                (requestedLocale.toString(), null);
            if (locale != null) {
                logger.debug("applied request locale="+locale);
            }
        }
        return locale;
}
4

1 回答 1

1

您需要更改替换拦截器。

默认堆栈在 struts 中定义如下(https://struts.apache.org/docs/struts-defaultxml.html):

<interceptor-stack name="defaultStack">
     <interceptor-ref name="exception"/>
     <interceptor-ref name="alias"/>
     <interceptor-ref name="servletConfig"/>
     <interceptor-ref name="i18n"/>
     <interceptor-ref name="prepare"/>
     <interceptor-ref name="chain"/>
     <interceptor-ref name="scopedModelDriven"/>
     <interceptor-ref name="modelDriven"/>
     <interceptor-ref name="fileUpload"/>
     <interceptor-ref name="checkbox"/>
     <interceptor-ref name="datetime"/>
     <interceptor-ref name="multiselect"/>
     <interceptor-ref name="staticParams"/>
     <interceptor-ref name="actionMappingParams"/>
     <interceptor-ref name="params"/>
     <interceptor-ref name="conversionError"/>
     <interceptor-ref name="validation">
        <param name="excludeMethods">input,back,cancel,browse</param>
     </interceptor-ref>
     <interceptor-ref name="workflow">
          <param name="excludeMethods">input,back,cancel,browse</param>
     </interceptor-ref>
     <interceptor-ref name="debugging"/>

您需要定义自己的拦截器并将其添加到默认堆栈

    <interceptor name="customi18n"
        class="foo.bar.CustomI18NInterceptor" />

并将其添加到您自己的堆栈中:

//Give a new name to your stack
<interceptor-stack name="customDefaultStack">
      <interceptor-ref name="exception"/>
      <interceptor-ref name="alias"/>
      <interceptor-ref name="servletConfig"/>
      //Replace your customi18n interceptor
      <interceptor-ref name="customi18n"/>
     //Same as above
  .....

将此堆栈设为默认堆栈

<default-interceptor-ref name="customDefaultStack"/>
于 2016-10-04T06:23:50.677 回答