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