Legal | Privacy

Building a Global Application with the Globalization Development Kit (GDK)

In this lesson, you use the APIs in the Oracle Globalization Development Kit (GDK) to migrate an existing English-only monolingual J2EE application to a global multilingual application. The application contains a JSP front end to a simple customer order-retrieval application (Oracle  Store) based on the oe sample schema. The application contains servlets that use GDK to persist regular Java objects.

This lesson covers the following topics:

Overview
Prerequisites
Files in the Oracle Store Application

Installing the Oracle Store Application

Running the Current English-Only Oracle Store Application
Configuring and Setting Up the GDK Application
Adding Translated Store Logos
Integrating Translated UI Text

Formatting Dates and Numbers with Oracle Formatter Classes

Using Predefined Oracle Locale Translations
Detecting the User-Preferred Locale
Enabling Support for Exchange Rates, Translated Product Names, and Translated Descriptions
Using Oracle Linguistic Sorts
Displaying Flags and Available Language Translations
Adding Support for a New Locale (Germany)
Integrating Language Detection Technology

Place the cursor on this icon to display all the screenshots in the lesson. You can also place the cursor on each individual icon in the following steps to see only the screenshot that is associated with that step.

The Globalization Development Kit (GDK) for Java provides a J2EE application framework and Java APIs to develop globalized Internet applications using the best globalization practices and freatures designed by Oracle. The GDK complements the existing globalization features in Java by extending Oracle Globalization Support features to the application server. Globalization logic such as Oracle date/number/monetary formatting and Oracle binary and linguistic sorting are now available in the middle tier. The GDK provides mappings between Oracle and Java locales, enables character-set conversions between Oracle and Java character sets, and returns locale-related data sets (such as the common languages, linguistic sorts, and local time zones supported in a given region).  It offers APIs that can encapsulate the complexity of globalization programming such as locale determination and processing of the locale information. It supports the detection of the user-preferred locale and the rewriting of URLs to locate content for the different locales.The GDK provides a single application configuration file to control the globalization behavior of the user application.

Note: A locale refers to a national language and the region in which the language is spoken. For example, the primary language of the United States and Great Britain is English; however, the two countries have different currencies and different conventions for date formats. Therefore, the United States and Great Britain are considered to be two different locales.

Before starting this lesson, you should have:

1.

Completed the Configuring Linux for the Installation of Oracle Database 10g lesson

2.

Completed the Installing Oracle Database 10g on Linux lesson

3.

Completed the Installing Oracle9i JDeveloper on Linux lesson

4.

Downloaded and unzipped gdk.zip to your working directory
(/home/oracle/wkdir)

The application includes the following files: 

Java Source Files

src/oracle/i18n/demo/obe/gdkshop
AuthFilter.java Authentication filter
MyAccountAction.java My Account servlet
OrderInformationAction.java Order Information servlet
ShopAction.java Shop actions
src/oracle/i18n/demo/obe/gdkshop/bean
Customer.java Customer bean
Order.java Order bean
OrderItem.java Order item bean
src/oracle/i18n/demo/obe/gdkshop/gdk
DBLocaleSource.java Locale source for user schema in the database
Translations.java UI translations for English (to be added during the lesson)
Translations_de.java UI translations for German (to be added during the lesson)
Translations_es.java UI translations for Spanish (to be added during the lesson)
Translations _zh_cn.java UI translations for Simplified Chinese (to be added during the lesson)

JSP and Static Contents

public_html/
index.jsp Index JSP page
myaccount.jsp My Account JSP page
orderinformation.jsp Order Information JSP page
feedback.jsp A Feedback JSP page
store_logo_new.gif Shop logo image for English
US.gif Flag image for United States (to be added during the lesson)
CN.gif Flag image for China (to be added during the lesson)
DE.gif Flag image for Germany (to be added during the lesson)
ES.gif Flag image for Spain (to be added during the lesson)
IN.gif Flag image for India (to be added during the lesson)
public_html/de/
store_logo_new.gif German Oracle Shop logo (to be added during the lesson)
public_html/es/
store_logo_new.gif Spanish Oracle Shop logo (to be added during the lesson)
public_html/zh_cn/
store_logo_new.gif Simplified Chinese Oracle Shop logo (to be added during the lesson)
public_html/WEB-INF/
web.xml Web deployment descriptor
gdkapp.xml GDK/OGS application configuration file (to be added during the lesson)
public_html/WEB-INF/lib/
orai18n-lcsd.jar GDK LCSD (language and character set detection) extension (to be added during the lesson)
orai18n.jar GDK main library (to be added during the lesson)

To populate the sample schema with new sample data, perform the following steps:

1.

Unzip gdk.zip to your working directory (/home/oracle/wkdir).

 

2.

Create tables for storing currency exchange rates and time zone information. Open a terminal window and execute the following:

cd /home/oracle/wkdir/gdk/step0
sqlplus oe/oe
@obeGdkSetup

Note: obeGdkSetup.sql is a script file that populates tables such as CUSTOMERS, ORDERS, and ORDER_ITEMS of OE schema. This directory also contains the obeGdkRevert.sql script, which uninstalls all the objects that are created for this lesson.

Move your mouse over this icon to see the image

 

You now run Oracle Store as an English-only (monolingual) application and observe its behavior. In the next exercise, you will change the source files to make it a multilingual application.

Note: The modified files are already provided and you are not expected to make changes to the source files. However, the changes that have been made to the files are explicitly described.

To run the monolingual application, perform the following steps:

1.

