Willem
Giga Sage
Giga Sage

The benefit of using translations

You can use Translations in many places. Here are some examples I will use in this Article:

- To set a field message

- Generate an Info or Error message

- Translate options

 

You can enter the translations in the [sys_ui_message]-table

 

Plugin for translations

Make sure you have the language you want to translate to installed:

https://docs.servicenow.com/bundle/orlando-platform-administration/page/administer/localization/task...

 

The Callback

To set up a translated Message in the Service Portal you need to use a Callback like so:

getMessage(messageKey, callback)

 

This is because the getMessage without callback is not supported in the Service Portal:

https://docs.servicenow.com/bundle/orlando-servicenow-platform/page/build/service-portal/concept/uns...

 

An example:

Without Callback:

g_form.addErrorMessge(getMessage('Your text in English'))

We get a JavaScript error caused by the system:

find_real_file.png

 

With Callback:

getMessage('Your text in English', function (msg) {
			g_form.addErrorMessage(msg);
		});

We get the error message we want:

find_real_file.png

 

The script: Examples

- To set a field message

getMessage('Your text in English', function (msg) {
    g_form.showFieldMsg('field_name', msg,'info');
});

 

- Generate an Info or Error message

info:

getMessage('Your text in English', function (msg) {
    g_form.addInfoMessage(msg);
});

error:

getMessage('Your text in English', function (msg) {
			g_form.addErrorMessage(msg);
		});

 

- Translate options to add or remove:

To add the option:

getMessage('Your option in English', function(msg){
    g_form.addOption('field_name','value', msg);
})

To remove you can just use:

g_form.removeOption('field_name','value');

 

Thanks @Mark Roethof for helping with this article.

Mark has a great article which mentions you can add the Message field to the Catalog Client script form as well as some other interesting information:

https://community.servicenow.com/community?id=community_article&sys_id=8d43d2bfdb4d8c50d58ea345ca961...

 

 

 

Comments
Daniel Oderbolz
Mega Sage

Dear Willem

Thanks for this article, this is valuable! 

One Input: the message-based translation system, where the English term is the "key" and the translation is the "value" can lead to issues which are evident in Service Now.

If, for example, the "key" is "open", it is absolutely unclear if this refers to a verb or an adjective.

When we translate this to another language like German or French or Italian or... many others - this leads to amiguity.

For example "Open" on a Button should read "öffnen", "ouvrir", "aprire" (verb), while "Open Tasks" should read "Offene Aufgaben", "tâches ouvertes" & "assegnazioni aperte". Note how the order also changes in French and Italian, which is yet another problem.

Therefore I would suggest that rather than using English as the "key", the "key" should be artificial. Also, it is not a good idea to split the translations (translating part of an expression), rather the whole expression should be translated.

So I would create a key like "open_verb" and then add an English Translation "open", and also the other translations. This is a bit more work, but it is much more obvious. 

 

Version history
Last update:
‎09-09-2020 11:46 PM
Updated by: