Caution: This documentation is for eZ Publish legacy, from version 3.x to 5.x.
For 5.x documentation covering Platform see eZ Documentation Center, for difference between legacy and Platform see 5.x Architecture overview.

i18n

Summary

Marks a string for translation.

Usage

input|i18n( [ context [, comment [, arguments ] ] ] )

Parameters

NameTypeDescriptionRequired
context string The context to which the string belongs. No.
comment string A comment describing the text. No.
arguments hash An associative array of arguments in the input parameter. No.

Returns

A string containing a translated version of the input parameter.

Description

This operator makes it possible to translate static strings that are defined in various templates. It is typically useful to ensure that the HTML interface is available in several languages in a multilanguage scenario.

The operator takes three optional parameters: "context", "comment" and "arguments". The "context" parameter can be used to specify a group to which the input parameter should be related. This is typically useful when there are a lot of strings that need to be structured/grouped. The "comment" parameter makes it possible to add additional comment which can help the person responsible for doing the actual translation. A comment could for example be "Button label" - revealing what that mysterious string actually is. The "arguments" parameter makes it possible to mix dynamic text into the translations. Please refer to "Example 2" for a demonstration of this feature.

Examples

Example 1

{"This is a test"|i18n}

Outputs "This is a test" translated to the current language.

Example 2

{def $number=5}
{"Please enter %number characters."|i18n( '', '', hash( '%number', $number ) )}

Outputs "Please enter 5 characters.", the %number will be dynamically replaced by the variable.

Example 3

{"Are you sure you want to remove these items?"|i18n('design/standard/node')}

Outputs "Are you sure you want to remove these items?" translated to the current language. The translation is taken from the context block named "design/standard/node" located in the appropriate translation file.

For example, let's say that the "translation.ts" file located in the "share/translations/ita-IT/" directory of your eZ Publish installation contains the following lines:

<context>
<name>design/standard/node</name>
 ...
<message>
<source>Are you sure you want to remove these items?</source>
<translation>Sei sicuro di voler rimuovere questi elementi?</translation>
</message>
 ...
</context>

If your current system locale is "ita-IT" (as specified in the " Locale" setting located in the "[RegionalSettings]" section of the "settings/site.ini" configuration file or its override) then the following output is produced: "Sei sicuro di voler rimuovere questi elementi?"

Balazs Halasy (05/02/2004 10:36 am)

Svitlana Shatokhina (21/04/2006 10:32 am)


Comments

  • special characters in translated strings

    Please take care that the i18n operator does prevent the translated string from containing any kind of special chars.

    As such, it is a good idea to have it always followed by the wash operator
    - if the translation files are being provided by a third party
    - if you are outputting content inside a javascript string (in which a case, other languages might easily include a quote char where the original one did not, thus breaking js)
    - if you are outputting content inside html, and the translation might include chars such as &, ", < or >
    • Re: special characters in translated strings

      Oops, was meant to be "Please take care that the i18n operator does NOT prevent the translated string from containing any kind of special chars."