Skip Headers
Oracle® Application Server Globalization Support Guide
10g Release 2 (10.1.2)
B14004-02
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

2 Developing Locale Awareness

This chapter contains the following topics:

2.1 Developing Locale Awareness in Global Internet Applications

Global Internet applications need to be aware of the user's locale.

Locale-sensitive functions, such as date formatting, are built into programming environments such as C/C++, Java, and PL/SQL. Applications can use locale-sensitive functions to format the HTML pages according to the cultural conventions of the user's locale.

Different programming environments represent locales in different ways. For example, the French (Canada) locale is represented as follows:

Environment Representation Locale Explanation
Various ISO standard fr-CA fr is the language code defined in the ISO 639 standard. CA is the country code defined in the ISO 3166 standard.
Java Java locale object fr_CA Java uses the ISO language and country code.
C/C++ POSIX locale name fr_CA on Sun Solaris POSIX locale names may include a character set that overrides the default character set. For example, the de.ISO8859-15 locale is used to support the Euro symbol.
PL/SQL and SQL NLS_LANGUAGE and NLS_TERRITORY parameters NLS_LANGUAGE="CANADIAN FRENCH"

NLS_TERRITORY="CANADA"

See Also: "Configuring the NLS_LANG Parameter" in Chapter 6

Table 2-1 shows how different programming environments represent some commonly used locales.

Table 2-1 Locale Representations in Different Programming Environments

Locale ISO Java POSIX Solaris NLS_LANGUAGE, NLS_TERRITORY

Arabic (U.A.E.)

ar

ar

ar

ARABIC, UNITED ARAB EMIRATES

Chinese (P.R.C)

zh-CN

zh_CN

zh_CN

SIMPLIFIED CHINESE, CHINA

Chinese (Taiwan)

zh-TW

zh_TW

zh_TW

TRADITIONAL CHINESE, TAIWAN

English (U.S.A)

en

en_US

en_US

AMERICAN, AMERICA

English (United Kingdom)

en-GB

en_GB

en_UK

ENGLISH, UNITED KINGDOM

French (Canada)

fr-CA

fr_CA

fr_CA

CANADIAN FRENCH, CANADA

French (France)

fr

fr_FR

fr

FRENCH, FRANCE

German (Germany)

de-DE

de_DE

de

GERMAN, GERMANY

Greek

el

el

el

GREEK, GREECE

Hebrew

he

he

he

HEBREW, ISRAEL

Italian (Italy)

it

it

it

ITALIAN, ITALY

Japanese

ja-JP

ja_JP

ja_JP

JAPANESE, JAPAN

Korean

ko-KR

ko_KR

ko_KR

KOREAN, KOREA

Portuguese (Brazil)

pt-BR

pt_BR

pt_BR

BRAZILIAN PORTUGUESE, BRAZIL

Portuguese (Portugal)

pt

pt

pt

PORTUGUESE, PORTUGAL

Spanish (Spain)

es-ES

es_ES

es

SPANISH, SPAIN

Thai

th

th

th

THAI, THAILAND

Turkish

tr

tr

tr

TURKISH, TURKEY


If you write applications for more than one programming environment, then locales must be synchronized between environments. For example, Java applications that call PL/SQL procedures should map the Java locales to the corresponding NLS_LANGUAGE and NLS_TERRITORY values and change the parameter values to match the user's locale before calling the PL/SQL procedures.

There are two things that affect an application's overall locale awareness: the development environment in which you create the application, and the target architecture for which the application is built. This chapter addresses these topics with respect to both monolingual and multilingual application architectures.

Determining a User's Locale in Monolingual Internet Applications

A monolingual application, by definition, serves users with the same locale. A user's locale is fixed in a monolingual application and is the same as the default runtime locale of the programming environment.

In most programming environments, almost all locale-sensitive functions implicitly use the default runtime locale to perform their tasks. Monolingual applications can rely on this behavior when calling these functions.