Launch Oracle9i JDeveloper.

 

2.

Set Mozilla as the default browser in JDeveloper.
Tools > Preferences > Web Browser/Proxy. Enter /usr/bin/mozilla -remote openURL(${URL}) || /usr/bin/mozilla ${URL} in the Browser Command Line field.

Move your mouse over this icon to see the image

 

3.

Click and highlight Workspaces in the System-Navigator window. Click the + icon at the top-left corner to Add to Workspaces.

Move your mouse over this icon to see the image

 

4.

Select the following file, and then click Open:
/home/oracle/wkdir/gdk/obe_gdk.jws

Note: Click Yes if you are asked if you want to migrate these files.

Move your mouse over this icon to see the image

 

5.

Expand the tree to ensure that the project gdkshop.jpr is included.

Move your mouse over this icon to see the image

 

6.

You must verify the JDBC database connect string. Expand the project tree below gdkshop.jpr. Right-click web.xml and select Open.

Move your mouse over this icon to see the image

 

7.

You should see the following information:

<context-param>
  <param-name>gdkdemo.jdbccon</param-name>
  <param-value>jdbc:oracle:thin:@localhost:1521:orcl</param-value>
</context-param> 

This currently connects to a database on your local machine with SID = orcl  using the port number 1521. Replace with your connect string if necessary, and then save the file.

Move your mouse over this icon to see the image

 

8.

Click and highlight the project gdkshop.jpr.
Select Run > Run gdkshop.jpr.

Note: You may have to open a browser instance to view the application

Move your mouse over this icon to see the image

 

9.

The first page is the login screen for the Oracle Store application. The drop-down list shows the available customers and their country of residence. Click the Submit button to view the account profile and the order history of the selected customer.  

Move your mouse over this icon to see the image

 

10.

View the customer details. Observe that the date is displayed in the upper-right corner of the browser. Click Back.

Move your mouse over this icon to see the image

 

11.

Check the details of another customer, Daniel Zhang. Select Daniel Zhang from the drop-down list, and then click Submit.

Move your mouse over this icon to see the image

 

12.

Note that Daniel's territory preference is China, but because this application has not been globalized, all the text is displayed in English. The credit limit is based on U.S. dollars; the date and time stamp of the order is based on the database time stamp and not the customer's time zone. Dates retrieved from the database are formatted using Oracle date conventions, while the date generated for the application is formatted based on Java conventions. Click the order link to view the details of the order.

Move your mouse over this icon to see the image

 

13.

As on the previous page, all the text (including product names and descriptions) is in English only; the monetary values are formatted using U.S. currency conventions based on U.S. dollars and U.S. debit symbols. The items are ordered based on the binary values of the English-language product names. Click the Oracle Store logo to return to the customer login page.

Move your mouse over this icon to see the image

 

You now migrate from a monolingual Oracle Store to a global multilingual Oracle Store. You add support for the following languages: Simplified Chinese, Spanish, and English. These languages serve Oracle Store customers in China, Spain, and India, respectively.

Notes:

  • You do not need to type the code changes into the existing application. Instead, all the updates are already prepared and shipped with the .zip file to demonstrate the multilingual Oracle Store application.
  • Some language characters may not be supported in certain browsers. We recommend that you use Internet Explorer 6.0 (or later versions) for this lesson.

Perform the following steps:

1.

Open a terminal window and execute the following commands:

cd /home/oracle/wkdir/gdk/gdkshop/public_html/WEB-INF
mkdir lib
cd lib
cp /home/oracle/wkdir/gdk/step1/lib/orai18n.jar orai18n.jar
cp /home/oracle/wkdir/gdk/step1/lib/orai18n-lcsd.jar orai18n-lcsd.jar
cd ..
cp /home/oracle/wkdir/gdk/step1/web.xml web.xml

In JDeveloper, right-click the gdkshop.jpr project and select Project Properties. Click Path and Edit Additional Class Path. Then click Add Entry and add the following paths:

/home/oracle/wkdir/gdk/gdkshop/public_html/WEB-INF/lib/orai18n.jar
and 
/home/oracle/wkdir/gdk/gdkshop/public_html/WEB-INF/lib/orai18n-lcsd.jar
Click OK
 
2.

Execute the following commands from your terminal window:

cd /home/oracle/wkdir/gdk/gdkshop/public_html/WEB-INF
cp /home/oracle/wkdir/gdk/step1/gdkapp.xml gdkapp.xml

The contents of the file include the following:

<?xml version="1.0" encoding="utf-8"?>
<gdkapp
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="gdkapp.xsd">
<!-- Application Configurations -->
<page-charset default="yes">UTF-8</page-charset>
<application-locales>
<locale default="yes">en</locale>
<locale>es</locale>
<locale>zh_CN</locale>
<locale>en_IN</locale>
</application-locales>
<locale-determine-rule>
<locale-source>oracle.i18n.servlet.localesource.HttpAcceptLanguage</locale-source>
</locale-determine-rule>
<!-- URL rewriting rule -->
<url-rewrite-rule fallback="yes">
<pattern>(.*)/([^/]+)$</pattern>
<result>$1/$A/$2</result>
</url-rewrite-rule>
</gdkapp>

This is the GDK application configuration file, which controls the globalization behavior of the Oracle Store application. One application configuration file is required for each J2EE application that uses the GDK.

Supports English (en) as the default application locale. Spanish (es), Simplified Chinese
in China (zh_CN), and English in India (en_IN) are also supported.
Uses the browser language preference (HTTP Accept-Language header)  to
determine the user locale
Rewrites URLs to redirect translated contents based on the user locale

 

