How to use gs.getMessage() to get the string translated?

hyperjam
Giga Contributor

var ret = ' ';

....

....

if(counter_app == 0){

  switch(counter_level){

  case 0:

  ret += "First level of approval "; // <------   how to get such string translated?

  break;

....

  }

  if     (when.indexOf('always') == -1)

                ret += '\(Depends on selected options)\: '; <--------- how to get such string translated too?

else ...

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Sorry Anna,


I thought you were doing a client script.



For server side scripts (business rules, UI actions, etc) there's no Messages field and you use the gs.getMessage() call.



For best results, go to System UI> Messages and create your translated messages. For example,



key=first_level_of_approval, Message=First level of approval



Now in your script...



ret += gs.getMessage('first_level_of_approval');



This may also be helpful: gs.getMessage() - The Second Parameter


View solution in original post

11 REPLIES 11

Chuck Tomasi
Tera Patron

Sorry Anna,


I thought you were doing a client script.



For server side scripts (business rules, UI actions, etc) there's no Messages field and you use the gs.getMessage() call.



For best results, go to System UI> Messages and create your translated messages. For example,



key=first_level_of_approval, Message=First level of approval



Now in your script...



ret += gs.getMessage('first_level_of_approval');



This may also be helpful: gs.getMessage() - The Second Parameter


yes, thank you!


Works great and as expected.


I use it all the time. Here's a little secret...



You do not NEED the translated message in the System UI> Messages table. Most people just use something like:



var msg = gs.getMessage('You made a mistake');



If no entry is found in the sys_ui_message table, it will simply use "You made a mistake" otherwise, THAT is the key if you do other translations.



That's how lazy people do it. My feeling, however is to use an "ugly" key in the gs.getMessage() call like this:



var msg = gs.getMessage('mistake_message');



Now if there's no key in the sys_ui_message table, it uses 'mistake_message'. If I see that in a notification, screen message, etc. I know "HEY! I forgot to put something in the sys_ui_message table!" Why do I take the extra step? Because when it comes time to translate things from English to any other language, I already have a starting point with the entries in sys_ui_message. If I didn't have them, I would have to start searching scripts to gs.getMessage() calls and ensure there is a corresponding key/message pair record there - which lazy people didn't do.


You're absolutely right. In a long run it is much more efficient, especially i saw it today, while doing translation for different languages.


Hi Chuck ,


Can we translate the level of variables of a catalog item in this way, or there is any better recommended way??