Determining a User's Locale in Multilingual Internet Applications

In a multilingual application, the user's locale may vary. Multilingual applications should do the following:

Multilingual applications can determine a user's locale dynamically in the following ways:

You can use these methods of determining the user's locale together or separately. After the application determines the locale, the locale should be:

2.2 Locale Awareness in J2EE and Internet Applications

This section discusses locale awareness in terms of the particular programming language and development environment in which an application is written.

2.2.1 Locale Awareness in Java Applications

A Java locale object represents the corresponding user's locale in Java. The Java encoding used for the locale is required to properly convert Java strings to and from byte data.

Consider the Java encoding for the locale when you make the Java code aware of a user's locale. There are two ways to make a Java method sensitive to the Java locale and the Java encoding:

  • Using the default Java locale and default Java encoding for the method

  • Explicitly specifying the Java locale and Java encoding for the method

Locale Awareness in Monolingual Java Applications

Monolingual applications should run implicitly with the default Java locale and default Java encoding so that the applications can be configured easily for a different locale. For example, to create a date format using the default Java locale, use the following method call:

DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
dateString = df.format(date); /* Format a date */

Locale Awareness in Multilingual Java Applications

You should develop multilingual applications that are independent of fixed default locales or encodings. Explicitly specify the Java locale and Java encoding that correspond to the current user's locale. For example, specify the Java locale object that corresponds to the user's locale, identified by user_locale, in the getDateTimeInstance() method:

DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, user_locale);
dateString = df.format(date); /* Format a date */


Note:

The only difference between the example code for the monolingual application and the multilingual application is the inclusion of user_locale.

Similarly, do not use encoding-sensitive methods that assume the default Java encoding. For example, you should not use the String.getBytes() method in a multilingual application because it is encoding-sensitive. Instead, use the method that accepts encoding as an argument, which is String.getBytes(String encoding). Be sure to specify the encoding used for the user's locale.

Do not use the Locale.setDefault() method to change the default locale for the following reasons:

  • It changes the Java default locale for all threads and makes your applications unsafe to threads

  • It does not affect the Java default encoding

The Oracle Globalization Development Kit for Java provides a set of Java classes to ensure consistency on locale-sensitive behaviors with Oracle databases. It provides an application framework that enables you to use the locale determination methods declaratively.

2.2.2 Locale Awareness in Perl and C/C++ Applications

Perl and C/C++ use the POSIX locale model for internationalized applications.

Locale Awareness in Monolingual Perl and C/C++ Applications

Monolingual applications should be sensitive to the default POSIX locale, which is configured by changing the value of the LC_ALL environment variable or changing the operating system locale from the Control Panel in Microsoft Windows.


See Also:

Table 2-1 for a list of commonly used POSIX locales

To run on the default POSIX locale, the applications should call the setlocale() function to set the default locale to the one defined by LC_ALL and use the POSIX locale-sensitive functions such as strftime() thereafter. Note that the setlocale() function affects the current process and all threads associated with it, so any multithread application should assume the same POSIX locale in each thread. The following example gets the current time in the format specific to the default locale in Perl:

use locale;
use POSIX qw (locale_h);
...
$old_locale = setlocale( LC_ALL, "" );
$dateString = POSIX::strftime( "%c", localtime());
...

Locale Awareness in Multilingual Perl and C/C++ Applications

Multilingual applications should be sensitive to dynamically determined locales. Call the setlocale() function to initialize the locale before calling locale-sensitive functions. For example, the following C code gets the local time in the format of the user locale identified by user_locale:

#include <locale.h>
#include <time.h>
    ...
    const char *user_locale = "fr";
    time_t ltime;
    struct tm *thetime;
    unsigned char dateString[100];
    ...
    setlocale(LC_ALL, user_locale);
    time (&ltime);
    thetime = gmtime(&ltime);
    strftime((char *)dateString, 100, "%c", (const struct tm *)thetime));
    ...