You can have different logos for each language. To add the Oracle Store logos, perform the following steps:

1.

In your terminal window, execute the following commands:

cd /home/oracle/wkdir/gdk/gdkshop/public_html
mkdir es
cd es
cp /home/oracle/wkdir/gdk/step2/es/store_logo_new.gif store_logo_new.gif
cd ..
mkdir zh_CN
cd zh_CN
cp /home/oracle/wkdir/gdk/step2/zh_CN/store_logo_new.gif store_logo_new.gif

The directories es and zh_CN store the Oracle Store logos for Spanish and Chinese, respectively.

 

2.

Copy the index.jsp, myaccount.jsp, and orderinformation.jsp files to the appropriate directories. In your terminal window, execute the following:

cd ..
cp /home/oracle/wkdir/gdk/step2/index.jsp index.jsp
cp /home/oracle/wkdir/gdk/step2/myaccount.jsp myaccount.jsp
cp /home/oracle/wkdir/gdk/step2/orderinformation.jsp orderinformation.jsp
cp /home/oracle/wkdir/gdk/step2/feedback.jsp feedback.jsp

Note: This folder already contains these three files, which were used for the monolingual application. Overwrite the old files with the modified ones.

Open each file and observe that the classes in the servlet and util packages are imported as follows:

<%@ page import="oracle.i18n.servlet.*, oracle.i18n.util.*" %>        

The Oracle Store logo file name in the JSP files is changed from store_logo_new.gif to the following:

<%= ServletHelper.rewriteURL("./store_logo_new.gif", request) %>

 

3.

You are now ready to run the application in JDeveloper. First you need to make sure the OC4J server has been terminated. Select Run > Terminate > Embedded OC4J Server.

Move your mouse over this icon to see the image

 

4.

Rebuild the project gdkshop.jpr. Select Project > Rebuild gdkshop.jpr.

Move your mouse over this icon to see the image

 

5.

Select Run > Run gdkshop.jpr.

Move your mouse over this icon to see the image

 

6.

If you see the Oracle Store logo in English (as displayed in the accompanying screenshot), you should set the language preference of your browser.

Move your mouse over this icon to see the image

 

7.

The steps in this lesson assume that you are using a Mozilla browser. Select Edit > Preferences. Then select Languages under Navigator. Click the Add button.

Move your mouse over this icon to see the image

 

8.

Enter es in the Others field, and then click OK.

Move your mouse over this icon to see the image

 

9.

Notice that Spanish has been added to the list. Click the Add button again to add Chinese.

Move your mouse over this icon to see the image

 

10.

Enter zh-CN in the Others field, and then click OK.

Move your mouse over this icon to see the image

 

11.

Select Spanish in the list and click the Move Up button until Spanish appears at the top of the list. Then click OK..

Move your mouse over this icon to see the image

 

12.

Switch back to your Web page and refresh the screen. You now see that the Spanish-language logo is displayed. Make sure that this is reflected on all three JSP pages.

Move your mouse over this icon to see the image

To translate the application into different languages, all hard-coded text strings should be externalized to resource files. These files can then be sent for translation. The resource bundle is Java's primary mechanism for localizing applications.

To externalize all UI text from the three JSP files into Java resource bundles, perform the following steps: 

1.

You need to copy the three translation files to your project directory. In your terminal window, execute the following commands:

cd /home/oracle/wkdir/gdk/gdkshop/src/oracle/i18n/demo/obe/gdkshop
mkdir gdk 
cd gdk 
cp /home/oracle/wkdir/gdk/step3/Translations.java Translations.java
cp /home/oracle/wkdir/gdk/step3/Translations_es.java Translations_es.java
cp /home/oracle/wkdir/gdk/step3/Translations_zh_CN.java Translations_zh_CN.java

The contents of the Spanish translation file, Translations_es.java, are as follows:

package oracle.i18n.demo.obe.gdkshop.gdk;
import java.util.ListResourceBundle;
public class Translations_es extends ListResourceBundle
{
static final Object[][] contents =
{
{ "RETURNING_CUSTOMERS", "Clientes que vuelven..." },
{ "SUBMIT", "Env\u00ede" },
{ "MY_ACCOUNT", "Mi cuenta " },
{ "ACCOUNT_PROFILE", "Infomaci\u00f3n de cuenta" },
{ "FIRST_NAME", "Nombre" },
{ "LAST_NAME", "Apellido" },
{ "EMAIL", "Correo electr\u00f3nico" },
{ "LANGUAGE", "Idioma" },
{ "TERRITORY", "Territorio" },
{ "REGISTERED_DATE", "Fecha de registraci\u00f3n" },
{ "CREDIT_LIMIT", "Limite de credito" },
{ "ORDER_TRACKING_AND_HISTORY", "Seguimiento del pedido e historial" },
{ "GRAND_TOTAL", "El gran total" },
{ "TOTAL", "Total" },
{ "DISCOUNT", "Descuento" },
{ "PRODUCT_NAME", "Nombre del producto" },
{ "PRODUCT_DESCRIPTION", "Descripci\u00f3n del producto" },
{ "ITEM_NUMBER", "N\u00famero de parte" },
{ "QUANTITY", "Cantidad" },
{ "SUB_TOTAL", "Subtotal" },
{ "ORDER_INFORMATION", "Informaci\u00f3n de orden" },
{ "ORDER_NUMBER", "N\u00famero de orden" },
{ "ORDER_DATE", "Fecha de orden" },
{ "YOUR_ORDER_PLACED", "Su orden procesada {0}" },
{ "FEEDBACK", "Comentarios" },
{ "YOUR_MESSAGE", "Su comentario ha sido enviado" }
};
public Object[][] getContents()
{
return contents;
}
}

 

