Internationalization struts中的国际化

Internationalization struts中的国际化,internationalization,Internationalization,我制作了一个struts应用程序。我想在我的应用程序中为 我的属性文件名是Application,它适用于Application_ja.properties文件,但 它不适用于applicationja_JP.properties文件。我正在tomcat服务器上运行一个应用程序。 请帮助我。我创建了支持两种语言的应用程序。如果您没有粘贴一些代码,我将尝试解释我的代码 首先,我创建Struts action类来处理区域设置,该类有以下方法: public ActionForward en(Acti

我制作了一个struts应用程序。我想在我的应用程序中为 我的属性文件名是Application,它适用于Application_ja.properties文件,但 它不适用于applicationja_JP.properties文件。我正在tomcat服务器上运行一个应用程序。
请帮助我。

我创建了支持两种语言的应用程序。如果您没有粘贴一些代码,我将尝试解释我的代码

首先,我创建Struts action类来处理区域设置,该类有以下方法:

public ActionForward en(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {      
    request.getSession().setAttribute(
            Globals.LOCALE_KEY, Locale.ENGLISH);
    return mapping.findForward(SUCCESS);
}

public ActionForward lt(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    request.getSession().setAttribute(
            Globals.LOCALE_KEY, new Locale("lt"));

    return mapping.findForward(SUCCESS);
}
一种是英语,一种是立陶宛语

我在struts-config.xml文件中声明了此操作类:

<action input="/views/index.jsp" 
        parameter="method" 
        path="/locale" 
        scope="request" 
        type="lt.klc.action.LanguageSelectAction" 
        validate="false">
    <forward name="success" path="/views/index.jsp"/>
</action>

我声明了我的资源:(application.properties和application\u lt.properties)


当我想要更改语言时,我通过提供我想要调用的方法来简单地调用这个类:

    <html:link action="locale.xhtml?method=en">English</html:link>
    <html:link action="locale.xhtml?method=lt">Lietuviškai</html:link>
英语
利图维斯凯

希望这对您有所帮助。

如果您想得到一些答案,请接受前面问题的一些答案(除非您觉得您的问题尚未得到回答)。是否要粘贴一些关于您如何阅读参考资料的代码片段?以及如何创建和传递区域设置对象?现在,除了“你在某处有一个编码错误”之外,实际上不可能回答你的问题。我怀疑你是否愿意阅读这样的答案。。。
Suppose you have two properties files-
struts_en_UK.properties
common.color = colour

struts_en_US.properties
common.color = color

The following code will fetch the resource from properties file as follows-
        Locale locale = new Locale("en", "UK");
        ResourceBundle bundle = ResourceBundle.getBundle("struts",locale);

        System.out.println(bundle.getString("common.color"));

        Locale usLocale = new Locale("en", "US");
        ResourceBundle usBundle = ResourceBundle.getBundle("struts",usLocale);
        System.out.println("Us Locale : "+usBundle.getString("common.color"));
Suppose you have two properties files-
struts_en_UK.properties
common.color = colour

struts_en_US.properties
common.color = color

The following code will fetch the resource from properties file as follows-
        Locale locale = new Locale("en", "UK");
        ResourceBundle bundle = ResourceBundle.getBundle("struts",locale);

        System.out.println(bundle.getString("common.color"));

        Locale usLocale = new Locale("en", "US");
        ResourceBundle usBundle = ResourceBundle.getBundle("struts",usLocale);
        System.out.println("Us Locale : "+usBundle.getString("common.color"));