Internationalization in struts
I made one struts application.I want to support a Internationalization in my application for japanese.My Property file name is Application,Its working for Application_ja开发者_如何转开发.properties file but Its not working for Application_ja_JP.properties file.I am running a application on tomcat server. please help me.
I have created application to support two languages. I case you did not paste some code I will try to explain mine.
At first I create Struts action class to handle locales, there are methods of this class:
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);
}
One method for English and one method for Lithuanian language.
I declared this action class in my struts-config.xml file:
<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>
I declared my resources: (application.properties and application_lt.properties)
<message-resources parameter="lt/klc/resources/application_lt"/>
<message-resources parameter="lt/klc/resources/application"/>
When I want to chage language I simple call this class by providing which method I want to call:
<html:link action="locale.xhtml?method=en">English</html:link>
<html:link action="locale.xhtml?method=lt">Lietuviškai</html:link>
Hope this helps.
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"));
精彩评论