J2EE BluePrints > Java Pet Store > Internationalizing/localizing the application

Internationalizing/localizing the application

This release of the Java Pet Store can be localized in Japanese. While the Japanese localization is not complete, the application is internationalized, and lacks only some content translation. The architecture fully supports content localization.

Installing Japanese database tables

The Japanese database tables needed to operate the Japanese version of the Java Pet Store are installed whenever you first visit any version of the Java Pet Store (default, annotated, Japanese). Consult the installation section for more information.


Note: The Japanese tables work with only the Cloudscape databases. They do not work with the Oracle or Sybase datatabases.

Localizing the application

If you want to localize the Java Pet Store, then you need to provide JavaServer Pages components (JSP pages) and a set of screen definitions for the locale you plan to support.


Note: These instructions use $JPS_HOME (UNIX) and %JPS_HOME% (Win32) to denote the root directory of the J2EE BluePrints bundle.
  1. Create localized JSP pages.

    Place these in a subdirectory under $JPS_HOME/src/petstore/src/docroot/ (UNIX) or %JPS_HOME%\src\petstore\src\docroot\ (Win32).

    For example, the Japanese version of the Java Pet Store has localized JSP pages in the directory $JPS_HOME/src/petstore/src/docroot/ja/ (UNIX) or %JPS_HOME%\src\petstore\src\docroot\ja\ (Win32).

  2. Create a localized screen definitions file.

    The screen definitions (which use your localized JSP pages, of course) should go into a file called screendefinitions.xml, which should be placed in a subdirectory under $JPS_HOME/src/petstore/src/docroot/WEB-INF/xml/ (UNIX) or %JPS_HOME%\src\petstore\src\docroot\WEB-INF\xml\ (Win32). (See the English and Japanese versions of screendefinitions.xml.)

    For example, the Japanese screen definitions are stored in %JPS_HOME%/src/petstore/src/docroot/WEB-INF/xml/ja/screendefinitions.xml (UNIX) or %JPS_HOME%\src\petstore\src\docroot\WEB-INF\xml\ja\screendefinitions.xml (Win32).

  3. Modify the request mappings file to reflect the new locale.

    Open $JPS_HOME/src/petstore/src/docroot/WEB-INF/xml/requestmappings.xml (UNIX) or %JPS_HOME%\src\petstore\src\docroot\WEB-INF\xml\requestmappings.xml (Win32) and add a screen-definition element which maps the locale to the new screen definitions file. This element needs two attributes:

    For example, the following entries define the screen definitions for the English and Japanese versions of the Java Pet Store, respectively:

    <screen-definition
        url="/WEB-INF/xml/screendefinitions.xml"
        language="en_US"/>
    <screen-definition
        url="/WEB-INF/xml/ja/screendefinitions.xml"
        language="ja_JP"/>
  4. Modify the catalog component to reflect the new locale.

    Change the class com.sun.j2ee.blueprints.shoppingcart.util.DatabaseNames to point to the correct database tables in relation to the current locale.

    All calls to the catalog component require a locale as an argument. The method getTableName() currently handles the US and Japanese locales:

    public static String getTableName(String tableName, Locale locale) {
        if (locale.equals(Locale.US)) {
            return tableName;
        } else if (locale.equals(Locale.JAPAN)) {
            return tableName + "_ja";
        }
        return tableName;
    }

    Note that the Java Pet Store installs English and Japanese versions of the catalog tables. If you add another locale, you'll probably have to create database tables that support it.

  5. Modify the application's JSP utilities class to reflect the new locale.

    You also need to edit the method getLocaleFromLanguage() in the class com.sun.j2ee.blueprints.petstore.util.JSPUtil. This method currently handles the US and Japanese locales:

    public static Locale getLocaleFromLanguage(String language) {
        Locale locale = Locale.US;
        if (language.equals("English")) locale = Locale.US;
        else if (language.equals("Japanese")) locale = Locale.JAPAN;
        return locale;
    }

Copyright © 2001 Sun Microsystems, Inc. All Rights Reserved.