More than 300 locales in Java!
By naotoj on Oct 30, 2006
I am going to give a presentation at the upcoming Internationalization and Unicode Conference held in Washington D.C. next month. The main topic of the presentation is the new i18n features in the upcoming Java 6, and now I am preparing a demo to showcase the potential of the Locale Sensitive Services SPI feature (I know. Kinda long name), which I wrote in the previous entry (wow, it was 8 months ago :-)
The demo consists of two components. One is just a simple Swing application which displays a list of available locales in the platform (precisely, a list returned from Locale.getAvailableLocales()), and displays formatted dates, times, numbers, currencies, or language/country/timezone names in a particular locale which is selected in the locale list.
The other component is invisible, but more interesting one. That is, an adapter which reads the CLDR's locale data in XML format, then it transforms the locale data and plugs them into the Java runtime through the Locale Sensitive Services SPI. Although Java currently do not support three letter language codes defined in ISO 639-2 so some locales may not be plugged in, but still we have more than 300 locales available in the Java text processing classes with this CLDR adapter!
Here is a preview of the demo. This demonstrates the date and time formatting in the Tamil (India) locale, which the Java runtime does not yet support out of the box:
Note that since Java does not support Tamil, it does not contain the suitable font either. However, the OS I used for running this demo was Windows XP, which contains fonts that are capable for displaying Tamil such as "Latha" font. And with the "font fallback" mechanism we introduced in Java 5.0, the demo worked like a charm with the formatted date and time, which are derived from the CLDR data.
Here is another screen shot of the demo, which displays date and time in Amharic (Ethiopia) locale.
For this demo, since Windows XP does not support Amharic, I used an open source TrueType font for Amharic called "Jiret", which is available here.
If you are interested, and planning to be at the next Unicode conference, please come to our presentation. I am sure I can show you more interesting bits!