Struts 2(版本2.3.28)仅接受已注册的区域设置 [英] Struts 2 (version 2.3.28) only accepts registered locales
问题描述
在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.localevalue =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)仅接受已注册的区域设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!