The JavaTM Web Services Tutorial
Home
TOC
Index
PREV TOP NEXT
Divider

Internationalizing and Localizing Web Applications

Internationalization is the process of preparing an application to support various languages and data formats. Localization is the process of adapting an internationalized application to support a specific language or locale. Although all client user interfaces should be internationalized and localized, it is particularly important for Web applications because of the far-reaching nature of the Web. For a good overview of internationalization and localization, see

http://java.sun.com/docs/books/tutorial/i18n/index.html
 

There are two approaches to internationalizing a Web application:

In the following chapters on Web technology, the Duke's Bookstore example is internationalized and localized into English and Spanish. The key and value pairs are contained in list resource bundles named messages.BookMessage_*.class. To give you an idea of what the key and string pairs in a resource bundle look like, here are a few lines from the file messages.BookMessages.java.

{"TitleCashier", "Cashier"},
{"TitleBookDescription", "Book Description"},
{"Visitor", "You are visitor number "},
{"What", "What We"re Reading"},
{"Talk", " talks about how Web components can transform the way 
you develop applications for the Web. This is a must read for 
any self respecting Web developer!"},
{"Start", "Start Shopping"},
 

To get the correct strings for a given user, a Web component retrieves the locale (set by a browser language preference) from the request, opens the resource bundle for that locale, and then saves the bundle as a session attribute (see Associating Attributes with a Session):

ResourceBundle messages = (ResourceBundle)session.
  getAttribute("messages");
  if (messages == null) {
    Locale locale=request.getLocale();
    messages = ResourceBundle.getBundle("WebMessages",
      locale); 
    session.setAttribute("messages", messages);
  }
 

A Web component retrieves the resource bundle from the session:

ResourceBundle messages =
  (ResourceBundle)session.getAttribute("messages");
 

and looks up the string associated with the key TitleCashier as follows:

messages.getString("TitleCashier");
 

This has been a very brief introduction to internationalizing Web applications. For more information on this subject see the Java BluePrints:

http://java.sun.com/blueprints
 
Divider
Home
TOC
Index
PREV TOP NEXT
Divider

This tutorial contains information on the 1.0 version of the Java Web Services Developer Pack.

All of the material in The Java Web Services Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.