Introduction


The audience for almost all web sites is global. Many sites have at least a subset of content that must be adapted to the language and nationality of their visitors , so that the visitor's browser formats numbers and dates properly and translates text into the proper language. An obvious example is a product documentation or help web site. What if most of your customers or viewers for this product speak a language other than English? Java provides tools that allow web developers to internationalize their sites.

Before I show these tools, let's first explain a few terms that always appear in discussions of web site translation.

  1. Internationalization, or i18n in its abbreviated version, means enabling a web site or other Java program to provide different versions of content translated into the visitor's language or nationality. This term basically means making your site global.

  2. Localization, or l10n , means adding resources to a web site to adapt it to a particular geographical or cultural region. An example of l10n is adding Korean language translations to a web site. The web developers who have this responsibility are often referred to as localizers .

  3. A locale is a particular cultural or geographical region. It is usually referred to as a language symbol followed by a country symbol (separated by an underscore character), as in "en_US" for the English locale, "de_DE" for German speakers in Germany, or "de_CH" for Swiss-German speakers , or "fr_CH" for people in Switzerland who speak French. A locale can also represent just the language, as in "ja" for Japanese or "it" for Italian. Finally, locales can have a third segment or "variant" that reflects a certain browser-type or vendor, such as "MAC" for Macintosh. An example of a locale for English with a Windows variant is "en_US_ WIN."

The language element is represented by an International Standards Organization (ISO) language code (http://www.ics.uci.edu/pub/ietf/http/ related /iso639.txt); the country is encoded under ISO-3166 (http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html).


So how do you internationalize or localize a Java web site? This is a big subject and the topic of several books. The following recipes provide the basics of how to create properties files (called ResourceBundles ). These files (they can also be implemented as Java classes) provide language translations for phrases that your web pages use. A servlet can then access these resources and provide different text versions according to the requester's locale.

The recipes in this chapter also cover how to adapt JSP pages to visitors who speak different languages by using the JSTL tags. I begin by describing how to detect the locale of a request using a servlet or JSP.



Java Servlet & JSP Cookbook
Java Servlet & JSP Cookbook
ISBN: 0596005725
EAN: 2147483647
Year: 2004
Pages: 326

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net