Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.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 MVC中使用cookie进行ICU定位_Java_Spring_Spring Mvc_Localization_Icu - Fatal编程技术网

Java 在Spring MVC中使用cookie进行ICU定位

Java 在Spring MVC中使用cookie进行ICU定位,java,spring,spring-mvc,localization,icu,Java,Spring,Spring Mvc,Localization,Icu,我需要使用ICU(Unicode的国际组件),因为我的应用程序应该支持JDK中不支持的区域设置,如“fa_IR” 我找到了一个使用Spring和Cookie提供此功能的配置 <beans:bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver"> <beans:property name="defaultLocale

我需要使用ICU(Unicode的国际组件),因为我的应用程序应该支持JDK中不支持的区域设置,如“fa_IR”

我找到了一个使用Spring和Cookie提供此功能的配置

    <beans:bean id="localeResolver"
            class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
    <beans:property name="defaultLocale" value="en" />
    <beans:property name="cookieName" value="myAppLocaleCookie"/>
    <beans:property name="cookieMaxAge" value="3600"/>
</beans:bean>

<interceptors>
    <beans:bean
            class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
        <beans:property name="paramName" value="locale" />
    </beans:bean>
</interceptors>

有没有办法在ICU中使用类似的配置


如果此配置不可能,是否有其他方式(如更改控制器等)?

op问题中的示例是
CookieLocalerResolver
的配置,允许您从cookie解析请求的区域设置(默认情况下从
Accept Language
头解析)和
LocaleChangeInterceptor
,允许您通过请求更改语言环境

ICU与此无关。ICU是一个允许您格式化和翻译消息的库。它不关心语言环境的变化,这是春天的事

我假设您希望使用ICU进行区域设置感知的消息格式化,以替代Java的
Java.text.MessageFormat

Spring在其
MessageSourceSupport
类中使用
MessageFormat
,该类由
AbstractMessageSource
扩展,后者也由
ResourceBundleMessageSource
扩展

SpringTemplateEngine engine = new SpringTemplateEngine();
// ...
engine.setTemplateEngineMessageSource(myCustomMessageSource);
return engine;
要将ICU的
com.ibm.ICU.text.MessageFormat
类合并到应用程序中,您必须实现自己的
MessageSrouce
类,该类提供MessageFormat。然后配置模板引擎以使用它。下面的代码片段显示了带有自定义
MessageSource
的ThymileAF配置

SpringTemplateEngine engine = new SpringTemplateEngine();
// ...
engine.setTemplateEngineMessageSource(myCustomMessageSource);
return engine;
至少我还没有找到更好的解决办法

也许您会对我的文章感兴趣

实现了一个与ICU兼容的消息源,可以在您的示例中使用它