Struts 2 (version 2.3.28) only accepts registered locales(Struts 2(2.3.28 版)只接受注册的语言环境)
问题描述
在 Struts 2 版本 2.3.28 中,i18n 拦截器只接受注册到 jvm 的语言环境,该列表由 Locale.getAvailableLocales() 返回.
In Struts 2 version 2.3.28, the i18n interceptor only accepts the locales which are registered to jvm, the list which is returned by Locale.getAvailableLocales().
好吧,虽然我可以扩展可用 Java 语言环境的列表,如前所述 如何扩展可用 Java 语言环境的列表,是否有任何捷径可以将此拦截器设置为接受所有字符串作为语言环境(例如 fa_IR )?!
Well, although I can extend the list of available Java Locales, as mentioned How to extend the list of available Java Locales, is it any short way that set this interceptor to accept all strings as locale (for example fa_IR ) ?!
请注意:将默认语言环境设置为 fa_IR ( <constant name="struts.locale" value="fa_IR"/> ) 可以正常工作.
Just a note: Setting the default locale to fa_IR ( <constant name="struts.locale" value="fa_IR" /> ) works fine.
推荐答案
不行,你必须创建自己的拦截器来扩展 i18n 并覆盖这个方法
No, you have to create your own interceptor that extends i18n and override this method
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 && LOG.isDebugEnabled()) {
LOG.debug("applied request locale=#0", locale);
}
}
if (locale == null) {
locale = Locale.getDefault();
}
return locale;
}
这篇关于Struts 2(2.3.28 版)只接受注册的语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Struts 2(2.3.28 版)只接受注册的语言环境
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
