How i18n works in Yanel


I18n serves for translating parts of your application to different languages. It uses a message catalogue to look up a message in a given language which is identified by a unique key.


This example assumes that you are using the XMLResource (or any other subclass of BasicXMLResource).

Example message catalogue (let's say it's stored in the default repository of your realm, with the path /i18n/foo.xml):

<?xml version="1.0" encoding="UTF-8" ?>
<message key="foo.user">
<text language="de">Benutzer</text>
<text language="en">User</text>
<message key="foo.logout">
<text language="de">Abmelden</text>
<text language="en">Log out</text>
<message key="foo.registeredUsers">
<text language="de">Es sind {0} Benutzer registriert.</text>
<text language="en">{0} users are registered.</text>

To translate text using this catalogue, use the following code in your xslt:

<i18n:text xmlns:i18n="" key="foo.user"/>

To translate an attribute:

<input type="submit" value="foo.logout" i18n:attr="value"/>

Or when there are multiple attributes using i18n:

<input type="button" name="Name" value="foo.button.value" title="foo.button.tooltip" i18n:attr="value title"/>


To translate a text with parameters:

  <i18n:text key="foo.registeredUsers"/>

The catalogue has to be associated with the content. There are two ways to do so:

  1. Resource-specific messages
    Add a property to the resource configuration file (.yanel-rc):


  2. Realm specific messages
    Add the following element to your realm.xml:


How it works

There is a transformer (I18nTransformer) which transforms the <i18n:text> elements into the text messages from the catalogue. If no message is found for a given key and a given language, fallback to the default language is applied. If still no message is found, the transformer inserts the message key.

As of today there are three different versions of this transformer in yanel: I18nTransformer, I18nTransformer2, and I18nTransformer3. The first two versions are deprecated. They use a different syntax and they support only plain-text property files as catalogues (ResourceBundles, which means the catalogues are loaded from the classpath).
I18nTransformer3 still supports the old syntax and also allows to use ResourceBundle catalogues, so it's the recommended choice.

Multiple Catalogues

It is possible to have more than one catalogue.
A resource configuration can have several catalogues, the realm can have one, and Yanel has a global message catalogue (see WEB-INF/classes/ or WEB-INF/classes/ Yanel will look for a message with a given key first in the resource catalogues, then in the realm catalogue, and eventually in the global catalogue.

Catalogues of a resource

One can also configure a resource specific catalogue. See for example:

and in particular
<yanel:property name="i18n-catalogue" value="contact-form"/>
which is the resource configuration of

The i18n properties files of the contact resource are located inside the directory src/resources/contact-form/conf, which are copied during the build process to local/TOMCAT/webapps/yanel/WEB-INF/classes, from where the I18nTransformers will read them.

Your comments are much appreciated

Is the content of this page unclear or you think it could be improved? Please add a comment and we will try to improve it accordingly.