2011-07-04 42 views
0

我做了一个支柱application.I想支持我的应用程序中的国际化的 japanese.My属性文件名是应用程序,它的工作Application_ja.properties文件,但 它不工作的Application_ja_JP.properties文件。我在tomcat服务器上运行一个应用程序。 请帮助我。国际化支柱

+0

如果你想得到一些答案,请接受一些在前面的问题(除非你觉得你的问题还没有得到答案)。 –

+0

关心如何从资源中读取代码片段?你如何创建Locale对象并将它们传递给它?现在实际上不可能回答你的问题,而不是“你在某个地方出现编码错误”。我怀疑你想读这样的答案... –

回答

0

我已经创建了支持两种语言的应用程序。我的情况你没有粘贴一些代码,我会试着解释我的。

起初,我创建Struts动作类来处理语言环境,也有这个类的方法:

英语
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_lt.properties)

<message-resources parameter="lt/klc/resources/application_lt"/>  
<message-resources parameter="lt/klc/resources/application"/> 

当我想chage language我简单地称呼这个类通过提供我想要调用的方法:

<html:link action="locale.xhtml?method=en">English</html:link> 
    <html:link action="locale.xhtml?method=lt">Lietuviškai</html:link> 

H这有助于。

0
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"));