You must map user locales to POSIX locale names for applications to initialize the correct locale dynamically in C/C++ and Perl. The POSIX locales depend on the operating system.

2.2.3 Locale Awareness in SQL and PL/SQL Applications

PL/SQL procedures run in the context of a database session whose locale is initialized by the NLS_LANG parameter in the database access descriptor (DAD). The NLS_LANG parameter specifies top-level globalization support parameters, NLS_LANGUAGE and NLS_TERRITORY, for the database session. Other globalization support parameters, such as NLS_SORT and NLS_DATE_LANGUAGE, inherit their values from these top-level parameters. These globalization support parameters define the locale of a database session.

There are two ways to make SQL and PL/SQL functions locale sensitive:

  • Basing the locale on the globalization support parameters of the current database session

  • Explicitly specifying the globalization support parameters


See Also:

  • "Configuring the NLS_LANG Parameter" in Chapter 6

  • Oracle Database Reference 10g Release 1 (10.1) in the Oracle Database Documentation Library

  • Oracle Database Globalization Support Guide 10g Release 1 (10.1) in the Oracle Database Documentation Library

for more information about globalization support parameters


Locale Awareness in Monolingual SQL and PL/SQL Applications

Generally speaking, the initial values of the globalization support parameters inherited from NLS_LANG are sufficient for monolingual PL/SQL procedures. For example, the following PL/SQL code calls the TO_CHAR() function to get the formatted date, which uses the current values of the NLS_DATE_FORMAT and NLS_DATE_LANGUAGE parameters:

mydate date;
dateString varchar2(100);
...
select sysdate into mydate from dual;
dateString = TO_CHAR(mydate);

If the initial values of the globalization support parameters are not appropriate, then use an ALTER SESSION statement to overwrite them for the current database session. You can use the ALTER SESSION statement with the DBMS_SQL package. For example:

cur integer;
status integer;
...
cur := dbms_sql.open_cursor;
dbms_sql.parse(cur, 'alter session set nls_date_format = "Day Month, YYYY"',
       dbms_sql.native);
status := dbms_sql.execute(cur);

Locale Awareness in Multilingual SQL and PL/SQL Applications

Multilingual applications should use ALTER SESSION statements to change the locale of the database session to the user's locale before calling any locale-sensitive SQL or PL/SQL functions. You can use the ALTER SESSION statement with the DBMS_SQL package. For example:

