如何在动作控制器中默认扩展不可用的Locale.Language?

时间:2018-11-26 08:47:24

标签: java locale struts struts-1

因此,我尝试使用默认不支持的某些语言(瑞典语,葡萄牙语,西班牙语等)来实现Struts 1 I18N应用程序,但是例如,当我在动作控制器中定义Locale.Portuguese时,它将显示我PORTUGUESE cannot be resolved or is not a field。为什么?我该如何扩展它以便继续进行?有人可以解释它的相关性吗?

public ActionForward french(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        HttpSession session = request.getSession();
        session.setAttribute("org.apache.struts.action.LOCALE", Locale.FRENCH);
        return mapping.findForward(SUCCESS);
    }

1 个答案:

答案 0 :(得分:0)

如果您没有在java.util.Locale中找到您所在国家/地区的语言和语言作为静态常量,则可以自己创建它们,

Locale portugese = new Locale("pt","PT");
Locale swedish = new Locale("sv","SE");
Locale spanish = new Locale("es","ES");

根据说不同语言的国家/地区而有所不同,但以上情况应该很好。

This locale information may be helpful for you