Struts2 資源配置文件國際化


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>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章