Internationalization
In order to deliver on the promise “write once, run anywhere,” the engineers at Java designed the famous Java Virtual Machine. True, your program will run anywhere there is a JVM, but what about users in other countries? Will they have to know English to use your application? Java 1.1 answers that question with a resounding “no,” backed up by various classes that are designed to make it easy for you to write a “global” application. In this section, we’ll talk about the concepts of internationalization and the classes that support them.
The java.util.Locale Class
Internationalization programming
revolves around the Locale class. The class itself
is very simple; it encapsulates a country code, a
language code, and a
rarely used variant code. Commonly used languages and countries are
defined as constants in the Locale class.
(It’s ironic that these names are all in English.) You can
retrieve the codes or readable names, as follows:
Locale l = Locale.ITALIAN; System.out.println(l.getCountry( )); // IT System.out.println(l.getDisplayCountry( )); // Italy System.out.println(l.getLanguage( )); // it System.out.println(l.getDisplayLanguage( )); // Italian
The country codes comply with ISO3166. A complete list of country codes is at http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html. The language codes comply with ISO639. A complete list of language codes is at http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt. There is no official set of variant codes; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access