Announcing the Global SNUG Board of Directors. Learn more here

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Mark Roethof
Tera Patron
Tera Patron

Hi there,

When working with Catalog Client Scripts in an International/Multi-Language environment, one could encounter some difficulties setting up Internationalization. For example hard coding messages, performance issues in displaying the translated Messages, or having issues with retrieving UI Messages. Though actually, it doesn't have to be that though!

With this article, I will try to share some insights into experience gained on working with Internationalization on Catalog Client Scripts.

Hardcoding messages

I've seen some examples of developers not being able to set up Internationalization and simply hardcoding messages in Catalog Client Scripts, or retrieving the language setting of the current user thru getReference or GlideAjax.

For example:
Hardcoded messages, multi-language

if(answer == "en" || answer == "") {
	g_form.setValue("description","...");
}
if(answer == "nl") {
	g_form.setValue("description","...");
}

* Retrieving the language (answer) thru GlideAjax usage

UI Messages in combination with getMessage()

More experienced developers would be aware of getMessage().

For example:

if(...) {
	g_form.showFieldMsg("error", "description", getMessage("…"))
}

Works fine except one issue: on the first interaction with this message, the message key will be shown. If your message key for example is "sn_inc_validate_end_date", then on the first interaction this will be shown. On the second interaction, the actual message defined in the UI Message will be shown.

Messages field

On Client Scripts the usage of the "Messages" field is a common thing. Out-of-the-box, we don't have this on Catalog Client Scripts. Though, actually… we do, Catalog Client Script is extended from Client Script and therefore does contain the Messages field. The Messages field is just not on the form lay-out. Why… I don't know. It simply works perfectly, so let's just add the Messages field ourselves!

Out-of-the-box
find_real_file.png


find_real_file.png

Applying Messages field and getMessage()

With this, you could just setup UI Messages as you would normally do. And creating multiple UI Messages for Internationalization. After having the UI Messages added, add the key of the UI Messages to the Messages field in the Catalog Client Script.
Note: If you have multiple UI Messages to be used in the Catalog Client Script, separate the keys with an enter.

Once this is set up, you could simply call your Messages and Internationalize and get rid of hard to maintain hardcoded text by using getMessage().

For example:

if(...) {
	g_form.addErrorMessage(getMessage('ccs_validate-date_future(7)'));
}

---


And that's it actually. Hope you like it. If any questions or remarks, let me know!

👍
If this post helped you in any way, I would appreciate it if you hit bookmark or mark it as helpful.

Interested in more articles, blogs, videos, and Share Projects on Service Catalog I published?
Service Catalog


Kind regards,
Mark

---

LinkedIn

Comments
kevin_eldridge
Giga Expert

Thank you for posting this again message regarding using the Messages fields.

 

Kevin Eldridge

Version history
Last update:
‎11-17-2019 10:21 PM
Updated by: