Use localization methods in your Virtual Agent scripts to ensure that the content can be translated. Localization methods are designed to show the original text when no translation is found. These methods can be applied to your code before you have created translations.

Localization method for message content

The gs.getMessageLang method checks the Message table [sys_ui_message] for a translated version of the text in the language selected for the current user. If a translated version isn't found, the default language (English) is returned.

This code provides a greeting that dynamically adds the value of the first_name variable.

(function execute() {
        return 'Hi there ' + vaInputs.first_name;
})()

The following example shows that same code rewritten for localization.

(function execute() {
         return gs.getMessageLang('Hi there {0}', vaContext.getRequesterLang()), [vaInputs.first_name]);
})()

The second example uses the gs.getMessageLang method. The text is the same as the previous example, but the format is changed. The number in brackets acts as a placeholder for the variable, which is then listed in an array after the comma: [vaInputs.first_name]. The gs.getMessageLang method searches for a record on the Message table with a key value matching Hi there {0} and a language value matching the requester's language. The method returns the translated version of the text, which is stored in the Message field of the record.

Note: Language values use ISO standard two-character language codes. For more information, see ISO 639.1 language codes.
Figure 1. Example translation record in the Message table
A translation record in the Message table displays the Key column, language, translated Message, and the date the record was updated.
Note: Content is translated only for published topics. Content does not appear translated when previewing unpublished topics.