網路城邦
上一篇 回創作列表 下一篇  字體:小 中 大
在 Struts 2 中使用 ResourceBundle 來達到多國語言效果
2008/10/23 14:27:47瀏覽3472|回應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

( 不分類|不分類 )
回應 推薦文章 列印 加入我的文摘
上一篇 回創作列表 下一篇

引用
引用網址:https://classic-blog.udn.com/article/trackback.jsp?uid=LupinBlog&aid=2322186