Introduction
Using supported globalization codes in Oracle APEX is essential for developing applications that cater to a global audience. These codes define language, territory, and regional settings that influence how dates, numbers, currencies, and text are displayed and processed. Understanding and applying the correct globalization codes ensures that your application respects local conventions and provides users with a familiar, intuitive experience regardless of their location.
Using supported globalization codes in Oracle APEX is a fundamental step in building applications that correctly handle language, regional settings, and data formats such as dates, numbers, and currencies. Globalization codes are standardized identifiers that define language and territory conventions, enabling your application to present information in a way that aligns with users’ cultural and regional expectations.
Here is a detailed guide on how to use supported globalization codes in Oracle APEX:
-
Understand Globalization Codes Format
Globalization codes typically follow the formatlanguage[_territory]
, where:-
Language is a two-letter ISO 639-1 code (e.g.,
en
for English,fr
for French,ja
for Japanese). -
Territory is a two-letter ISO 3166-1 alpha-2 country code (e.g.,
US
for United States,FR
for France).
For example,en_US
represents English as spoken in the United States, whilefr_FR
stands for French in France.
-
-
Set Primary Language and Globalization Attributes
In your Oracle APEX application, go to Shared Components > Globalization Attributes. Here, you can:-
Specify the Primary Language using a globalization code (e.g.,
en_US
). -
Set the Application Primary Time Zone and Date Format consistent with the target region.
-
-
Add Supported Languages
Under Shared Components > Languages, add the globalization codes corresponding to the languages and territories your application will support. These codes will be used to control translations and locale-specific formatting. -
Control Session Language and Locale
Oracle APEX determines the session language using several methods, including browser preferences, application items, or URL parameters. You can programmatically set the session language using PL/SQL:BEGIN APEX_UTIL.SET_SESSION_LANG('fr_FR'); END;
This sets the language and regional context for the user session.
-
Use Globalization Codes in SQL and PL/SQL
You can reference globalization codes in your SQL queries or PL/SQL logic to control formatting or data retrieval based on user locale. For example, usingTO_CHAR
with a format model that adapts to locale or usingNLS_SESSION_PARAMETERS
:SELECT value FROM nls_session_parameters WHERE parameter = 'NLS_LANGUAGE';
-
Format Items Based on Locale
When designing page items (date pickers, number fields), you can use the globalization code to dynamically apply format masks appropriate for the user’s locale. This ensures that dates, numbers, and currencies appear in familiar formats. -
Translate Application Text Based on Language Codes
The globalization codes correspond to the language codes used in the APEX translation framework. When exporting and importing translation files, make sure to use the correct globalization codes to match target languages. -
Test Multi-Language and Regional Support
Switch session languages and territories during testing to verify that your application displays data correctly for each locale. Check for date formatting, numeric separators, currency symbols, and translated text.
By effectively using supported globalization codes, Oracle APEX developers can create applications that adapt dynamically to user language and regional preferences. This leads to improved usability, better international reach, and a polished user experience tailored to diverse audiences worldwide.
Oracle APEX provides built-in globalization codes that determine how an application behaves in different languages, date formats, number formats, and regional settings. These codes are automatically set based on the Globalization Attributes selected at the application level. Understanding these codes is essential for building multilingual applications that display data correctly based on the user's locale.
What Are Globalization Codes?
Globalization codes control various language and region-based behaviors in an APEX application, such as:
Application language (determines which translated text is shown)
Date and number formatting (e.g., DD/MM/YYYY vs. MM/DD/YYYY)
Currency symbols (e.g., $ for USD vs. € for EUR)
Sorting and collation rules (e.g., alphabetical order differences across languages)
These codes are applied at the session level, meaning they can dynamically change based on the user's preferences.
Where Are Globalization Codes Set?
Globalization settings are primarily controlled in Application Attributes under the Globalization section. You can configure:
Primary Language – The default language in which the application is developed.
Application Language Derived From – Determines how the user’s language is selected:
User’s browser settings
A specific APEX item
A PL/SQL function
Date and Number Format Derived From – Defines whether date and number formats follow:
Application language
User’s browser settings
A specific APEX item
These settings impact how APEX renders content and interacts with database data.
Common Globalization Codes in Oracle APEX
These values are set automatically but can be overridden using PL/SQL code.
Retrieving and Modifying Globalization Codes
You can check the current globalization settings using SQL:
SELECT
SYS_CONTEXT('USERENV', 'NLS_LANGUAGE') AS language,
SYS_CONTEXT('USERENV', 'NLS_TERRITORY') AS territory,
SYS_CONTEXT('USERENV', 'NLS_DATE_FORMAT') AS date_format,
SYS_CONTEXT('USERENV', 'NLS_CURRENCY') AS currency
FROM DUAL;
This query returns the session-specific settings for language, territory, and date formats.
To manually change these settings at the session level, use:
ALTER SESSION SET NLS_LANGUAGE = 'FRENCH';
ALTER SESSION SET NLS_TERRITORY = 'FRANCE';
ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MM-YYYY';
This modifies the behavior for the current session only.
Controlling Globalization in APEX Applications
In Oracle APEX, you can dynamically control globalization settings using Dynamic Actions or PL/SQL processes.
Example: Setting the Application Language from a Select List
Add a Select List (P0_LANGUAGE) with values 'en', 'fr', 'es'.
Create a PL/SQL Process to set the session language:
BEGIN
APEX_UTIL.SET_SESSION_LANG(:P0_LANGUAGE);
END;
Refresh the page so that the language changes dynamically.
This ensures users can switch languages at runtime.
Best Practices for Using Globalization Codes
Always set consistent NLS parameters for date and number formatting to prevent errors.
Store translations separately using APEX’s built-in translation features.
Use APEX_UTIL.SET_SESSION_LANG to dynamically change the application language.
Test applications in different locales to ensure all formatting rules work as expected.
Consider NLS_SORT settings when performing text searches to ensure correct results across languages.
By understanding and managing globalization codes in Oracle APEX, developers can build applications that automatically adapt to different languages, number formats, and regional preferences, ensuring a smooth user experience for international audiences.
Conclusion
Mastering supported globalization codes in Oracle APEX allows developers to build truly internationalized applications that adapt seamlessly to different languages and regional preferences. By leveraging these codes for language and territory settings, you can enhance data formatting, improve user interaction, and make your applications more accessible and relevant to users around the world.
No comments:
Post a Comment