Java Reference
In-Depth Information
Chapter
24.
Internationalization
and
Localization
Nobody can be exactly like me. Sometimes even I have trouble do-
ing it.
Tallulah Bankhead
The credo of "Write once, run anywhere " means that your code will run
in many places where languages and customs are different from yours.
With a little care you can write programs that can adapt to these vari-
ations gracefully. Keeping your programs supple in this fashion is called
internationalization. You have several tools for internationalizing your
code. Using internationalization tools to adapt your program to a specif-
ic localesuch as by translating messages into the local languageis called
localization.
The first tool is inherent in the language: Strings are in Unicode, which
can express almost any written language on our planet. Someone must
still translate the strings, and displaying the translated text to users re-
quires fonts for those characters. Still, having Unicode is a big boost for
localizing your code.
The nexus of internationalization and localization is the locale, which
defines a "place." A place can be a language, culture, or countryanything
with an associated set of customs that requires changes in program be-
havior. Each running program has a default locale that is the user's pre-
ferred place. It is up to each program to adapt to a locale's customs as
best it can. The locale concept is represented by the Locale class, which
is part of the java.util package.
Given a locale, several tools can help your program behave in a locally
comprehensible fashion. A common pattern is for a class to define the
methods for performing locale-sensitive operations. A generic "get in-
stance" static method of this class returns an object (possibly of a
subclass) suitable for the default locale. The class will also provide an
overload of each "get instance" method that takes a locale argument
 
Search WWH ::




Custom Search