2011-07-04 41 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"));