Translation for Catalog Variable 'Default Value' and 'Help Text' Instructions

Stacy1
Mega Guru

I have some catalog variables that have help text in them.  I have used sys_ui_message to translate the labels pretty easily.

However on one I have a default value which needs to be translated and the other the more information instructions.

I did what was stated in the documentation.  I went in to the variable, changed my language via the gear to the other language.  Updated the field to the new language and hit update.  I can see it in the sys_translated_text table.  However, when I impersonate a user in that language it still shows in English.

Any ideas?

Thanks,

Stacy

1 ACCEPTED SOLUTION

Narsing1
Mega Sage

Hi,

You can try in this way.  For instance, I have English & Spanish Languages.  I can configure like this.

  • I have a Multi Line Text Variable and I wanted to display a Default Message as "Hello" for English Language and "Hola" for Spanish Language.
  • Now, Create 2 Messages via System UI ==> Messages in English & Spanish Language. Provide names as "mymessage_english" & "mymessage_spanish".  Provide the above text "Hello" & "Hola" under Message field accordingly.
  • In my Multi Line Text Variable "Default value" field, I am going to call like this.
javascript: gs.getUser().getLanguage() == 'en' ?  gs.getMessage('mymessage_english') :  gs.getMessage('mymessage_spanish')

In case, if you have more than 2 Languages, you can create a Script Include with a Method like this and call this method in the "Default value" field.

Method in Script Include


myLanguageMessage: function() {
        var lan = gs.getUser();
        if (lan.getLanguage() == 'en') {
            return gs.getMessage('mymessage_english');
        } else if (lan.getLanguage() == 'es') {
            return gs.getMessage('mymessage_spanish');
        } else if (gs.getLanguage() == '<some other language code>') {
            return gs.getMessage('mymessage_<otherlanguage>');
        }
    },

Calling in Default value like this

javascript: new <Your Script Include Name>.myLanguageMessage()

In the same way, you can configure for help text as well.

 

Please mark it as correct answer if it resolves your issue.

Thanks,

Narsing

View solution in original post

4 REPLIES 4

Narsing1
Mega Sage

Hi,

You can try in this way.  For instance, I have English & Spanish Languages.  I can configure like this.

  • I have a Multi Line Text Variable and I wanted to display a Default Message as "Hello" for English Language and "Hola" for Spanish Language.
  • Now, Create 2 Messages via System UI ==> Messages in English & Spanish Language. Provide names as "mymessage_english" & "mymessage_spanish".  Provide the above text "Hello" & "Hola" under Message field accordingly.
  • In my Multi Line Text Variable "Default value" field, I am going to call like this.
javascript: gs.getUser().getLanguage() == 'en' ?  gs.getMessage('mymessage_english') :  gs.getMessage('mymessage_spanish')

In case, if you have more than 2 Languages, you can create a Script Include with a Method like this and call this method in the "Default value" field.

Method in Script Include


myLanguageMessage: function() {
        var lan = gs.getUser();
        if (lan.getLanguage() == 'en') {
            return gs.getMessage('mymessage_english');
        } else if (lan.getLanguage() == 'es') {
            return gs.getMessage('mymessage_spanish');
        } else if (gs.getLanguage() == '<some other language code>') {
            return gs.getMessage('mymessage_<otherlanguage>');
        }
    },

Calling in Default value like this

javascript: new <Your Script Include Name>.myLanguageMessage()

In the same way, you can configure for help text as well.

 

Please mark it as correct answer if it resolves your issue.

Thanks,

Narsing

Is my answer helpful to you?  If so, please mark it as correct answer so that it helps other Users to find out similar kind of requirement.

Thanks,

Narsing

Good answer, but it can be simplified even more.

You don't need to manage the language yourself, ServiceNow does that for you. All you need is to call the gs.getMessage function.

javascript: gs.getMessage('myMessage');

Then you just add a message for each language in System UI -> Messages making sure they have the same Key (in this example the Key is 'myMessage').

This way you don't need to change your code if you need to add another language. Just add a new message with the same Key and a different Language selected.

@Jannik Nielsen,

This (your way) is the correct way to do it 🙂 

--------------------------------------------------------------------
Director of Globalization Deployment, Internationalization