Internationalization (i18n)


Internalization involves adapting the application's wording and texts to the language used by the contributor.

How does it work?

In CMS, a text to be translated is used in the following way in XSL or XML files:

<p><i18n:text i18n:key="WELCOME_MESSAGE" i18n:catalogue="plugin.cms"/></p>

WELCOME_MESSAGE is the translation key. The translation of this key is then stored in files known as " i18n catalogs". These files are suffixed with the language code :

messages_en.xml

<message key="WELCOME_MESSAGE">Bienvenue sur le CMS Ametys</message>

messages_en.xml

<message key="WELCOME_MESSAGE">Welcome to Ametys CMS</message>

Catalog files i18n

In Ametys there are several catalogs i18n:

  • plugins catalogs: plugins/[nom_plugin]/i18nspecific texts and labels plugin
  • workspace catalogs : workspace/[nom_workspace]/i18n: workspace-specific texts and labels

  • graphic design catalogs : skins/[nom_skin]/i18nTexts and labels specific to the graphic charter
  • the application catalog: WEB-INF/i18n

Each catalog is a XML file in the following format:

<?xml version="1.0" encoding="UTF-8"?>
<catalogue xml:lang="fr">
	<message key="MSG_1">Traduction de MSG1</message>
	<message key="MSG_2">Traduction de MSG2</message>
	<message key="MSG_3">Traduction de MSG3</message>
</catalogue>

The name of the internationalization file is of the form messages_[lang].xml where lang is the language code (fr, en, es, de, ...)

The file, if it exists, is the default catalog. It is used for text translation when the language used does not have its own translation file.

There is one exception, however, for the application catalog: the names of the translation files here are of the form application.xml, application_en.xml, application_es.xml, ...

Using a key i18n

To use a i18n key in a XSL file, you must first declare the i18n namespace:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                              xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
    
</xsl:stylesheet>

Next, define the key (i18n:key) and specify the catalog (i18n:catalogue) to be used for translation:

<i18n:text i18n:key="MY_KEY" i18n:catalogue="skin.{$skin}"/>

For the catalog i18n:catalogueThe format depends on the catalog:

  • for a catalog of plugin : plugin.[nom_plugin]
  • for a workspace catalog: workspace.[nom_workspace]
  • for a graphic design catalog : skin.[nom_skin]
  • for the application catalog : application

La traduction d'une clé i18n peut contenir des paramètres. Chaque paramètre est remplacé par  {x} où x est le numéro du paramètre, comme dans l'exemple ci-dessous:

<message key="MY_KEY">{0} - Copyright © {1}. Tous droits réservés.</message>

In a XSL file, parameters are passed as follows:

<i18n:translate>
    <i18n:text i18n:key="MY_KEY" i18n:catalogue="skin.{$skin}"/>
    <i18n:param>Ametys CMS</i18n:param>
    <i18n:param><xsl:value-of select="$year"/></i18n:param>
</i18n:translate>

This will read: "Ametys CMS - Copyright 2013. All rights reserved."

Finally, it's also possible to use a i18n key for element attributes HTML. To do this, simply replace the attribute with the i18n key, preceded by the catalog name, and indicate the attribute(s) to be translated via the i18n:value attribute:

<img src="{ametys:skinURL('img/previous.png')}" i18n:attr="alt title" alt="skin.{$skin}:BUTTON_PREVIOUS" title="skin.{$skin}:GO_TO_PREVIOUS"/>
Back to top