Official Content

Looks for a given text in the Language object sent as a parameter (or in the current active Language object if that parameter is omitted) and returns the corresponding translated text.

Syntax

GetMessageText(MessageCode, [LanguageObjectName)

Where:

MessageCode
    Is the text for which you want to find its translation.

LanguageObjectName
    Is the name of the Language object in which you want to look for a translation.

Scope

Objects: ProcedureTransactionWeb PanelPanelData Provider
Generators: .NET, .NET Framework, JavaApple, Android, Angular

Sample

Consider a Knowledge Base whose default language is English (Kb Language property = 'English').

Set your Environment Translation type property to 'Static'.

Select the Spanish Language object in the KB Explorer below the Localization node:

image_2024724161331_1_png

Set the Environment Translate to language property to 'Spanish'.

Create a Web Panel object that contains a Text Block control in its Web Layout with its Caption = "Hello World".

Define the Web Panel Start event as follows:

Event Start
   Textblock1.Caption = GetMessageText('Hello World', 'Spanish')
Endevent

Build the Web Panel (select 'Build With This Only' from the Web Panel contextual menu).

After this action, open the Spanish Language object.

Note that the "Hello World" text is added (as a Code). Enter the corresponding Localized text (in this case, "Hola Mundo"):

image_202472416446_1_png

Press F5 and when executing the Web Panel, the Text Block Caption is translated as shown below:

image_2024724165535_1_png

Note: No errors are returned by this function. If the MessageCode is not found in the current Language, the MessageCode is returned. It is, therefore, a good design method to use full text message codes that can be used as message texts.

Run-time translation considerations

Make sure to place an exclamation mark (!) in the GetMessageText function for both parameters when the Translation type property is set to Run-time.

Textblock1.Caption = GetMessageText(!'Test about the GetMessageText function', !'Spanish')

You will need to reference the desired texts in the code too so that the application metadata will include the desired translations. The correct code when using Run-time translation is:

&sample = 'Test about the GetMessageText function' // needed so the text is added to the application metadata
Textblock1.Caption = GetMessageText(!'Test about the GetMessageText function', !'Spanish')

Note that, at specification time, the GetMessageText function is used so that texts with no exclamation mark appear translated at runtime. This may lead to performance issues because the GetMessageText function cannot be evaluated by the DBMS, or to specification warnings or errors like the following:

spc0075 Operand getmessagetext( "M") does not match the data type of &var in the IN comparison. (Events, Line: 2)

Last update: March 2025 | © GeneXus. All rights reserved. GeneXus Powered by Globant