| This Chapter | |
| - | Chapter 7: Internationalization |
| - | New Supported Locales |
| - | Locale Sensitive Services SPI |
| - | Resource Bundle Enhancement |
| - | ResourceBundle.Control |
| - | Summary |
Java 6 ships with ten new locales. They are listed in Table 7.1.
As an example, consider the code in Listing 7.1 that uses the new locale Japanese calendar.
| Language | Country | Locale Identifier |
|---|---|---|
| Chinese (Simplified) | Singapore | zh_SG |
| English | Malta | en_MT |
| English | Philippines | en_PH |
| English | Singapore | en_SG |
| Greek | Cyprus | el_CY |
| Indonesian | Indonesia | in_ID |
| Japanese (Japanese calendar) | Japan | ja_JP_JP |
| Malay | Malaysia | ms_MY |
| Maltese | Malta | mt_MT |
| Spanish | US | es_US |
Table 7.1: New locales in Java 6
Listing 7.1: Japanese calendar testing
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Locale;
import javax.swing.JOptionPane;
public class JapaneseCalendar {
public static void main(String[] args) {
// Create Japanese locale
Locale japanese = new Locale("ja", "JP", "JP");
Calendar cal = Calendar.getInstance(japanese);
System.out.println(cal);
// Format time
DateFormat df = DateFormat.getDateTimeInstance(
DateFormat.FULL, DateFormat.FULL, japanese);
String str = df.format(cal.getTime());
// Display the string in JOptionPane
JOptionPane.showMessageDialog(null, str);
}
}
If you run the JapaneseCalendar class in Listing 7.1, you’ll see a JOptionPane similar to that in Figure 7.1. The JOptionPane contains a date and time in the new Japanese locale.
Figure 7.1: Using the new Japanese locale