Struts2 資源配置檔案國際化
Struts2資源檔案的命名規範:basename_language_country.properties
Struts2國際化
如果系統同時存在資源檔案、類檔案,系統将以類檔案為主,而不會調用資源檔案。
對于簡體中文的Locale,ResourceBundle搜尋資源的順序是:
(1)baseName_zh_CN.class
(2)baseName_zh_CN.properties
(3)baseName_zh.class
(4)baseName_zh.properties
(5)baseName.class
(6)baseName.properties
Struts2資源檔案加載方式有3種,
1.全局資源配置檔案
2.包資源配置檔案
3.Action資源配置檔案
查找順序:Action資源配置檔案>包資源配置檔案>全局資源配置檔案
1.全局資源檔案加載方式:
struts.xml
<constant name="struts.custom.i18n.resources" value="baseName"/>
或
struts.properties
struts.custom.i18n.resources=baseName
2.包資源檔案加載方式:
檔案命名規範:package_language_country.properties
将包資源檔案放到 Action所在的包目錄中
3.Action資源配置檔案加載方式:
檔案命名規範:Action_language_country.properties
将Action資源配置檔案 放到Action所在的包目錄中
struts2标簽使用資源配置檔案
key:資源檔案中的key path:資源檔案所在的路徑
<s:i18n name="path">
<s:text name="key">
<s:param>參數</s:param>
</s:text>
</s:i18n>