Java Reference
In-Depth Information
Chapter
9.
Internationalizing
and
Localizing
Web
Applications
The process of preparing an application to support more than one language and data format
is called internationalization . Localization is the process of adapting an internationalized
application to support a specific region or locale. Examples of locale-dependent informa-
tion include messages and user interface labels, character sets and encoding, and date and
currency formats. Although all client user interfaces should be internationalized and local-
ized, these processes are particularly important for web applications because of the global
nature of the web.
The following topics are addressed here:
• “ Java Platform Localization Classes ” on page 183
• “ Providing Localized Messages and Labels on page 184
• “ Date and Number Formatting on page 187
• “ Character Sets and Encodings on page 188
Java Platform Localization Classes
In the Java platform, java.util.Locale ( http://docs.oracle.com/
javase/6/docs/api/java/util/Locale.html ) represents a specific geograph-
ical, political, or cultural region. The string representation of a locale consists of the in-
ternational standard two-character abbreviation for language and country and an optional
variant, separated by underscore ( _ ) characters. Examples of locale strings include fr
(French), de_CH (Swiss German), and en_US_POSIX (English on a POSIX-compliant
platform).
Locale-sensitive data is stored in a java.util.ResourceBundle ( ht-
tp://docs.oracle.com/javase/6/docs/api/java/util/Re-
sourceBundle.html ). A resource bundle contains key-value pairs, where the key
uniquely identifies a locale-specific object in the bundle. A resource bundle can be backed
by a text file (properties resource bundle) or a class (list resource bundle) containing the
pairs. You construct a resource bundle instance by appending a locale string representation
to a base name.
The Duke's Tutoring application contains resource bundles with the base name mes-
sages.properties for the locales pt (Portuguese), de (German), es (Spanish), and
Search WWH ::




Custom Search