Java多版本国际化_Java -- 国际化 多语化
1. 以中英两种语言做示例,显示 "hello"
2. 建立英文语言文件 “mess_en_US.properties ”, 输入内容 “hello=welcome you !”, 文件名格式为Java支持的 XX_国家_语言.properties
3. 建立中文语言文件 “mess_zh_CN.properties”,输入内容 “hello=你好”
4. 使用工具 native2ascii 转为Unicode存储, 该工具在 JAVA_HOME目录 bin下
native2ascii mess_zh_CN.properties mess1_zh_CN.properties
native2ascii mess_en_US.properties mess1_en_US.properties
6. 代码示例:
public class Main {
public static void main(String[] args) throws IOException {
Locale [] localeList = Locale.getAvailableLocales();
for( int i=0; i!=localeList.length; i++ )
{ //输出支持的国家和语言
System.out.println( localeList[i].getDisplayCountry() + "=" + localeList[i].getCountry()
+ " " + localeList[i].getDisplayLanguage() + "=" + localeList[i].getLanguage() );
}
Locale mylocale = Locale.getDefault();
ResourceBundle bundle = ResourceBundle.getBundle("mess1", mylocale); //根据系统信息 获取语言包
System.out.println(bundle.getString("hello")); //根据系统 输出对应的值, key -- value
}
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
