#JavaWeb-国际化java
##国际化开发概述编程
##合格的国际化软件数组
##固定文本元素的国际化安全
###建立资源包和资源文件编码
###资源文件的书写格式线程
###编程实现固定文本的国际化code
ResourceBundle类提供了一个静态方法getBundle,该方法用于装载资源文件,并建立ResourceBundle实例:orm
Locale currentLocale = Locale.getDefault(); ResourceBundle myResources = ResourceBundle.getBundle(basename, currentLocale);对象
basename为资源包基名(且必须为完整路径)。blog
若是与该locale对象匹配的资源包子类找不到。通常状况下,则选用默认资源文件予以显示
加载资源文件后, 程序就能够调用ResourceBundle 实例对象的 getString 方法获取指定的资源信息名称所对应的值:String value = myResources.getString(“key");
在WEB应用中实现固定文本的国际化
##动态数据的国际化
###DateFormat类(国际化日期)
###NumberFormat类
###练习
###MessageFormat(动态文本)
以上字符串中包含了时间、数字、货币等多个与国际化相关的数据,对于这种字符串,可使用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/