2.

To register the Translations class, execute the following commands in the terminal window:

cd /home/oracle/wkdir/gdk/gdkshop/public_html/WEB-INF
cp /home/oracle/wkdir/gdk/step3/gdkapp.xml gdkapp.xml

Review the contents of the file to see the details of the <message-bundles> tag:

<message-bundles>
  <resource-bundle name="default">oracle.i18n.demo.obe.gdkshop.gdk.Translations
  </resource-bundle>
</message-bundles>

3.

The code that is required to handle translation has been added to your JSP files. In the terminal window, execute the following commands:

cd .. (Note: you want to be in the /home/oracle/wkdir/gdk/gdkshop/public_html directory)
cp /home/oracle/wkdir/gdk/step3/index.jsp index.jsp
cp /home/oracle/wkdir/gdk/step3/myaccount.jsp myaccount.jsp
cp /home/oracle/wkdir/gdk/step3/orderinformation.jsp orderinformation.jsp
cp /home/oracle/wkdir/gdk/step3/feedback.jsp feedback.jsp

Review the contents of each file to see that the Localizer object is instantiated at the top of each JSP page by adding the following:

<% Localizer localizer = ServletHelper.getLocalizerInstance(request); %> 

In addition, all translatable texts are replaced with the localizer.getMessage API call. For example, "Returning Customers..." is replaced with the following:

<%= localizer.getMessage("RETURNING_CUSTOMERS") %>


4.

The code that is required to handle translation has been added to your Java files. In the terminal window, execute the following commands:

cd /home/oracle/wkdir/gdk/gdkshop/src/oracle/i18n/demo/obe/gdkshop
cp /home/oracle/wkdir/gdk/step3/MyAccountAction.java MyAccountAction.java
cp /home/oracle/wkdir/gdk/step3/OrderInformationAction.java 
    OrderInformationAction.java

Review the contents of each file to see that the Localizer object is instantiated with the following:

<% Localizer localizer = ServletHelper.getLocalizerInstance (request); %> 

In addition, all translatable texts are replaced with the localizer.getMessage API call. For example, "Returning Customers..." is replaced with the following:

import oracle.i18n.servlet.ServletHelper; 
import oracle.i18n.servlet.Localizer; Localizer localizer = ServletHelper.getLocalizerInstance(request); request.setAttribute("localizer",localizer);

 

5.

Before the application can pick up the Spanish and Simplified Chinese translation files, the resource bundles must be included in the project. In JDeveloper, click and highlight gdkshop.jpr in the System-Navigator window. Click the + icon at the top-left corner.

 

6.

Select and open the directory home/oracle/wkdir/gdk/gdkshop/src. Select Java Source
(*.java)
from the "File type" list. Click Open.

Move your mouse over this icon to see the image

 

7.

Click OK.

Move your mouse over this icon to see the image

 

8.

You are now ready to rerun the application. Terminate the Embedded OC4J Server, Rebuild gdkshop.jpr and Run gdkshop.jpr.

 

9.

You see that the field and button labels on this page are now translated into Spanish. Click the Envie button.

Move your mouse over this icon to see the image

 

10.

You see that the labels and links on this page are translated into Spanish.

Move your mouse over this icon to see the image

 

To format dates and numbers (and see the impact on the application), perform the following steps:

1.

Changes have been made to format the dates and numbers in the application. In the terminal window, execute the following commands:

cd /home/oracle/wkdir/gdk/gdkshop/public_html
cp /home/oracle/wkdir/gdk/step4/myaccount.jsp myaccount.jsp
cp /home/oracle/wkdir/gdk/step4/orderinformation.jsp orderinformation.jsp
cp /home/oracle/wkdir/gdk/step4/feedback.jsp feedback.jsp

The following date formatting is used:

<%= localizer.formatDateTime(new Date(), DateFormat.LONG) %>
<%= localizer.formatDate(customer.registeredDate,DateFormat.SHORT)%>
<%= localizer.formatDateTime(order.orderDate,DateFormat.LONG)%>

The following currency formatting is used:

<%= localizer.formatCurrency(customer.creditLimit) %>  

The following message formatting is used to format complex UI text with translations:

<%=
  new MessageFormat(localizer.getMessage("YOUR_ORDER_PLACED")).
  format(new Object[] {localizer.formatDateTime(o.orderDate, 
DateFormat.LONG)}) %>

2.

You want to change the language in your browser to English. Select Edit > Preferences. Under Navigator, select Languages. Select English/United States and click Move Up. Then select English and click Move Up. Then click OK.

Move your mouse over this icon to see the image

 

3.

You are now ready to rerun the application. Terminate the Embedded OC4J Server, Rebuild gdkshop.jpr and Run gdkshop.jpr.

 

4. Click Submit.

Move your mouse over this icon to see the image

 

5. You see that all the dates, numbers, and currencies now have a consistent format based on Oracle globalization conventions.

Move your mouse over this icon to see the image

 

6. Change the language to Chinese to see how the date and currency change.

Move your mouse over this icon to see the image

 

7. The language is now Chinese. Click the submit button.

Move your mouse over this icon to see the image

 

8. You see that all date and currency formatting has been changed to Chinese.

Move your mouse over this icon to see the image

