Red Hat Web Application Framework 6.1: WAF Developer Guide | ||
---|---|---|
Prev | Chapter 4. WAF Component: Services | Next |
A globalized application is one that tries to equally accommodate readers of different languages and dialects. Elements of the application's user interface are shown in the user's preferred language, if it is supported. For example, a link to the categories page is displayed as Categories for English speakers and Kategorien for German speakers.
A partial list of globalization and localization facilities supported by the Java language includes:
The notion of locale (http://java.sun.com/j2se/1.3/docs/api/java/util/Locale.html).
Resource bundles (http://java.sun.com/j2se/1.3/docs/api/java/util/ResourceBundle.html) allow you to organize and maintain locale-specific objects, such as strings to be shown as button labels, e.g. Categories and Kategorien.
Locale-specific date format (http://java.sun.com/j2se/1.3/docs/api/java/text/DateFormat.html\ #getDateInstance(int,java.util.Locale) — "\" has been inserted to show where the line was broken for printing purposes; you will need to put both halves together again in e.g. your Web browser URL window).
Locale-specific collation (http://java.sun.com/j2se/1.3/docs/api/java/text/Collator.html) of sequences of strings.
Miscellaneous other facilities.
The WAF globalization service provides classes and methods that can be roughly divided into the following three categories.
Convenient wrappers around most-frequently used Java globalization APIs, such as resource bundles.
Means of configuring the list of supported languages, locales, and character sets.
A mechanism for locale and character set negotiation.
Most modern browsers allow users to select their preferred language or a ranked sequence of preferred languages. The globalization service looks at the user's preferred language and locale, as reported by the user's browser, and compares them to the list of languages and locales that the system is configured to support.
For example, a user can configure the preferred first language to be German ("de") and the preferred second language to be British English ("en_GB"). If the system is configured to support both of the languages, then the globalization service will choose "de" as the preferred locale. If the system has been configured to support British English, but not German, then the globalization service will choose "en_GB" as the preferred locale. If the system does not support either of the configured languages, then the service falls back to a default locale which could be "en_US" (US English).
Once the desired locale is configured, a supported character set must be selected. For example, pages in German can be displayed using the ISO-8859-1 [1], UTF-8, or UTF-16 character sets. The user may express a preference by configuring their browser. The user's preference must then be reconciled with the list of character sets that the system has been configured to support.
This example of locale and character set negotiation is simplified for this discussion, but it illustrates the fact that correct negotiation is non-trivial. The globalization service relieves the developer of the burden of negotiating the preferred locale and character set correctly.
The WAF globalization service provides a set of high-level APIs based on the standard Java globalization facilities that handle issues such as language negotiation and localization of static strings. These APIs complement the basic globalization infrastructure provided by Java (i.e., ResourceBundles and property files are still used in WAF) and are specifically designed for use by web applications built with WAF.
[1] |