How to Translate UI Macro content

Matthieu B_
Kilo Contributor

Good morning,

In a service catalog entry i'm using a UI Macro to display message with a clickable link to a documentation.

If working fine but i can only display the message in one language but i need the message to be automatically translated regarding g_lang variable's value.

i then tried the following code but with no luck: no message is displayed.

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	
	<j:if test="${g_lang=='en'}">
	<p><b>Need help to fill the form ? Click on <a href="https://undisclosed.com/" target="_blank"><span class="icon-help"></span></a> to open the documentation in a new navigator Tab.</b></p>
	</j:if>
	<j:if test="${g_lang=='fr'}">
	<p><b>Besoin d'aide pour remplir la demande ? Cliquer sur <a href="https://undisclosed.com/" target="_blank"><span class="icon-help"></span></a> pour ouvrir la documentation dans un nouvel onglet de votre navigateur yo.</b></p>
	</j:if>

</j:jelly>

 

Could you help me on this ?

Thank you.

Matthieu

 

(Sorry for language mistakes as english is not my mother language)

1 ACCEPTED SOLUTION

Shane Craddock
Kilo Expert

As Joro mentioned you need to use gs.getMessage(), though to be clear you do use ${} in Jelly, it just doesn't do translations as it does in AngularJS.

Your j:if tests would work if g_lang existed in this context, unless you left the creation of that out of your code snip, if you check your system logs you should see the errors there.

 

You can use something like below to translate the text with the embedded link.

<g:evaluate var='jvar_linkText'>
	gs.getMessage('Need help to fill the form ? Click on {0} to open the documentation in a new navigator Tab.',
		'<a href="https://undisclosed.com/" target="_blank"><span class="icon-help"></span></a>');
</g:evaluate>
<p><b><g:no_escape>${jvar_linkText}</g:no_escape></b></p>

<g:no_escape> is required or the link will be printed as plain text

Or if you would like to keep your format you can get the language using:

<j:if test="${jvar_session.getLanguage() == 'en'}">

View solution in original post

4 REPLIES 4

Community Alums
Not applicable
Use gs.getMessage() instead of ${text} - this is for AngularJS only. You need to add translation in sys_measage_text table beforehand though.

Shane Craddock
Kilo Expert

As Joro mentioned you need to use gs.getMessage(), though to be clear you do use ${} in Jelly, it just doesn't do translations as it does in AngularJS.

Your j:if tests would work if g_lang existed in this context, unless you left the creation of that out of your code snip, if you check your system logs you should see the errors there.

 

You can use something like below to translate the text with the embedded link.

<g:evaluate var='jvar_linkText'>
	gs.getMessage('Need help to fill the form ? Click on {0} to open the documentation in a new navigator Tab.',
		'<a href="https://undisclosed.com/" target="_blank"><span class="icon-help"></span></a>');
</g:evaluate>
<p><b><g:no_escape>${jvar_linkText}</g:no_escape></b></p>

<g:no_escape> is required or the link will be printed as plain text

Or if you would like to keep your format you can get the language using:

<j:if test="${jvar_session.getLanguage() == 'en'}">

Matthieu B_
Kilo Contributor

A big thank you to both of you for giving me these answsers.

I used the following solution because as a beginner it seemed easier for me and it's now displaying properly.

<j:if test="${jvar_session.getLanguage() == 'en'}">

But next time i'll try the gs.getMessage method.

Once again, thank you for uour precious help.

 

Regards,

Matthieu

Community Alums
Not applicable

No worries 🙂

Cheers mate!

 

Joro