Get translated labels for a javascript custom action

Having trouble deploying Oxygen XML Web Author? Got a bug to report? Post it all here.
NicoAMP
Posts: 97
Joined: Tue Mar 06, 2018 2:07 pm
Contact:

Get translated labels for a javascript custom action

Post by NicoAMP »

Hello,

I created a new action with javascript and I would like to use translated labels for my description.

Code: Select all

//description
MyCustomAction.prototype.getDescription = function () {
   return 'My custom action description'; //not translated for the moment
};
How can I get, with javascript, the translation (stored in translation.xml) of my description.
In an action created by the UI I can use ${i18n(my.custom.action_description)}

Thanks.

Regards,
Nicolas
Nicolas Delobel
AmeXio
nicolas.delobel at group.amexio.net
andrei_popa
Posts: 6
Joined: Mon Sep 21, 2020 5:24 pm

Re: Get translated labels for a javascript custom action

Post by andrei_popa »

Hello,
For your action, you can add the messages to client-side translations[1], before using them.
Here is an example:

Code: Select all

sync.Translation.addTranslations({
  "my.custom.action_description": { 'en_US': 'english string', 'fr_FR': 'french string'... },
});
MyCustomAction.prototype.getDescription = function () {
   return tr(msgs["my.custom.action_description"]); //now translated
};
You cannot get the client-side messages directly from translation.xml, but you can add them as in the example.

[1] - https://www.oxygenxml.com/maven/com/oxy ... ation.html
Post Reply