package com.sls.test.i18n;
import java.util.Locale;
import java.util.ResourceBundle;
/**
* 读取国际化资源文件
* @Description:
* @author
* @Date:2013-11-14
*
*/
public class MyLocal {
/**
* @param args
*/
public static void main(String[] args) {
//
Locale myLocal = Locale.getDefault();
ResourceBundle bundle = ResourceBundle.getBundle("mess",myLocal);
System.out.println(bundle.getString("hello"));
Locale usLocal = new Locale("en", "US");
ResourceBundle usBundle = ResourceBundle.getBundle("mess",usLocal);
System.out.println(usBundle.getString("hello"));
}
}
=======================================================
==============================================================================
找国家名及国家代码可以从如下地址查找:
http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm
找语言代码如下地址:
http://www.loc.gov/standards/iso639-2/php/English_list.php
一、
app_en_US.properties文件内容
welcome.msg=hello world!
app_zh_CN.properties
welcome.msg=欢迎您!
二、
注:java.util.ResourceBundle是加载国际化资源文件的类。利用此类的getBundle()方法加载classpath下的指定开头的文件名的国际化资源文件。并且在加载时需要指定加载哪个国家的国际人资源文件。