APEX_LANG.MESSAGE API is a great fit for translating messages in APEX. Here we can define a message for each desired language like en, fr etc.
MESSAGE function is very useful to translate the messages or string returned from PL/SQL stored procedures, functions, triggers, packaged procedures, and functions.
Syntax
APEX_LANG.MESSAGE (
p_name IN VARCHAR2 DEFAULT NULL,
p0 IN VARCHAR2 DEFAULT NULL,
p1 IN VARCHAR2 DEFAULT NULL,
p2 IN VARCHAR2 DEFAULT NULL,
...
p9 IN VARCHAR2 DEFAULT NULL,
p_lang IN VARCHAR2 DEFAULT NULL,
p_application_id IN NUMBER DEFAULT NULL)
RETURN VARCHAR2;
Parameter | Description |
---|---|
p_name | Name of the message as defined in Text Messages under Shared Components of your application in Oracle Application Express. |
p0 through p9 | Dynamic substitution value: p0 corresponds to %0 in the translation string; p1 corresponds to %1 in the translation string; p2 corresponds to %2 in the translation string, and so on. |
p_lang | Language code for the message to be retrieved. If not specified, Oracle Application Express uses the current language for the user as defined in the Application Language Derived From attribute. |
p_application_id | Used to specify the application ID within the current workspace that owns the translated message you wish to return. Useful when coding packages that might be called outside of the scope of Oracle Application Express such as packages called from a database job. |
Examples:
- Define Message Shared Components > Globalization > Text Messages
How to use APEX_LANG.MESSAGE?
- Plain String
Select apex_lang.message(p_name=>'TEXT_MESSAGE') from dual;
- Specific language
Select apex_lang.message(p_name=>'TEXT_MESSAGE', p_lang=>'hi') from dual;
- With Substitution
Select apex_lang.message('MESSAGE_WITH_SUBSTITUTION', V('APP_USER')) from dual;
- Test in Command Prompt
Select apex_lang.message('MESSAGE_WITH_SUBSTITUTION','Ashish ', p_application_id =>128 ) from dual;
Here Application id is 128 where i have created the Messages.