mess_en_US.properties :
msg=Hello {0}! now the time is {1}.mess_zh_CN.properties :
msg=\u4f60\u597d{0}!\u73b0\u5728\u65f6\u95f4\u662f{1}.MessageFormatDemo.java :
public class MessageFormatDemo {
public static void main(String[] args) {
Locale locale=Locale.getDefault();
ResourceBundle bundle=ResourceBundle.getBundle("mess",locale);
String str=bundle.getString("msg");
System.out.println(MessageFormat.format(str,"Tom",new Date()));
System.out.println(MessageFormat.format(str,"Sun",new Date()));
}
}
在控制面板里将操作系统的语言环境改为美国英文,再次运行程序输出:
本文介绍了一个使用Java进行国际化处理的例子,展示了如何通过ResourceBundle加载不同语言环境下的资源文件,并利用MessageFormat实现动态参数的格式化输出。
530

被折叠的 条评论
为什么被折叠?



