Benefits of Using SetLocalizations() with Locale Catalogue
The ui.Application.GetCurrent().SetLocalizations() Method
Benefits of Using ui.Application.GetCurrent().SetLocalizations()
In some cases, hardcoded client-side messages in forms cannot be translated directly using the Locale Catalogue because they are processed on the server side. To address this limitation, the SetLocalizations() method is used to apply localization to client-side strings. This method allows you to override hardcoded messages with localized translations at runtime.
The SetLocalizations() method provides an opportunity to replace or translate client-side messages dynamically. It accepts a dynamic array of records, where each record contains the original hardcoded string and its translated version.
Define the array for client-side messages using the following structure:
DEFINE client_messages DYNAMIC ARRAY OF RECORD
original STRING,
translated STRING
END RECORD
original: The hardcoded message string in the form.
translated: The corresponding localized string.
Example 1: Basic Usage
...
DEFINE client_messages DYNAMIC ARRAY OF RECORD
original STRING,
translated STRING
END RECORD
LET client_messages[1].original = "Find"
LET client_messages[1].translated = "Encontrar"
LET client_messages[2].original = "In Columns"
LET client_messages[2].translated = "En columnas"
CALL ui.Application.GetCurrent().SetLocalizations(client_messages)
...
In this example, the client-side messages Find and In Columns are replaced with their Spanish translations, Encontrar and En columnas respectively.
Example 2: Using Locale Catalogue with SetLocalizations
To integrate the Locale Catalogue with the SetLocalizations() method, you can retrieve translations from a resource file instead of hardcoding the translated strings. This approach maintains consistency with the server-side locale catalogue.
hello_world.4gl:
...
DEFINE client_messages DYNAMIC ARRAY OF RECORD
original STRING,
translated STRING
END RECORD
LET client_messages[1].original = "Find"
LET client_messages[1].translated = %"Find"
LET client_messages[2].original = "In Columns"
LET client_messages[2].translated = %"In Columns"
CALL ui.Application.GetCurrent().SetLocalizations(client_messages)
...
hello_world.4s Resource File:
hello_world_de_DE {
Find {"Finden"}
In Columns {"In Spalten"}
}
Summary
The SetLocalizations() method provides a robust solution for localizing client-side messages that cannot be handled by the server-side Locale Catalogue alone. By defining an array of original and translated strings, you can dynamically update hardcoded form messages at runtime. Integrating this method with the Locale Catalogue ensures that translations remain consistent across the application, offering a seamless internationalization experience.
The ui.Application.GetCurrent().SetLocalizations() method is used to localize client-side messages in forms or dialogs that are directly displayed by the LyciaWeb client. It provides a mechanism to translate the hardcoded text elements that are not automatically processed by the server-side locale catalogue.
While the locale catalogue mechanism on the server side handles most translations in your application, certain messages hardcoded in forms or UI components on the client side cannot be automatically translated. To address this, the SetLocalizations() method can be used to manually replace these client-side strings with their localized versions.
ui.Application.GetCurrent().SetLocalizations(
DYNAMIC ARRAY OF RECORD
original_text STRING,
translated_text STRING
END RECORD
)
DYNAMIC ARRAY OF RECORD: An array where each record contains:
Example 1: Basic Client-Side Localization
...
DEFINE client_messages DYNAMIC ARRAY OF RECORD
original STRING,
translated STRING
END RECORD
LET client_messages[1].original = "Find"
LET client_messages[1].translated = "Buscar"
LET client_messages[2].original = "Cancel"
LET client_messages[2].translated = "Cancelar"
CALL ui.Application.GetCurrent().SetLocalizations(client_messages)
-- Now the client UI will display "Buscar" instead of "Find" and "Cancelar" instead of "Cancel"
...
Example 2: Using Locale Catalogue with SetLocalizations
hello_world.4gl
...
DEFINE client_messages DYNAMIC ARRAY OF RECORD
original STRING,
translated STRING
END RECORD
-- Use locale catalogue for translations
LET client_messages[1].original = "Find"
LET client_messages[1].translated = %'Find'
LET client_messages[2].original = "In Columns"
LET client_messages[2].translated = %'In Columns'
CALL ui.Application.GetCurrent().SetLocalizations(client_messages)
...
hello_world.4s (Locale Catalogue Resource File)
hello_world_de_DE {
Find {"Finden"}
In Columns {"In Spalten"}
}
The ui.Application.GetCurrent().SetLocalizations() method is a powerful tool for handling client-side localization needs in your application. By defining a dynamic array of record with original and translated strings, you can ensure that all client-side messages are displayed in the appropriate language, enhancing the user experience and supporting internationalization.