Transalted messages in client script

rajaganeshs
Kilo Contributor

We are displaying field messages using showFieldMessage in catalog client script. But if the user preferred language is different we should display the translated version. How to achieve this requirement?

1 ACCEPTED SOLUTION

AnveshKumar M
Tera Sage
Tera Sage

Hi @rajaganeshs 

 

You can try the following approach.

 

1. Add translations for your text in sys_ui_message.

AnveshKumarM_0-1699014355252.png

 

2. In your client script try the following code.

 

g_form.showFieldMessage("VARIABLE_NAME", getMessage("My example message from client script"), "info");

 

 

Please mark my answer helpful and accept as solution if it helped 👍✔️

Thanks,
Anvesh

View solution in original post

4 REPLIES 4

Shruti
Mega Sage
Mega Sage

Hi,

Use below code in client script

getMessage("Test Message", function(msg){
g_form.addInfoMessage(msg);
});

Navigate to System UI -> messages

Create a new entry with Key = "Test Message" //Key used in client script

Select the language

Enter the translated value in Message field and save the record

Shruti_0-1699008684678.png

 

@Shruti  Thanks for the answer.

The solution you provided is for formMessage. But it's good to know this approach for future use.

AnveshKumar M
Tera Sage
Tera Sage

Hi @rajaganeshs 

 

You can try the following approach.

 

1. Add translations for your text in sys_ui_message.

AnveshKumarM_0-1699014355252.png

 

2. In your client script try the following code.

 

g_form.showFieldMessage("VARIABLE_NAME", getMessage("My example message from client script"), "info");

 

 

Please mark my answer helpful and accept as solution if it helped 👍✔️

Thanks,
Anvesh

Thanks @AnveshKumar M

This is what exactly I'm looking for.

Thanks again 👍