myres_zh_CN.properties
bbb=thanks
myres_en_US.properties
bbb=thanks
myres_zh_CN.properties
bbb=\u591a\u8c22
import java.util.ResourceBundle;
/**
* 國際化資源綁定測試
*
* @author leizhimin 2009-7-29 21:17:42
*/
public class TestResourceBundle {
public staticvoid main(String[] args) {
Locale locale1 = new Locale("zh","CN");
ResourceBundle resb1 = ResourceBundle.getBundle("myres", locale1);
System.out.println(resb1.getString("aaa"));
ResourceBundle resb2 = ResourceBundle.getBundle("myres", Locale.getDefault());
System.out.println(resb1.getString("aaa"));
Locale locale3 = new Locale("en","US");
ResourceBundle resb3 = ResourceBundle.getBundle("myres", locale3);
System.out.println(resb3.getString("aaa"));
}
}
好
good
Process finished with exit code 0
Locale 對象表示了特定的地理、政治和文化地區。需要 Locale 來執行其任務的操作稱爲語言環境敏感的 操作,它使用 Locale 爲用戶量身定製信息。例如,顯示一個數值就是語言環境敏感的操作,應該根據用戶的國家、地區或文化的風俗/傳統來格式化該數值。
Locale(String language, String country)
Locale(String language, String country, String variant)
http://www.loc.gov/standards/iso639-2/englangn.html。
國家參數是一個有效的 ISO 國家代碼。這些代碼是由 ISO-3166 定義的大寫兩字母代碼。在許多網站上都可以找到這些代碼的完整列表,如:
http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html。
在myeclipse裏面,src中的中文資源文件中,經myeclipse自動編譯後,在WEB-INF/class下面的資源文件都變爲unicode編碼了,形如:\u7528\u6237\u4e2d\u5fc3。