Translate Content Examples

Last modified by Manuel Leduc on 2026/08/05 17:15

cogShows how to translate content, using the Message Tool
TypeSnippet
Category
Developed by

Oana Florea

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Description

In Groovy

This snippet allows you to use the internationalized messages in Groovy. Parameters can also be passed as is shown in the example below:

def msgTool = xcontext.context.getMessageTool();
  def paramList = ["Apples", "pears", "oranges"];
  print msgTool.get("fruits", paramList);
  print msgTool.get("apples");

You also need to add the key/value pairs to a Document Resource Bundle (see Internationalizing Applications for more details).

fruits={0}, {1} and {2}!
apples=An apple a day keeps the doctor away!

The result should look like this:

Apples, pears and oranges!
An apple a day keeps the doctor away!

In Velocity

key=Hello {0}, you are {1} years old and a {2} {3}
$msg.get('key', ['John', 18, 'dead', 'zombie'])

Translate StaticList items

<Space>.<ClassName>_<propertyName>_<listIndex>=your key

Get Connected