有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

JavaStruts2(版本2.3.28)只接受注册的区域设置

在Struts 2版本2.3.28中,i18n拦截器只接受注册到jvm的区域设置,即Locale.getAvailableLocales()返回的列表

好的,尽管我可以扩展可用Java语言环境的列表,正如前面提到的How to extend the list of available Java Locales,但是设置这个拦截器接受所有字符串作为语言环境(例如fa_IR)有什么捷径吗

请注意:将默认区域设置设置为fa_IR<constant name="struts.locale" value="fa_IR" />)效果很好


共 (1) 个答案

  1. # 1 楼答案

    不,您必须创建自己的拦截器来扩展i18n并重写此方法

     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;
        }