1.在editPlus里进行JAVA国际化还是比较麻烦的,有以下步骤:
(1)新建一系列的.properties文件,就是我们所谓的资源文件,资源文件一般命名方式为:
baseName_Language_Country.properties。而一般在了一个项目中的baseName是任意的,并且各个资源文件的baseName应该相同,以便使用,而Language和Country是有规定的。例如mess_en_US代表的是美国英语,mess_zh_CN代表的是中国汉字
(2)建立的.properties文件并不能直接使用,需要在命令行中使用JAVA命令native2ascii
native2ascii使用格式:native2ascii 源资源文件 目的资源文件(注意:必须在资源文件的根目录下使用该命令)
3.通过native2ascii生成文件aa.properties,bb.properties后必须将文件名改成原来的文件名MyResource_zh_CN.properties,MyResouce_en_US.properties
4.
资源文件MyRsource_en_US:
msg=Hello,{0}!Today is {1}.
MyRsource_zh_CN:(通过native2ascii后)
msg=\u4f60\u597d\uff0c{0}!\u4eca\u5929\u662f{1}
测试文件:
import java.util.ResourceBundle;
import java.text.MessageFormat;
import java.util.Locale;
import java.util.Date;
public class HelloArg
{
public static void main(String[] args)
{
int i=0;
Locale currentLocale=null;
Locale[] localeList=Locale.getAvailableLocales();
if(args.length==2){
currentLocale=new Locale(args[0],args[1]);
}
else{
//获取系统默认的Locale(国家/语言环境)
currentLocale=Locale.getDefault();
}
for(i=0;i
System.out.println(localeList[i].getDisplayCountry()+"="+localeList[i].getCountry()
+" "+localeList[i].getDisplayLanguage()+"="+localeList[i].getLanguage());
}
//根据指定的Locale加载资源文件
ResourceBundle bundle=ResourceBundle.getBundle("MyResource",Locale.US);
String msg=bundle.getString("msg");
//为资源文件中的占位符添加信息
System.out.println(MessageFormat.format(msg,"qianhao",new Date()));
}
}