在 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 版)只接受注册的语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!