Contents |
An internationalized program displays information differently throughout the world. For example, the program will display different messages in Paris, Tokyo, and New York. If the localization process has been fine-tuned, the program will display different messages in New York and London, to account for the differences in American and British English. How does an internationalized program identify the appropriate language and region of its end-users? Easy. It references aLocale
object.A
Locale
object is an identifier for a particular combination of language, region, and culture. If a class varies its behavior according toLocale
, it is said to be locale-sensitive. For example, theNumberFormat
class is locale-sensitive, because the format of the number it returns depends on theLocale
.NumberFormat
may return a number as 902 300 (France), or 902.300 (Germany), or 902,300 (U.S.).Locale
objects are only identifiers. The real work, such as formatting and detecting word boundaries, is performed by the methods of the locale-sensitive classes.In this lesson, you'll learn how to work with
Locale
objects, and how to perform the following tasks:
Creating a Locale
When creating aLocale
object, you must specify a language and code and a country code. A third parameter, the variant, is optional.Identifying Available Locales
Locale-sensitive classes only support certainLocale
definitions. This section shows you how to determine which Locale definitions are supported.The Default Locale
If you don't explicitly assign aLocale
to a locale-sensitive object, the defaultLocale
will be used. Fortunately, you can set the defaultLocale
.The Scope of a Locale
On the Java platform, you do not specify a globalLocale
by setting an environment variable before running the application. Instead, you assign aLocale
to each locale-sensitive object.
Contents |