How to translate APEX internal messages

In today's globalized world it is so important to be able to have our applications well translated.

In this post I want to show you how we can use the Oracle APEX Message function to translate text strings (or messages) generated from stored procedures, functions, triggers, packed procedures and PL/SQL functions.

Remember that Oracle APEX is translated into 10 languages including Spanish 😊

But when we call procedures within our application, the internal APEX messages are in English, and that's why we use this APEX feature called "Text Message" to translate those messages.

There are about 126 internal messages that need to be translated, as shown in the excerpt from the table below:

This table can be viewed in its entirety in the Oracle APEX documentation in the following link.

In addition, there are also messages that require translation that correspond to the Interactive Grid.

And of course, there are also messages to be translated that correspond to the Interactive Report.

On the other hand, if we use the new APEX Progressive Web App (PWA) functionality we also need to translate the messages.

When using smart filters and facet searches in our application, it is also necessary to translate the messages.

Here is an example of how to translate a message in APEX.

We open our application in Oracle APEX.

For this demonstration I have created a simple application in Oracle APEX.

It is important to note that Oracle Application Express is translated by default into 10 languages, as I mentioned above (English, German, Spanish, French, Italian, Japanese, Korean, Brazilian Portuguese, Simplified Chinese and Traditional Chinese). Unfortunately, if our application uses a different language, we must translate ourselves the internal messages displayed by the APEX reporting engine, such as the Actions button, the search or the "next/previous, etc." links.

But before we learn how to translate APEX internal messages, let's learn how APEX works with the "Text Messaging”.

First of all, we define the language of our application in the globalization section of the application definition.

Save the changes.

Next, we can create a greeting message for the user.

To do this, we go to Shared Components => Text Messages

Click on the button Create Text Message.

The modal window for creating the Text Message opens.

En primer lugar, ingresamos el nombre del mensaje de texto, por ejemplo, GREETING_MSG, seguidamente seleccionamos el idioma inglés y en el recuadro de texto colocamos: <h1>Good morning %0!</h1>.

Seguidamente, realizamos el mismo procedimiento para crear el texto en español, como sigue: <h1>Buen día %0!</h1>.

Click on the Create Text Message button.

What we have done is to create a message called GREETING_MSG in our application in Spanish as Buen Día %0 and in English as Good morning %0.

Let's see how we can now invoke this message:

BEGIN
--
-- Print the greeting
--
HTP.P(APEX_LANG.MESSAGE('GREETING_MSG', V('APP_USER')));
END;

The way in which the attribute is defined p_lang depends on how the APEX engine derives the main language of the application. For example, if we are running the application in Spanish and the above call is made to the APEX_LANG.MESSAGE API, the APEX engine first looks for a message called GREETING_MSG with a LANG_CODE of is. Si no encuentra nada, se revierte al atributo Application Primary Language. Si aún no encuentra nada, el motor APEX busca un mensaje con este nombre con un código de idioma de in.

Function 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 Meaning

ParameterDescription
p_nameMessage name as defined in Text Messages under Shared Components of your application in Oracle APEX .
p0 a través de p9Dynamic substitution value: p0 corresponds to %0 in the translation chain; p1 corresponds to %1 in the translation chain; p2 corresponds to %2 in the translation chain, and so on.
p_langLanguage code of the message to retrieve. If not specified, APEX uses the current language for the user as defined in the Application Language Derived From attribute.
p_application_idUsed to specify the ID of the application within the current workspace that owns the translated message you wish to return. Useful when encoding packages that may be called outside the scope of APEX, such as packages called from a database job.
Parameters description

Now that we know this function, let's see how to implement it in our application.

For example, on page 1 of our application we are going to greet the logged in user.

In the breadcrumb bar region we create a dynamic content region and enter the following code:

BEGIN
--
-- Print the greeting
--
HTP.P(APEX_LANG.MESSAGE('GREETING_MSG', V('APP_USER')));
END;

As our application is defined in the primary language as Spanish (United States) (es-us), when running the application, we will see the user greeting in Spanish:

Now if we change the primary language of the application to English, we will see that when the page is executed, the message will be displayed in English.

Now that we know how Text messages work in APEX, let's see how we can translate APEX internal messages.

For this second demonstration we are going to define our application with the language Ukrainian (uk). (I choose this language because I am proudly of Ukrainian descent, my mother was born in Poltawa, Ukraine, and I have a great affection for my mother's land, and a great love for my homeland Argentina where I was born and raised and now that I live and enjoy the United States I feel very globalized 😊).

When running our application, nothing will be in Ukrainian, right? 😊 then let's create the text message for the greeting in Ukrainian (I trust google translator 😊 ).

And when executing we see the greeting 😊

Now on the other hand, I have the interactive Employee report on page 2.

What I can translate in my application I do on my own, for example the name of the navigation path entry we translate it from Employees to Співробітники.

Undoubtedly everything that we can translate such as the headers of the report, or when more data is found or if there are no records in the report, all of that we can translate from the same page designer without problems.

But how can we translate for example the name of the Actions button or the Go button of the interactive report, because now the APEX engine cannot find a Ukrainian translation and it will show it in English.

So let's see an example of how to translate the name of the Actions button, and the name of the Go button in the search bar into the Ukrainian language.

Interactive Report Messages

We create two text messages:

Text MessageIn EnglishIn Ukrainian
APEXIR_GOGoЗнайти
APEXIR_ACTIONSActionsДії
Description of text messages

These text messages can be found in the table 21-3 from the Oracle APEX documentation regarding the internal message translation issue that I mentioned earlier in this article.

Now we run the application and we see that in the interactive employee report we can already see the translation of the Go button and the Actions button.

This way we can translate internal messages in APEX using this "Text Messaging" functionality.

I share with you this link where you can find the translation scripts for many languages made by the Pretius team.

I hope this article has been useful!

See you soon!

Publicado por Ing. Clarisa Maman Orfali

Clarisa is an Oracle ACE Pro, with more than 25 years of experience as a developer, teacher, author and IT consultant. Clarisa is from Argentina living and working in Irvine, California, in the United States. She is the author of the first three Oracle APEX books. She is also co-founder of the Argentine Oracle Users Group (AROUG) and has specialized for the last 13 years in web application development with Oracle Application Express (APEX).

Un comentario en “Cómo traducir los mensajes internos de APEX

Deja un comentario

Discover more from Kiú

Subscribe now to keep reading and get access to the full archive.

Continue reading