cur integer;
status integer;
...
cur := dbms_sql.open_cursor;
dbms_sql.parse(cur, 'alter session set nls_language = "NLS_LANGUAGE_of_user_
       locale"', dbms_sql.native);
dbms_sql.parse(cur, 'alter session set nls_territory = "NLS_TERRITORY_of_
       user_locale"', dbms_sql.native);
status := dbms_sql.execute(cur);

Alternatively, applications can specify the globalization support parameters in every SQL function that accepts a globalization support parameter as an argument. For example, the following PL/SQL code gets a date string based on the language of the user's locale:

mydate date;
dateString varchar2(100);
...
select sysdate into mydate from dual;
dateString TO_CHAR(mydate, 'DD-MON-YYYY HH24:MI:SSxFF', 
                    'NLS_DATE_LANGUAGE=language' );
...

In the preceding code example, language specifies the Oracle language name for the user's locale.

2.3 Locale Awareness in Oracle Application Server Component Applications

This section discusses locale awareness in terms of application development for particular Oracle Application Server components.

2.3.1 Locale Awareness in Oracle Application Server Wireless Services

Oracle Application Server Wireless (OracleAS Wireless) sends all mobile context information as HTTP headers when invoking a request. The user locale is sent using the X-Oracle-User.Locale header. The locale value contains the ISO language, and an optional ISO country code, separated by a hyphen. For example, "en-US", "zh-CN", and "ja" are all valid locale values for this header. Mobile service applications should use the user locale specified in this header to determine the language and cultural conventions used in the user interface.

For example, JSP applications may retrieve the user locale as follows:

<%
   String userLocale = request.getHeader("X-Oracle-User.Locale");
%>

2.3.2 Locale Awareness in Oracle Application Server Forms Services

The Oracle Application Server Forms Services (OracleAS Forms Services) architecture includes:

  • A Java client (browser)

  • OracleAS Forms Services (middle tier)

  • The Oracle customer database (back end)

The Java client is dynamically downloaded from Oracle Application Server when a user runs an OracleAS Forms Services session. The Java client provides the user interface for the OracleAS Forms Services Runtime Engine. It also handles user interaction and visual feedback for actions such as navigating between items or checking a checkbox.

OracleAS Forms Services consists of the OracleAS Forms Services Runtime Engine and the Forms Listener Servlet. The OracleAS Forms Services Runtime Engine is the process that maintains a connection to the database on behalf of the Java client. The Forms Listener Servlet acts as a broker, taking connection requests from the Java client processes and initiating a OracleAS Forms Services runtime process on their behalf.

The NLS_LANG parameter for OracleAS Forms Services initializes the locale of OracleAS Forms Services. The NLS_LANGUAGE parameter derives its value from NLS_LANG and determines the language of OracleAS Forms Services messages. The NLS_TERRITORY parameter also derives its value from NLS_LANG and determines conventions such as date and currency formats.

By default, the NLS_LANG parameter for OracleAS Forms Services initializes the Java client locale. The locale of the Java client determines such things as button labels on default messages and parts of strings in menus.

Locale Awareness in Monolingual OracleAS Forms Services Applications

A user's locale is fixed in a monolingual OracleAS Forms Services application and is usually the same as the default OracleAS Forms Services locale. When you develop a monolingual OracleAS Forms Services application, you must develop it to conform to the intended user's locale. The database character set should be a superset of the OracleAS Forms Services character set.

For example, a monolingual Forms Services application for a Japanese locale should include Japanese text, Japanese button labels, and Japanese menus. The application should also connect to a database whose character set is JA16SJIS, JA16EUC, or UTF8.

The NLS_LANG parameter in the default.env file controls the Forms Services locale. Additionally, in order to pass non-Latin-1 parameters to Forms Services, you can set the defaultcharset parameter in formsweb.cfg.

Locale Awareness in Multilingual OracleAS Forms Services Applications

In a multilingual environment, the application can dynamically determine the locale of OracleAS Forms Services in two ways:

  • Based on the user's profile

  • Based on the user's input

When you develop an OracleAS Forms Services application you must choose one of these methods.

You can configure multilingual OracleAS Forms Services applications by using multiple environment configuration files (envFile). For example, do the following to create a form and translate it into different languages:

  1. Create a form called form.fmx.

  2. Translate it into Japanese and into Arabic using Oracle Translator.

  3. Save them as d:\form\ja\form.fmx (Japanese) and d:\form\ar\form.fmx (Arabic).

  4. Create two environment configurations files, ja.env and ar.env.

  5. Specify the following settings in the appropriate environment file as follows:

Form Environment File NLS_LANG FORMS_PATH
d:\form\ja\form.fmx ja.env JAPANESE_JAPAN.JA16SJIS d:\form\ja
d:\form\ar\form.fmx ar.env ARABIC_EGYPT.ARMSWIN1256 d:\form\ar

Also, you can configure OracleAS Forms Services to read the preferred language settings of the browser. For example, if you have a human resources (HR) application translated into 24 languages, then add an application entry in the formsweb.cfg file similar to the following:

[HR]
default.env
[HR.de]
de.env
[HR.fr]
fr.env
[HR.it]
it.env
.
.
.

When the Forms Servlet detects a language preference in the browser, it checks the formsweb.cfg file to see if there is a translated version of the application.

For example, suppose the request is http://myserver.mydomain/forms/frmservlet?config=HR and the preferred languages are set to German (de), Italian (it), and French (fr), in this order, then this is the order of priority. The Forms Servlet tries to read from the application definitions in the following order:

HR.de
HR.it
HR.fr
HR

If the Forms Servlet cannot find any of those configurations, then it uses the HR configuration (default.env).

This means that you can configure Oracle Forms to support multiple languages with one URL. Each application definition can have its own environment file that contains the NLS language parameter definition. You can also specify separate working directory information and path information for each application.

Additionally, Oracle Forms can display more than one language in a form if the Java client machine has the Albany WT J font installed. You can obtain this font from the utilities CD-ROM in your CD pack or from

http://metalink.oracle.com

The Albany WT J font should be copied to %WINDOWS%\Fonts directory if the client is using JInitiator 1.3.1, or %JAVA_HOME%\lib\fonts directory if the client is using Java Plug-in 1.4.1.

2.3.3 Locale Awareness in Oracle Reports

The Oracle Reports (OracleAS Reports Services) architecture includes:

  • A client tier (browser)

  • A Reports Server (middle tier)

  • An Oracle customer database (back end)

OracleAS Reports Services can run multiple reports simultaneously upon users' requests. The Reports Server enters requests for reports into a job queue and dispatches them to a dynamic, configurable number of pre-spawned runtime engines. The runtime engine connects to the database, retrieves data, and formats output for the client.

The NLS_LANG setting for the Reports Server initializes the locale of the runtime engine. The NLS_LANGUAGE parameter derives its value from the NLS_LANG parameter and determines the language of the Reports Server messages. The NLS_TERRITORY parameter derives its value from the NLS_LANG parameter and determines the date and currency formats. For example, if NLS_LANG is set to JAPANESE_JAPAN.JA16SJIS, then Reports Server messages are in Japanese and reports use the Japanese date format and currency symbol.

The dynamic environment switching feature enables one instance of the Reports Server to serve reports with any arbitrary environment setting, including NLS_LANG. Using the environment element in the Reports Server configuration file, you can create a language environment that can be referenced in two ways:

  • On a per-runtime engine basis through the engine element of the Reports Server configuration file

  • On a per-job basis using the ENVID command line argument


See Also:

Oracle Application Server Reports Services Publishing Reports to the Web for more information about dynamic environment switching

Report output is generated in the OracleAS Reports Services character set. The client needs to be aware of the character set in which OracleAS Reports Services generated the HTML or XML.

Locale Awareness in Monolingual OracleAS Reports Services Applications

A user's locale is fixed in a monolingual OracleAS Reports Services application and is usually the same as the locale of the Reports Server. The database character set should be a superset of the Reports Server character set.

Locale Awareness in a Multilingual OracleAS Reports Services Application

In a multilingual report, the application can dynamically determine the locale of the Reports Server in two ways:

  • Based on the user's profile

  • Based on the user's input

When you develop a report you must choose one of these methods.

You can use the dynamic environment switching feature to support multiple languages.


See Also:


2.3.4 Locale Awareness in Oracle Business Intelligence Discoverer

Oracle Business Intelligence Discoverer (OracleBI Discoverer) can simultaneously support users with different locales. Users may explicitly control the locale used for the user interface, or they may allow OracleBI Discoverer to automatically determine the default. The order of precedence for determining the language and locale is:

  1. Language and locale settings included in the URL for OracleBI Discoverer.

  2. Language and locale settings specified in the OracleBI Discoverer Connection. If the locale is specified in the user's browser, then the language settings in the user's browser is used.

  3. Language and locale of Oracle Application Server.

For example, suppose a user's browser's language and locale are set to German - Germany and the user goes to the URL to start OracleBI Discoverer. The HTML page returned to the user is displayed in German. If the user clicks on the OracleBI Discoverer Connection, which has the language and locale specified as English - US, the OracleBI Discoverer user interface appears in English. This is because the OracleBI Discoverer Connection settings take precedence over the browser's settings.