Because the localizer is dependent on the language setting in the browser, the time stamp is also being converted from the database time zone to the default time zone defined by the browser locale. The problem with this approach is that for countries with more than one time zone, the converted time stamp may not accurately reflect the local time of the customer. See Detecting the User-Preferred Locale for information on resolving this issue.

In addition, the currency is now changed to reflect the local currency. However, because the exchange rates are never static and do vary between currencies, it is not possible for the localizer to recalculate the new values automatically. See
Enabling Support for Exchange Rates, Translated Product Names, and Translated Descriptions for information on resolving this issue.

 

Using Predefined Oracle Locale Translations    

The translations of names for all Oracle-supported territories, languages, linguistic sorts, time zones, currencies, and character sets are available in the GDK. These can be used directly inside the application by calling the appropriate classes. To use the predefined Oracle locale translations, the following changes are made:

1.

Changes have been made to myaccount.jsp for the translations of names. In the terminal window, execute the following commands:

cd /home/oracle/wkdir/gdk/gdkshop/public_html
cp /home/oracle/wkdir/gdk/step5/myaccount.jsp myaccount.jsp

The territory in the account profile is changed to the appropriate translated name:

<%= localizer.getDisplayTerritory(customer.nlsTerritory)%>

The language name is changed to the appropriate translated language name:

<%= 
  localizer.getDisplayLanguage
  (LocaleMapper.getOraLanguageFromShortName(customer.nlsLanguage))
%>  

The language ID stored in the OE.CUSTOMER table uses the Oracle short language name. To get the full translation name, call LocaleMapper.getOraLanguageFromShortName.

 

2.

You are now ready to rerun the application. Terminate the Embedded OC4J Server, Rebuild gdkshop.jpr and Run gdkshop.jpr.

 

3. When the first page appears, click Submit. Note that the language and the territory names on the Account Profile page are now translated into the language set in your  browser.

Move your mouse over this icon to see the image

 

Detecting the User-Preferred Locale

A customer's account profile already contains that customer's language and territory information. This information can be used to establish the preferred locale after the customer logs in to the application. A table storing the customers' time zone information was created by the OBE setup script obeGdkSetup.sql. This information is used to convert from the system time stored in the database to the user's current time zone.

 

SQL> desc ext_user_profile
         
 Name                                      Type
 ----------------------------------------- -----------------------
 CUSTOMER_ID                               NUMBER(6)
 TIMEZONE                                  VARCHAR2(50)
 REG_DATE                                  DATE
         
SQL> select * from ext_user_profile;
           
 CUSTOMER_ID TIMEZONE                                           REG_DATE
 ----------- -------------------------------------------------- ---------
        9000 America/Los_Angeles                                30-SEP-02
        9001 Europe/Madrid                                      05-MAR-01
        9002 Asia/Shanghai                                      12-JUN-99
        9003 Asia/Calcutta                                      23-NOV-00
        9004 Europe/Berlin                                      20-NOV-02
       

 

Perform the following steps:

1.

A DBLocaleSource is created that will retrieve the user's locale preference stored in the OE.CUSTOMER table, and the user's time zone in  OE.EXT_USER_PROFILE. In the terminal window, execute the following commands:

cd /home/oracle/wkdir/gdk/gdkshop/src/oracle/i18n/demo/obe/gdkshop/gdk
cp /home/oracle/wkdir/gdk/step6/DBLocaleSource.java DBLocaleSource.java

 

2.

To register the locale source class in the GDK configuration file, a change has been made to gdkapp.xml. In the terminal window, execute the following commands:

cd /home/oracle/wkdir/gdk/gdkshop/public_html/WEB-INF
cp /home/oracle/wkdir/gdk/step6/gdkapp.xml gdkapp.xml

One line was added (in bold) to the gdkapp.xml file.

<locale-determine-rule>
    <locale-source>oracle.i18n.demo.obe.gdkshop.gdk.DBLocaleSource
</locale-source>
  <locale-source>oracle.i18n.servlet.localesource.HttpAcceptLanguage
</locale-source> </locale-determine-rule>

 

3.

Before the application can pick up the Spanish and Simplified Chinese translation files, the resource bundles need to be included into the project. In JDeveloper, click and highlight gdkshop.jpr in the System-Navigator window. Click the + icon at the top-left corner.

 

4.

Before the application can pick up DBLocaleSource.java, the file needs to be included in the JDeveloper project. Select and open the directory home/oracle/wkdir/gdk/gdkshop/src. Select Java Source
(*.java)
from the "File type" list. Click Open.

Move your mouse over this icon to see the image

 

5.

Click OK.

Move your mouse over this icon to see the image

 

6.

You are now ready to rerun the application. Terminate the Embedded OC4J Server, Rebuild gdkshop.jpr and Run gdkshop.jpr.

 

7.

Make sure that Becky.Landis (AMERICA) is selected, and then click the button to show the details.

Move your mouse over this icon to see the image

 

8.

The application simulates the customer logging in and proceeds to present the order history information, based on the customer's time zone, language, and territory settings. In this case, it is English. Click the Oracle Store logo.

Move your mouse over this icon to see the image

 

9.

Select Colin.Olin (SPAIN), and then click the button to show the details.

Move your mouse over this icon to see the image

 

10.

The information is now translated into Spanish. Click the order link.

Move your mouse over this icon to see the image

Note: The GDK application framework can also detect locale preferences stored inside a user profile table, using a predefined locale source rather than a customer locale source. You can incorporate the locale source to the framework by defining it under the <locale-determine-rule> tab in the GDK application configuration file.

 

