标签:des style blog http java 使用
>ResourceBundle类提供了一个静态方法getBundle,该方法用于装载资源文件,并创建ResourceBundle实例:
Locale currentLocale = Locale.getDefault();
ResourceBundle myResources = ResourceBundle.getBundle(basename, currentLocale);
basename为资源包基名(且必须为完整路径)。
如果与该locale对象匹配的资源包子类找不到。一般情况下,则选用默认资源文件予以显示
加载资源文件后, 程序就可以调用ResourceBundle 实例对象的 getString 方法获取指定的资源信息名称所对应的值:String value = myResources.getString(“key");
在WEB应用中实现固定文本的国际化
以上字符串中包含了时间、数字、货币等多个与国际化相关的数据,对于这种字符串,可以使用MessageFormat类对其国际化相关的数据进行批量处理
At 12:30 pm on jul 3,1998, a hurricance destroyed 99 houses and caused $1000000 of damage
模式字符串:
格式化模式字符串
MessageFormat类
String pattern = “On {0}, a hurricance destroyed {1} houses and caused " + “{2} of damage.“;
MessageFormat msgFmt = new MessageFormat(pattern,Locale.US);
//准备参数数组
String datetime = “Jul 3, 1998 12:30 PM”;
Date date = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.US).parse(datetime);
Object [] msgArgs = {date, new Integer(99),new Double(1E7)};
//执行格式化操作
String result = msgFmt.format(msgArgs);
System.out.println(result);
占位符有三种方式书写方式:
String pattern = “At {0, time, short} on {0, date}, a destroyed‘\n‘“+ “{1} houses and caused {2, number, currency} of damage.“;
MessageFormat msgFmt = new MessageFormat(pattern,Locale.US);
String datetimeString = “Jul 3, 1998 12:30 PM”;
Date date = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
DateFormat.SHORT,Locale.US).parse(datetimeString);
String event = “a hurricance”;
Object []msgArgs = {date, event, new Integer(99), new Double(1E7)};
String result = msgFmt.format(msgArgs);
System.out.println(result);
http://blog.163.com/meihua_can/blog/static/18543529220114221315952/
(JavaEE-13)国际化开发.md,布布扣,bubuko.com
标签:des style blog http java 使用
原文地址:http://my.oschina.net/raining0822/blog/292660