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 版)只接受注册的语言环境
基础教程推荐
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
- JPA惰性列表上的流 2022-01-01
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- 在springboot中如何给mybatis加拦截器 2023-04-29
- 将 Windows 证书导入 Java 2022-01-01
- 将 double 转换为 Int,向下舍入 2022-01-01
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- Maven:无效的目标版本:10 2022-01-01