Observe that the product names and descriptions are still in English, although some of the text on the page is in Spanish.

Move your mouse over this icon to see the image

In this exercise, you learn how to translate product names and descriptions and how to support exchange rates.

 

The previous exercise provided the localizer with the customer's locale information. Orders can be further customized to include the product names and descriptions in the user's local language. Exchange rates can be applied to the orders to convert from U.S. dollarsto the local currency of the customer.

 

SQL> desc exchange_rates;
          Name                                      Type
          ----------------------------------------- -----------------------
          NLS_TERRITORY                             VARCHAR2(50)
          RATES                                     NUMBER(8,4)
         
SQL> select * from exchange_rates;
         
         NLS_TERRITORY                                RATES
         -------------------------------------------- ----------
         AMERICA                                      1
         CHINA                                        8.2768
         INDIA                                        47.175
         GERMANY                                      .8705
         JAPAN                                        117.168
         SPAIN                                        .8705

 

Perform the following steps:

1.

In the terminal window, execute the following commands:

cd /home/oracle/wkdir/gdk/gdkshop/src/oracle/i18n/demo/obe/gdkshop
cp /home/oracle/wkdir/gdk/step7/ShopAction.java ShopAction.java
cp /home/oracle/wkdir/gdk/step7/MyAccountAction.java MyAccountAction.java
cp /home/oracle/wkdir/gdk/step7/OrderInformationAction.java 
     OrderInformationAction.java

The modifications to the ShopAction.java file are:

Import globalization classes in ShopAction.java:

  import java.util.Locale;
  import oracle.i18n.servlet.Localizer;
  import oracle.i18n.util.OraLocaleInfo;
  import oracle.i18n.util.LocaleMapper;
  import oracle.i18n.text.OraCollator;
Add a Localizer parameter to getOrders:
  public static List /* Order */ getOrders(String
          userid, Localizer localizer) throws Exception

Enhance the SQL to include the exchange rate for order_total:

         
    ps = cn.prepareStatement(
      "SELECT o.order_id, o.order_date, o.order_mode, o.customer_id, "
      + "o.order_status, o.order_total * e.rates, "
      + "TO_CHAR(o.order_date, 'DD-MON-RR HH12:MI:SS AM') "
      + "FROM orders o, customers c, exchange_rates e "
      + "WHERE o.customer_id = c.customer_id AND "
      + "e.nls_territory =? AND "
      + "LOWER(c.cust_email) = LOWER(?) ORDER BY order_date DESC" );
    ps.setString(1, localizer.getOraTerritory().toUpperCase(Locale.US));
    ps.setString(2, userid); 

Add a Localizer parameter to getOrder:

  public static Order getOrder(long orderid, Localizer localizer) throws Exception


Enhance the SQL to include the exchange rate for order_total:

     ps = cn.prepareStatement(
       "SELECT o.order_id, o.order_date, o.order_mode, o.customer_id,          "
     + "o.order_status, o.order_total * e.rates,          "
     + "TO_CHAR(o.order_date, 'DD-MON-RR HH12:MI:SS AM')          "
     +"FROM orders o, exchange_rates e "
     + "WHERE o.order_id = ? AND e.nls_territory = ?"  );
     ps.setLong(1, orderid);
     ps.setString(2, localizer.getOraTerritory().toUpperCase(Locale.US));
     :
     :
    
  public static Customer getCustomer(String userid) throws Exception

Enhance the SQL to include the exchange rate for credit_limit:

         
   ps = cn.prepareStatement(
     "SELECT c.cust_first_name, c.cust_last_name, c.nls_language, "
   + "c.nls_territory, c.cust_email, c.credit_limit * ex.rates, "
   + "e.reg_date, TO_CHAR(e.reg_date) "
   + "FROM customers c, ext_user_profile e, exchange_rates ex "
   + "WHERE c.customer_id = e.customer_id "
   + "AND ex.nls_territory = c.nls_territory "
   + "AND LOWER(c.cust_email) = LOWER(?)" );


Add a Localizer parameter to getOrderItems:

      public static List /* OrderItem */ getOrderItems(long orderId, Comparator
            sortComp, Localizer localizer) throws Exception
         

Change the SQL to get the translated product names and descriptions:

       
      ResultSet rs = null;
   ps = cn.prepareStatement("SELECT oi.order_id, oi.product_id,"
       + "pd.translated_name, pd.translated_description,"
       + "oi.unit_price * e.rates, oi.quantity        FROM order_items oi, "
       + "product_information p,        product_descriptions pd,exchange_rates e " 
       + "WHERE oi.order_id = ? AND        p.product_id = oi.product_id AND "
       + "pd.product_id = p.product_id        AND pd.language_id = ? AND "
       + "e.nls_territory = ?"
     );
   ps.setLong(1, orderId);
   String lang = localizer.getOraShortLanguage().toUpperCase(Locale.US);
   String terr = localizer.getOraTerritory().toUpperCase(Locale.US);
   ps.setString(2, lang);
   ps.setString(3, terr);
               

The modifications to the MyAccountAction.java file are:

The new Localizer argument is added to getOrder, getOrders, and getOrderItems:

   List orderLst = ShopAction.getOrders(userid, localizer);   

The modifications to the OrderInformationAction.java file are:

 List orderItemList = ShopAction.getOrderItems(orderId, sortDir, localizer);
  Order od = ShopAction.getOrder(orderId, localizer);   

2.

