Skip to Main Content

Namespace: lang

QuickNav

apex.lang

This namespace is used for text and message localization related functions of Oracle Application Express.

Functions

(static) addMessages(pMessages)

Add messages for use by apex.lang.getMessage and the format functions. Can be called multiple times. Additional messages are merged. It is generally not necessary to call this function, because it is automatically called with all the application text messages that have Used in JavaScript set to Yes.

Parameters:
Name Type Description
pMessages Object An object whose properties are message keys, and the values are localized message text.
Example

This example adds a message with key "APPLY_BUTTON_LABEL" and message text "Apply".

apex.lang.addMessages( {
    APPLY_BUTTON_LABEL: "Apply"
} );

(static) clearMessages()

Remove all messages. This method is rarely needed. Many Oracle Application Express components rely on client-side messages, so if you clear the messages you need to add any needed messages again.

Example

This example removes all messages.

apex.lang.clearMessages();

(static) format(pPattern, …pValues) → {string}

Formats a message. Same as apex.lang.formatMessage except the message pattern is given directly. It is already localized or isn't supposed to be. It is not a key. The replacement arguments are HTML escaped.

Parameters:
Name Type Attributes Description
pPattern string The message pattern.
pValues * <repeatable>
Any number of replacement values, one for each message parameter %0 to %9. Non string arguments are converted to strings.
Returns:
The formatted message text.
Type
string
Example

This example returns "Total cost: $34.00" assuming the orderTotal variable equals "34.00".

apex.lang.format( "Total cost: $%0", orderTotal );

(static) formatMessage(pKey, …pValues) → {string}

Format a message. Parameters in the message, %0 to %9, are replaced with the corresponding function argument. Use %% to include a single %. The replacement arguments are HTML escaped.

Parameters:
Name Type Attributes Description
pKey string The message key. The key is used to lookup the localized message text as if with getMessage.
pValues * <repeatable>
Any number of replacement values, one for each message parameter %0 to %9. Non string arguments are converted to strings.
Returns:
The localized and formatted message text. If the key is not found then the key is returned.
Type
string
Example

This example returns "Process 60% complete" when the PROCESS_STATUS message text is "Process %0%% complete" and the progress variable value is 60.

  apex.lang.formatMessage( "PROCESS_STATUS", progress );

(static) formatMessageNoEscape(pKey, …pValues) → {string}

Same as apex.lang.formatMessage except the replacement arguments are not HTML escaped. They must be known to be safe or will be used in a context that is safe.

Parameters:
Name Type Attributes Description
pKey string The message key. The key is used to lookup the localized message text as if with getMessage.
pValues * <repeatable>
Any number of replacement values, one for each message parameter %0 to %9. Non string arguments are converted to strings.
Returns:
The localized and formatted message text. If the key is not found then the key is returned.
Type
string
Example

This example returns "You entered <ok>" when the CONFIRM message text is "You entered %0" and the inputValue variable value is "<ok>". Note this string must be used in a context where HTML escaping is done to avoid XSS vulnerabilities.

apex.lang.formatMessageNoEscape( "CONFIRM", inputValue );

(static) formatNoEscape(pPattern, …pValues) → {string}

Same as apex.lang.format, except the replacement arguments are not HTML escaped. They must be known to be safe or are used in a context that is safe.

Parameters:
Name Type Attributes Description
pPattern string The message pattern.
pValues * <repeatable>
Any number of replacement values, one for each message parameter %0 to %9. Non string arguments are converted to strings.
Returns:
The formatted message text.
Type
string
Example

This example returns "You entered <ok>" when the inputValue variable value is "<ok>". Note this string must be used in a context where HTML escaping is done to avoid XSS vulnerabilities.

apex.lang.formatNoEscape( "You entered %0", inputValue );

(static) getMessage(pKey) → {string}

Return the message associated with the given key. The key is looked up in the messages added with apex.lang.addMessages.

Parameters:
Name Type Description
pKey string The message key.
Returns:
The localized message text. If the key is not found then the key is returned.
Type
string
Example

This example returns "OK" when the localized text for key OK_BTN_LABEL is "OK".

apex.lang.getMessage( "OK_BTN_LABEL" );

(static) hasMessage(pKey) → {boolean}

Return true if pKey exists in the messages added with apex.lang.addMessages.

Parameters:
Name Type Description
pKey string The message key.
Returns:
true if the given message exists and false otherwise.
Type
boolean
Example

This example checks for the existence of a message, "EXTRA_MESSAGE", before using it.

if ( apex.lang.hasMessage( "EXTRA_MESSAGE" ) ) {
    text += apex.lang.getMessage( "EXTRA_MESSAGE" );
}