Introduction
Implementing Oracle APEX Globalization Codes in your application allows you to build solutions that automatically adapt to different languages, regions, and user preferences. These codes help control how text is translated, how dates and numbers are formatted, and how the interface adjusts for international users. By integrating globalization codes properly, you ensure that your application is user-friendly and culturally relevant no matter where your audience is located.
Implementing Oracle APEX globalization codes involves configuring your application to support multiple languages and regional settings. These globalization codes manage how your application behaves based on user preferences, browser settings, or explicit language selections. Oracle APEX includes built-in support for this through language definitions, application attributes, substitution strings, and session-level language controls.
Start by defining the primary language of your application. This is done in Shared Components > Globalization Attributes. Choose the default language (e.g., en
, fr
, de
) that your app will use when no specific preference is set. Also, define how the language should be determined at runtime—via browser, application item, or user profile.
To enable multilingual support, go to Shared Components > Languages. Here, you can add other languages that your application should support. Each language is defined using a language code like es
for Spanish or zh-cn
for Simplified Chinese.
Once languages are configured, use substitution strings and text messages to manage content. Go to Shared Components > Text Messages, where you define messages with a unique name and specify translations for each language. For example:
-
Name:
WELCOME_MSG
-
Language:
en
, Text:Welcome
-
Language:
fr
, Text:Bienvenue
-
Language:
es
, Text:Bienvenido
In your pages, reference the message using #WELCOME_MSG#
, and APEX will automatically replace it with the correct translation based on the session language.
If your application includes translatable UI elements (page titles, region labels, button text), use the Translate Application feature. This generates an XLIFF file (XML Localization Interchange File Format) containing all UI text. Export the file, provide translations for each target language, and re-import it. Oracle APEX will handle language switching automatically when the session language changes.
To set the session language manually, you can use this PL/SQL in a Before Header process:
BEGIN
APEX_UTIL.SET_SESSION_LANG('fr'); -- French
END;
Or, if using a language picker (like a select list), bind the value to an item (e.g., P0_LANGUAGE
) and configure your globalization settings to derive the language from that item.
Date, time, number, and currency formats are also automatically managed based on the session's NLS (National Language Support) settings. These can be customized using PL/SQL:
BEGIN
EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_DATE_FORMAT = ''DD.MM.YYYY''';
EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_NUMERIC_CHARACTERS = '',.'''
END;
You can store language preferences per user in a custom user table and apply them when a user logs in:
DECLARE
v_lang VARCHAR2(10);
BEGIN
SELECT language_code INTO v_lang
FROM app_users
WHERE username = :APP_USER;
APEX_UTIL.SET_SESSION_LANG(v_lang);
END;
By organizing your application this way, you can maintain one code base while delivering content in multiple languages and formats. Oracle APEX globalization codes make it easy to build international-ready applications that automatically adapt to the user's language and cultural expectations.
Implementing globalization codes properly ensures a smoother, more inclusive experience for all users, no matter where they are in the world.
Oracle APEX provides built-in globalization features that allow applications to support multiple languages, date formats, number formats, and other locale-specific settings. Understanding and correctly implementing globalization codes ensures that your APEX application adapts to different user regions and languages seamlessly.
Understanding Globalization Codes
Globalization codes in APEX are settings that control how an application behaves for users in different locations. These codes affect:
Language and translation settings
Date, time, and number formats
Currency display
Sorting and character sets
Session and database NLS (National Language Support) parameters
APEX automatically assigns globalization codes based on the application's Globalization settings. These can be overridden programmatically or adjusted per session.
Setting Globalization Codes in an APEX Application
Step 1: Configuring Globalization Settings at the Application Level
Navigate to App Builder and open your application.
Go to Shared Components.
Under Globalization, select Globalization Attributes.
Configure the following options:
Primary Language: The default language of the application.
Application Language Derived From: Defines how the application determines the user's language. Options include:
Session (derived from user session settings)
Browser Language (automatically detects based on the user’s browser)
Fixed Language (forces a specific language)
Date Format: Defines the default date format for users.
Number Format: Determines decimal and thousand separators.
Step 2: Using Globalization Codes in APEX
You can retrieve and set globalization codes dynamically within APEX.
Retrieve the Current Language
Use the following PL/SQL function to get the language code for the current user session:
SELECT APEX_UTIL.GET_SESSION_LANG FROM DUAL;
Alternatively, use LANG function:
SELECT APEX_LANG.LANG FROM DUAL;
Set the Language Dynamically
You can change the language setting for a user session by setting the language preference:
BEGIN
APEX_UTIL.SET_SESSION_LANG('fr'); -- Set language to French
END;
This method allows users to switch languages dynamically without affecting the entire application.
Step 3: Implementing Translation for Multilingual Applications
Seeding Translations
If you want to support multiple languages, you must first generate a translatable version of your application using Seed Translations:
Go to Shared Components → Globalization → Translate Application.
Click Seed Translations to extract all translatable text.
Download the XLIFF (XML Localization Interchange File Format) file.
Provide the translated content and upload it back into APEX.
Use Publish Application to apply the translations.
Applying Translations at Runtime
To ensure that the correct language is used based on the user's session or browser settings, check the language dynamically:
IF APEX_UTIL.GET_SESSION_LANG = 'es' THEN
-- Apply Spanish settings
APEX_LANG.MESSAGE('WELCOME_MESSAGE');
ELSE
-- Apply English settings
APEX_LANG.MESSAGE('WELCOME_MESSAGE');
END IF;
Step 4: Formatting Dates, Numbers, and Currency
Globalization settings also control how dates, numbers, and currency values appear.
Formatting Dates Based on User Locale
SELECT TO_CHAR(SYSDATE, APEX_UTIL.GET_SESSION_DATE_FORMAT) FROM DUAL;
Alternatively, use NLS_DATE_FORMAT for session-based formatting:
ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MM-YYYY';
Formatting Numbers
Ensure numbers are displayed correctly based on locale:
SELECT TO_CHAR(1234567.89, '999G999G999D99', 'NLS_NUMERIC_CHARACTERS='',.''') FROM DUAL;
Formatting Currency
To format currency based on the session locale:
SELECT TO_CHAR(1000, 'L999G999D99', 'NLS_CURRENCY=''€''') FROM DUAL;
This ensures that currency symbols and formatting are applied based on the user's region.
Step 5: Handling Right-to-Left (RTL) Languages
If your application supports languages like Arabic or Hebrew, you need to adjust styles to support Right-to-Left (RTL) layouts.
In Shared Components, go to Themes → Theme Roller.
Select Enable Right-to-Left Support.
You can also apply CSS to modify directionality:
html[lang="ar"], html[lang="he"] {
direction: rtl;
text-align: right;
}
Step 6: Using Globalization in SQL Queries
To return results based on language settings, use language-dependent queries.
For example, to return translated content dynamically:
SELECT MESSAGE_TEXT
FROM TRANSLATIONS_TABLE
WHERE MESSAGE_ID = 'WELCOME_MESSAGE'
AND LANGUAGE_CODE = APEX_UTIL.GET_SESSION_LANG;
This ensures that users see translated messages based on their session language.
Step 7: Debugging Globalization Issues
If you experience issues with globalization settings, use the APEX Debugging Tool to check the language and formatting settings in real time.
BEGIN
APEX_DEBUG.MESSAGE('Current Language: ' || APEX_UTIL.GET_SESSION_LANG);
APEX_DEBUG.MESSAGE('Current Date Format: ' || APEX_UTIL.GET_SESSION_DATE_FORMAT);
END;
Implementing Oracle APEX globalization codes ensures that your application can support multiple languages, number formats, and date formats dynamically. By configuring globalization attributes, seeding translations, applying language settings at runtime, and formatting content properly, you create a seamless user experience for a global audience.
This approach enhances usability, accessibility, and localization, making your APEX application adaptable to different cultural and regional preferences.
Conclusion
Using Oracle APEX Globalization Codes is an essential step in developing flexible, accessible, and globally ready applications. With careful configuration and use of built-in language tools and locale settings, you can create a seamless experience for users around the world. Whether you're targeting one region or many, APEX provides the framework to localize your application efficiently and effectively.
No comments:
Post a Comment