You are now ready to rerun the application. Terminate the Embedded OC4J Server, Rebuild gdkshop.jpr and Run gdkshop.jpr.

 

3.

Review Colin Olin's order again. The product names and product descriptions are now displayed based on the customer's language setting. All monetary values are converted from U.S. dollars to the customer's local currency.

Move your mouse over this icon to see the image

 

In the applications that you have developed and run so far, there is no sort option. To add a linguistic sort, perform the following steps:

1.

In the terminal window, execute the following commands:

cd /home/oracle/wkdir/gdk/gdkshop/src/oracle/i18n/demo/obe/gdkshop/bean
cp /home/oracle/wkdir/gdk/step8/OrderItem.java OrderItem.java
cd ..
cp /home/oracle/wkdir/gdk/step8/ShopAction.java ShopAction.java
cp /home/oracle/wkdir/gdk/step8/OrderInformationAction.java 
     OrderInformationAction.java

The modifications to the OrderItem.java file are:

Import OraCollationKey

    import oracle.i18n.text.OraCollationKey;


Add a variable of type OraCollationKey to OrderItem:

      public OraCollationKey ocolkey;


Change Comparator objects so that collation keys are compared (instead of product names):

                  
   From  return s.productName.compareTo(d.productName);
   To    return s.ocolkey.compareTo(d.ocolkey);
       
   From  return d.productName.compareTo(s.productName);
   To    return d.ocolkey.compareTo(s.ocolkey);
                

The modifications to the ShopAction.java file are:

Import OraCollator

    import oracle.i18n.text.OraCollator;

Add a new URL parameter to hold the name of the linguistic sort:

    public static String PARAM_SORT_NAME = "sortname";

Add a method that retrieves the linguistic sort name:

    public static String getSortingName(HttpServletRequest request)
     {
       String sortname = request.getParameter(PARAM_SORT_NAME);
       if (sortname != null)
       {
         return sortname;
       }
       Localizer localizer = (Localizer)request.getAttribute("localizer");
       return localizer.getLocalLinguisticSorts()[0];
     }
       


Add a sort-name parameter to the getOrderItems method:

    public static List /* OrderItem */ getOrderItems (long orderId, String
        sortName, Comparator sortComp, Localizer localizer ) throws Exception
        


Add code to generate collation keys for each OrderItem object:

  OraCollator ocol = OraCollator.getInstance(sortName);
    ...
    odit.ocolkey = ocol.getCollationKey(odit.productName); 

The modifications to the ShopAction.java file are:

Add the linguistic sort name to getOrderItems:

  String sortName = ShopAction.getSortingName(request);
    request.setAttribute("sortname", sortName);
    List orderItemList = ShopAction.getOrderItems(orderId, sortName, sortDir,
      localizer);

 

2.

In the terminal window, execute the following commands:

cd /home/oracle/wkdir/gdk/gdkshop/public_html
cp /home/oracle/wkdir/gdk/step8/orderinformation.jsp orderinformation.jsp

The modifications to the orderinformation.jsp file are:

Add a JavaScript that submits the linguistic sort name when you select a pull-down menu:

 <script language="JavaScript" type="text/JavaScript">
  <!--
    function MM_jumpMenu(targ,selObj, restore, orderid){ //v3.0
    eval(targ+".location='orderinformation?orderid="+ orderid +
         "&sortname=" + selObj.options[selObj.selectedIndex].value+"'");
   if (restore) selObj.selectedIndex=0;
    }
  //-->
 </script>
Add a form for the pull-down menu:
 <td width="750" colspan="4">
   <select name="sortings" onChange="MM_jumpMenu(
     'parent',this,0,'<%= order.orderId %>','asc')">
 <%
   String[] lingsorts = localizer.getLocalLinguisticSorts();
   String sortname = (String) request.getAttribute("sortname");
   for (int i=0; i<lingsorts.length; ++i)
   {
 %>
      <option value="<%= lingsorts[i] %>" 
        <%=lingsorts[i].equals(sortname) ? "selected" : "" %>>
        <%=localizer.getDisplayLinguisticSort(lingsorts[i]) %>
      </option>
 <%
   }
 %>
   </select> 
 </td>

 

3.

You are now ready to rerun the application. Terminate the Embedded OC4J Server, Rebuild gdkshop.jpr and Run gdkshop.jpr.

4.

On the Order Information page, you see that a linguistic sort drop-down list (above the Product Name column) is now available. By using it, the customer can resequence the records by selecting from a list of the Oracle linguistic sorts that are suitable for their choosen language. Select Binary Sort from the list.

Move your mouse over this icon to see the image

 

5.

The problem with using binary sort is that uppercase letters are always sorted before all lowercase ones. Click the Oracle Store logo and select Colin.Olin (Spanish) to view the sort options available in Spanish.

Move your mouse over this icon to see the image

 

6.

Select Espanol Multilingue to find that ch is considered as a separate character sorted c and d for sorting in traditional Spanish order.

Move your mouse over this icon to see the image

 

To display all the locales that are supported in the application, you can display flags and language translations. Perform the following steps:

1.

Add bitmaps to indicate the supported locales. In the terminal window, execute the following commands:

cd /home/oracle/wkdir/gdk/gdkshop/public_html
cp /home/oracle/wkdir/gdk/step9/US.gif US.gif
cp /home/oracle/wkdir/gdk/step9/ES.gif ES.gif
cp /home/oracle/wkdir/gdk/step9/CN.gif CN.gif
cp /home/oracle/wkdir/gdk/step9/IN.gif IN.gif
cp /home/oracle/wkdir/gdk/step9/index.jsp index.jsp

