在 Struts 2 中使用 ResourceBundle 來達到多國語言效果
2008/10/23 14:27
瀏覽3,389
迴響0
推薦0
引用0
Step 1. 在 struts.xml 中加入以閜程式碼,
<struts> .... <constant name="struts.custom.i18n.resources" value="resources.application"/> |
其中 resources.application 表示相關的語言檔放置在路徑 <src>/resources/ , 語言檔的檔名為 application_<language>_<country>.properties
Step 2. 在路徑 <src>/resources/ 中建立語言檔, 例如:
繁體中文 應設為 application_zh_TW.properties
英文 應設為 application_en.properties
login.title = 歡迎光臨 |
Step 3. 如果在 JSP, 可使用 Struts Tag lib 來協助完成
<%@ taglib prefix="s" uri="/struts-tags" %> .... <html> .... <body> .... <s:text name="login.title"/> |
Step 4. 如果在 java 中
ResourceBundle reesource = ResourceBundle.getBundle("resources.application"); String message = reesource.getString("logon.title"); |
其中 resources.application 表示對應到 <src>/resources/application_xxx.properites
自訂分類:Framework - Struts2
你可能會有興趣的文章: