Internationalization Topics

Java Locale

A locale represents a geographic, political or cultural region. Locales are frequently defined by a language/country combination. The language is usually represented using a lowercase two-letter designator defined by ISO 639 (e.g. en for English, fr for French, zh for Chinese). The country is typically represented using uppercase two-letter designators defined by ISO 3166 (e.g. US for the United States, FR for France). The representation of the US locale would be en_US. The third argument, the Variant, can be vendor specific (ex. Texas or California as subsets of en_US). Create a Locale object using one of the three constructors in this class:

Locale(String language)
Locale(String language, String country)
Locale(String language, String country, String variant)

Java has a number of functions that facilitate international programming. One such class is the java.util.Locale class. This class maintains a static default locale that can be set and queried. The Locale class does not implement any internationalization behaviors. It serves as a locale identifier for those classes that do. The application should make a runtime determination of user locale. This determination can be made from any of the following techniques:

  • java.util.Locale class method Locale.getDefault() returns the default locale object inherited from the host system.
  • User selected via a mechanism built into the application that allows the user to select the language. Here you would use the Locale.setDefault() method.
  • Explicitly specify a locale based on personalization settings. Here again you would use the Locale.setDefault() method.

Please see the Java Locale example for more information on usage.