The modifications to the index.jsp file are:

Display the names of the supported languages as defined in gdkapp.xml:

 <%
   Locale[] locales = localizer.getSupportedLocales();
   for (int i=0; i<locales.length; ++i)
   {
     OraLocaleInfo oloc = OraLocaleInfo.getInstance(locales[i]);
     String jt = LocaleMapper.getJavaTerrFromOraTerr(oloc.getTerritory());
 %>
 <td><div align="center"><img src="<%= jt %>.gif" width="25" height="18"><br>
  <font size="-2">
   <%= OraDisplayLocaleInfo.getInstance(locales[i]).getDisplayLanguage(locales[i]) %>
  </font></div>
 </td>
 <%
   }
 %>  


2.

Before the application can pick up the flags, the image files need to be included in the project. In JDeveloper, click and highlight gdkshop.jpr in the System-Navigator window. Click the + icon in the top-left corner.

 

3.

Select and open the directory home/oracle/wkdir/gdk/gdkshop/public_html. Select Image from the "File type" list. Click Open.

Move your mouse over this icon to see the image

 

4.

Click OK.

Move your mouse over this icon to see the image

 

5.

You are now ready to rerun the application. Terminate the Embedded OC4J Server, Rebuild gdkshop.jpr and Run gdkshop.jpr.

 

6.

You should see the four locales that are supported by Oracle Store.

Move your mouse over this icon to see the image

 

7.

If you select Sarah (the customer from Germany), the application defaults to English (en) as the user locale because there is no support for the German locale.

Move your mouse over this icon to see the image

 

Because the Oracle Store application has now been fully globalized using GDK, to add support for a new locale is very simple. You just need to create a tranlsation file with the translations for the new language, a new flag, and a new store logo corresponding to the new locale. Finally, you must update the locale entry in the GDK application configuration file. Perform the following steps:

1.

In the terminal window, execute the following commands:

cd /home/oracle/wkdir/gdk/gdkshop/src/oracle/i18n/demo/obe/gdkshop/gdk
cp /home/oracle/wkdir/gdk/stepA/Translations_de.java Translations_de.java
cd /home/oracle/wkdir/gdk/gdkshop/public_html
cp /home/oracle/wkdir/gdk/stepA/DE.gif DE.gif
mkdir de
cd de
cp /home/oracle/wkdir/gdk/stepA/de/store_logo_new.gif store_logo_new.gif
cd /home/oracle/wkdir/gdk/gdkshop/public_html/WEB-INF
cp /home/oracle/wkdir/gdk/stepA/gdkapp.xml gdkapp.xml

The modifications to the gdkapp.xml file are:

Display the names of the supported languages as defined in gdkapp.xml:

 <application-locales>
      <locale default="yes">en</locale>
      <locale>es</locale>
      <locale>zh_CN</locale>
      <locale>en_IN</locale>
      <locale>de</locale>
  </application-locales>

 

2.

Before the application can pick up the flag images and the German resource bundle, they need to be included in the project. In JDeveloper, click and highlight gdkshop.jpr in the System-Navigator window. Click the + icon in the top-left corner.

 

3.

Shift-select /home/oracle/wkdir/gdk/gdkshop/public_html and /home/oracle/wkdir/gdk/gdkshop/src. Then click Open.

Move your mouse over this icon to see the image

 

4.

Click OK.

Move your mouse over this icon to see the image

 

5.

You are now ready to rerun the application. Terminate the Embedded OC4J Server, Rebuild gdkshop.jpr and Run gdkshop.jpr.

 

6.

You should see the five locales that are now supported by Oracle Store. If you select Sarah, all her order information should be translated. The locale-sensitive information is now based on the German conventions.

Move your mouse over this icon to see the image

Move your mouse over this icon to see the image

Move your mouse over this icon to see the image

 

The Oracle Store application has a feedback page that enables customers to compose and submit feedback. However, without prior knowledge of the language that the feedback is written in, it is not possible for the application to route the feedback to the most appropriate international Oracle Store offices for processing. Perform the following steps to add language detection to the application:

1.

In the terminal window, execute the following commands:

cd /home/oracle/wkdir/gdk/gdkshop/public_html
cp /home/oracle/wkdir/gdk/stepB/feedback.jsp feedback.jsp

The modifications to the feedback.jsp file are:

Import the LCSD packages:

<%@ page import="oracle.i18n.lcsd.*" %>

Detect the content language after getting the content:

<%
  // detect
   String fb_content = request.getParameter("fb_content");
   String olang = null;
   if (fb_content != null && fb_content.length() > 0) 
  {    
     LCSDetector led = new LCSDetector();
     led.detect(fb_content);
     LCSDResultSet ledrs = led.getResult();
     olang = ledrs.getISOLanguage();
   }  
  Localizer localizer = ServletHelper.getLocalizerInstance(request);
%>

Show the result:

<% if (olang != null){%>
<p>
<%= localizer.getMessage("YOUR_MESSAGE") %>
&nbsp;
(<%= localizer.getDisplayLanguage(olang)%>)
</p>
<%}%>
2.

You are now ready to rerun the application. Terminate the Embedded OC4J Server, Rebuild gdkshop.jpr and Run gdkshop.jpr.

 

3.

Click the Feedback link in the upper-right part of the page.

 

4.

Type a message in the text box, and then click Submit.

 

5.

View the result.

 

Place the cursor on this icon to hide all screenshots.

 

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy