Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Marking messages in jelly files

Your jelly files in src/main/resources often contain messages that need to be localized, and those need to be marked as well.

In the simplest case, suppose you have a part of a Jelly file that looks like the following:

No Format

<h1>Output</h1>
<p>...</p>

Then all you need to do is to change this to the following:

No Format

<h1>${%Output}</h1>
<p>...</p>

The ${%...} marker indicates stapler to look for localized resources, and when none is found it'll just print "Output" for this, which is what you want.

Let's consider the case where the localization requires parameters. Suppose you have a Jelly file foo.jelly like this:

No Format

<p>Click <a href="${obj.someMethod(a,b,c)}">here</a></p>

In this case, first you have to write foo.properties for the default locale:

No Format

click.here.link=Click <a href="{0}">here</a>

Then update foo.jelly to refer to this like this:

No Format

<p>${%click.here.link(obj.someMethod(a,b,c))}</p>

If you have multiple parameters you can pass them by separating ',' (just like a function call), and from property files you can reference them as {0}, {1}, etc., by following the MessageFormat class convention.