国际化与格式化(2):MessageFormat

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()));
	}

}

在控制面板里将操作系统的语言环境改为美国英文,再次运行程序输出:




你可能感兴趣的:(format,MessageFormat)