Internationalize your software, Part 3

Learn how to develop software for the global marketplace

1 2 3 4 5 Page 5
Page 5 of 5

The displayed result is the same as the previous result except that the F is replaced by the euro currency symbol. In Figure 3, I showed an example of a euro number with the euro currency symbol to the left of the number. However, Java's currency formatter places the euro currency symbol to the right of the number. Which is correct? I'm not sure, but I'll stick with Java. Let Java's currency formatter "worry" about which side of a number to place the euro currency symbol.

JDK 1.1.7 introduced the concept of the EURO variant. Unfortunately, its currency formatter for the EURO variant does not use the euro currency symbol. Instead, it falls back to using existing currency formats. This problem has been corrected in JDK 1.1.7B. (I'm not sure about JDK 1.1.7A.)

The following results were generated from an application that formats French and German currency values according to the France and Germany euro locale conventions. (This application must be run under JDK 1.1.7B or higher). The source code to this application is located in example18.java. (NOTE: There is one additional caveat that I will shortly discuss.)

Unformatted: 1234567.89

Formatted for en_US: ,234,567.89 Formatted for fr_FR: 1�?234�?567,89 F Formatted for de_DE: 1.234.567,89 DM Formatted for ja_JP: €1,234,567.89 Formatted for fr_FR_EURO: 1�?234�?567,89 Ä Formatted for de_DE_EURO: 1.234.567,89 Ä

If you can't see the euro currency symbol, then you probably have guessed that the previously mentioned caveat is about this symbol. Windows 95, Windows NT, and versions of Solaris prior to version 7 cannot display the euro currency symbol without an update to their fonts. Information on obtaining the update is distributed with the README file that accompanies JDK 1.1.7B. I suggest that you obtain a copy of this update.

The other major new feature that I've come across in JDK 1.1.7 is an update to Java's Character class. This update makes it possible for Java to transition from the Unicode 2.0.14 standard (used by JDK versions prior to 1.1.7) to the Unicode 2.1.2 standard. The following table lists these changes. Basically, some of Character's methods have been modified so that certain Unicode argument values are remapped according to Unicode 2.1.2.

java.lang.Character MethodMethod argumentReturn Value Under JDK versions 1.1.7Return Value Under JDK version 1.1.7
toLowerCase (char) '\u018E' '\u0258' '\u01DD'
toLowerCase (char) '\u019F' '\u019F' '\u0275'
toUpperCase (char) '\u01DD' '\u01DD' '\u018E'
toTitleCase (char) '\u01DD' '\u01DD' '\u018E'
toUpperCase (char) '\u0258' '\u018E' '\u0258'
toTitleCase (char) '\u0258' '\u018E' '\u0258'
toLowerCase (char) '\u0275' '\u0275' '\u019F'
toUpperCase (char) '\u03C2' '\u03C2' '\u03A3'
toTitleCase (char) '\u03C2' '\u03C2' '\u03A3'
toUpperCase (char) '\u1E9B' '\u1E9B' '\u1E60'
toTitleCase (char) '\u1E9B' '\u1E9B' '\u1E60'
getType (char) '\u20AC' 0 - unassigned26 - currency symbol
isDefined (char) '\u20AC' false true
isJavaIdentifierPart (char) '\u20AC' false true
isJavaIdentifierStart (char) '\u20AC' false true
getType (char) '\u301F' 21 - start of punctuation22 - end of punctuation
getType (char) '\uFFFC' 0 - unassigned28 - other symbol
isDefined (char) '\uFFFC' false true

What's new in Java 2?

After spending some time with JDK 1.2 Beta 4 (and beyond), I've uncovered the following new internationalization features.

  • Complex character input (such as Japanese, Chinese and Korean) is supported through the Input Method Framework.

  • Complex character output (such as Japanese, Arabic and Hebrew) is supported through Java's 2D API.

  • The concept of Unicode character blocks (subsections of Unicode's character set) has been introduced to simplify the classification of characters.

  • The Character class has a new compareTo (Character) method that compares the current Character object with a Character object argument (for ordering).

  • The Character class has a new compareTo (Object) method that compares the current Character object with an Object object argument (for ordering). This argument must be castable to another Character object, otherwise a ClassCastException object is thrown. If the argument is another Object object, then this method behaves like the compareTo (Character) method.

  • The Character class has a new getUnicodeBlock (char) method, which returns a constant that identifies the character block to which the character located in the char argument belongs.

  • The Collator class has a new compare (Object, Object) method that compares two Object object arguments (for ordering). These two arguments must be castable to two String objects. Otherwise, a ClassCastException object is thrown.

  • The CollationKey class has a new compareTo (Object) method that compares the current CollationKey object with the Object object argument (for ordering).

  • The Comparator interface is new to Java 2.

  • The Comparable interface is new to Java 2. The String class uses this interface as the basis of its public CASE_INSENSITIVE_ORDER constant.

  • The Date class has a new compareTo (Date) method that compares the current Date object with the Date object argument (for ordering).

  • The Date class has a new compareTo (Object) method that compares the current Date object with an Object object argument (for ordering). This argument must be castable to another Date object, otherwise a ClassCastException object is thrown. If the argument is another Date object, then this method behaves like the compareTo (Date) method.

  • The String class has a new compareTo (Object) method that compares the current String object with an Object object argument (for ordering). This argument must be castable to another String object, otherwise a ClassCastException object is thrown. If the argument is another String object, then this method behaves like the compareTo (String) method.

  • The String class has a new compareToIgnoreCase (String) method that compares the current String object with a String object argument and ignores case (for ordering).

Conclusion

We've certainly been busy. After exploring Java's Date, TimeZone, and Calendar classes, we explored the formatter classes for dates, messages, and numbers. Along the way, we discovered that parsing user-input is handled by these same formatter classes. We briefly looked at international fonts and working with non-Unicode text. Finally, we ventured beyond JDK 1.1.6 and explored some internationalization features that are new to JDK 1.1.7 and Java 2.

We've come to the end of this series. I hope you've learned a few things and had some fun. If you'd like to learn more about internationalizing your software, check out the Web sites in the Resources section. These sites contain a wealth of useful material. In trying to keep this series to a manageable size, I did not go into a great deal of depth on some aspects of internationalization, such as calendars. Hopefully, some of you will expand on this work and present your results in future JavaWorld articles. Interested?

Jeff is a consultant working with various technologies including C++, digital signatures/encryption, Java, smart cards and Win32. He has worked for a number of technology-related consulting firms including EDS (Electronic Data Systems).

Learn more about this topic

  • More information on calendars is available in The Calendar FAQ http://www.pip.dknet.dk/~pip10160/calendar.html
  • An interesting overview article on internationalization is available at http://developer.java.sun.com/developer/technicalArticles/intl.html
  • The official Unicode Web site contains a wealth of information on this character definition standard http://www.unicode.org
  • IBM has a "cookbook" on creating global applications http://www.ibm.com/java/education/globalapps/index.html
  • Sun offers a tutorial on Java, The Java Tutorial, that contains a really good section on internationalization http://java.sun.com/docs/books/tutorial/index.html
  • A complete list of ISO-639 language codes is available at http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt
  • A complete list of ISO-3166 country codes is available at http://www.ics.uci.edu/pub/ietf/http/related/iso3166.txt
  • An interesting article on localization with resource bundles is available at http://developer.java.sun.com/developer/technicalArticles/ResourceBundles.html
  • You can translate text from one language to another from this site http://babelfish.altavista.com/cgi-bin/translate?
  • Note: Two of the Resources links take you to Sun's Java Developer Connection site. You need to be a member of the Java Developer Connection in order to view articles, and you will be prompted to enter a user ID and password the first time you access this site. There is no charge to become a member. You can register when prompted to enter a user ID/password.

Related:
1 2 3 4 5 Page 5
Page 5 of 5