Java I18N

- What to be internationalized ?
   Messages
   Labels on GUI
   Online help
   Sounds
   Graphics
   Icons
   Dates
   Times
   Numbers
   Currencies
   Measurements
   Phone Numbers
   Honorifics and personal titles
   Postal address
   Page layouts
 
- Language Code & Country Code
 
http://ftp.ics.uci.edu/pub/ietf/http/related/iso639.txt (Language Code)
 
http://userpage.chemie.fu-berlin.de/diverse/doc/ISO_3166.html (Country Code)
 
- Find out which Locale definitions are supported by the DateFormat class
  Locale list[] = DateFormat.getAvailableLocales();
 
- Example Code
  String languageCode = "en";
  String countryCode = "US";
  Locale currentLocale = new Locale(languageCode, countryCode);
 
  ResourceBundle labels = ResourceBundle.getBundle("LabelsBundle",currentLocale);
  System.out.println(labels.getString("ok"));

 
- The order of ResourceBundle looking up properties file
  If defaule locale is en_US
  Locale currentLocale = new Locale("fr", "CA", "UNIX");
  ResourceBundle introLabels = ResourcBundle.getBundle("ButtonLabel", currentLocale);
  ButtonLable_fr_CA_UNIX
  ButtonLable_fr_CA
  ButtonLable_fr
  ButtonLable_en_US
  ButtonLable_en
  ButtonLable
 
- How to format Numbers and Currencies
  Double amount = new Double(345987.246);
  numberFormatter = NumberFormat.getNumberInstance(currentLocale);
  amountOut = numberFormatter.format(amount);
  ============================================================
  Double currency = new Double(9876543.21);
  currencyFormatter = NumberFormat.getCurrencyInstance(currentLocale);
  currencyOut = currencyFormatter.format(currency);
  ============================================================ 
  percentFormatter = NumberFormat.getPercentInstance(currentLocale);
  percentOut = percentFormatter.format(percent);
 
- How to format Dates and Times
  dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, currentLocale);
  today = new Date();
  dateOut = dateFormatter.format(today);

  timeFormatter = DateFormat.getTimeInstance(DateFormat.DEFAULT, currentLocale);
  dateTimeFormatter = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, currentLocale);
 
 
  SimpleDateFormat formatter = new SimpleDateFormat(pattern, currentLocale);
  Date today = new Date();
  String output = formatter.format(today);
 
- How to format Messages
  MessageFormat formatter = new MessageFormat("");
  formatter.setLocale(currentLocale);
  formatter.applyPattern("template = At {2,time,short} on {2,date,long}, we detected {1,number,integer} spaceships on the planet {0}.");
  String output = formatter.format(messageArguments);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值