java.lang.Objectorg.apache.avalon.framework.logger.AbstractLogEnabled
org.apache.cocoon.xml.AbstractXMLProducer
org.apache.cocoon.xml.AbstractXMLPipe
org.apache.cocoon.transformation.AbstractTransformer
org.apache.cocoon.transformation.I18nTransformer
All Implemented Interfaces:
org.apache.avalon.framework.activity.Disposable, CacheableProcessingComponent, org.apache.avalon.framework.service.Serviceable, org.apache.avalon.framework.configuration.Configurable, Transformer, XMLPipe, org.apache.avalon.excalibur.pool.Recyclable, XMLProducer
Direct Known Subclasses:
PortalToolsI18nTransformer
Internationalization - transformer is used to transform i18n markup into text
based on a particular locale.i18n - TBD - sitemap.transformer.i18n -
The i18n transformer works by finding a translation for the user's locale in the configured catalogues. Locale is passed as parameter to the transformer, and it can be determined based on the request, session, or a cookie data by the org.apache.cocoon.acting.LocaleAction .
For the passed local it then attempts to find a message catalogue that satisifies the locale, and uses it for for processing text replacement directed by i18n markup.
Message catalogues are maintained in separate files, with a naming
convention similar to that of java.util.ResourceBundle . I.e.
basename_locale, where basename can be any name,
and locale can be any locale specified using ISO 639/3166
characters (eg. en_AU, de_AT, es).
NOTE: ISO 639 is not a stable standard; some of the language codes it defines (specifically, iw, ji, and in) have changed (see java.util.Locale for details).
Catalogues are of the following format:
<?xml version="1.0"?> <!-- message catalogue file for locale ... --> <catalogue xml:lang="locale"> <message key="key">text <i>or</i> markup</message> .... </catalogue>Where
key specifies a particular message for that
language.
Files to be translated contain the following markup:
<?xml version="1.0"?> ... some text, translate <i18n:text>key</i18n:text>At runtime, the i18n transformer will find a message catalogue for the user's locale, and will appropriately replace the text between the
<i18n:text> markup, using the value between the tags as
the lookup key.
If the i18n transformer cannot find an appropriate message catalogue for the user's given locale, it will recursively try to locate a parent message catalogue, until a valid catalogue can be found. ie:
In addition, catalogues can be split across multiple locations. For example, there can be a default catalogue in one directory with a user or client specific catalogue in another directory. The catalogues will be searched in the order of the locations specified still following the locale ordering specified above. eg: Assuming a basename of messages and a locale of en_AU (no variant) and locations of translations/client and translations, the following search will occur:
The i18n:text element can optionally take an attribute
i18n:catalogue to indicate which specific catalogue to use.
The value of this attribute should be the id of the catalogue to use
(see sitemap configuration).
<map:transformer name="i18n" src="org.apache.cocoon.transformation.I18nTransformer"> <catalogues default="someId"> <catalogue id="someId" name="messages" [location="translations"]> [<location>translations/client</location>] [<location>translations</location>] </catalogue> ... </catalogues> <untranslated-text>untranslated</untranslated-text> <preload>en_US</preload> <preload catalogue="someId">fr_CA</preload> </map:transformer>Where:
catalogue attribute is present, will preload only specified
catalogue. Multiple preload elements can be specified.
To use the transformer in a pipeline, simply specify it in a particular transform, and pass locale parameter:
<map:match pattern="file"> <map:generate src="file.xml"/> <map:transform type="i18n"> <map:parameter name="locale" value="..."/> </map:transform> <map:serialize/> </map:match>You can use org.apache.cocoon.acting.LocaleAction or any other way to provide transformer with a locale.
If in certain pipeline, you want to use a different catalogue as the default catalogue, you can do so by specifying a parameter called default-catalogue-id.
The untranslated-text can also be overridden at the pipeline level by specifying it as a parameter.
For date, time and number formatting use the following tags:
date, date-time and time
accept pattern and src-pattern attribute, with
values of:
short
medium
long
full
Elements date, date-time, time and
number, a different locale and
source-locale can be specified:
<i18n:date src-pattern="short" src-locale="en_US" locale="de_DE"> 12/24/01 </i18n:date>Will result in 24.12.2001.
A given real pattern and src-pattern (not
keywords short, medium, long, full) overrides any value
specified by locale and src-locale attributes.
Future work coming:
< - a href="mailto:kpiroumian@apache.org">Konstantin Piroumian< - a href="mailto:mattam@netcourrier.com">Matthieu Sozeau< - a href="mailto:crafterm@apache.org">Marcus Crafter< - a href="mailto:Michael.Enke@wincor-nixdorf.com">Michael Enke$ - Id: I18nTransformer.java 474832 2006-11-14 15:56:43Z vgritsenko $| Nested Class Summary: | ||
|---|---|---|
| public final class | I18nTransformer.CatalogueInfo | Holds information about one catalogue. The location and name of the catalogue can contain references to input modules, and are resolved upon each transformer usage. It is important that releaseCatalog is called when the transformer is recycled. |
| Field Summary | ||
|---|---|---|
| public static final String | I18N_NAMESPACE_URI | The namespace for i18n is "http://apache.org/cocoon/i18n/2.1". |
| public static final String | I18N_OLD_NAMESPACE_URI | The old namespace for i18n is "http://apache.org/cocoon/i18n/2.0". |
| public static final String | I18N_TEXT_ELEMENT | i18n:text element is used to translate any text, with
or without markup. Example:
<i18n:text> This is <strong>translated</strong> string. </i18n:text> |
| public static final String | I18N_TRANSLATE_ELEMENT | i18n:translate element is used to translate text with
parameter substitution. Example:
<i18n:translate>
<i18n:text>This is translated string with {0} param</i18n:text>
<i18n:param>1</i18n:param>
</i18n:translate>
The i18n:text fragment can include markup and parameters
at any place. Also do parameters, which can include i18n:text,
i18n:date, etc. elements (without keys only).
|
| public static final String | I18N_CHOOSE_ELEMENT | i18n:choose element is used to translate elements in-place.
The first i18n:when element matching the current locale
is selected and the others are discarded.
To specify what to do if no locale matched, simply add a node with
<i18n:choose> <i18n:when locale="en"> Good Morning </en> <i18n:when locale="fr"> Bonjour </jp> <i18n:when locale="jp"> Aligato? </jp> <i18n:otherwise> Sorry, i don't know how to say hello in your language </jp> <i18n:translate> You can include any markup within
|
| public static final String | I18N_WHEN_ELEMENT | i18n:when is used to test a locale.
It can be used within i18:choose elements or alone.
Note: Using locale="*" here has no sense.
Example:
<greeting> <i18n:when locale="en">Hello</i18n:when> <i18n:when locale="fr">Bonjour</i18n:when> </greeting>
|
| public static final String | I18N_IF_ELEMENT | i18n:if is used to test a locale. Example:
<greeting> <i18n:if locale="en">Hello</i18n:when> <i18n:if locale="fr">Bonjour</i18n:when> </greeting>
|
| public static final String | I18N_OTHERWISE_ELEMENT | i18n:otherwise is used to match any locale when
no matching locale has been found inside an i18n:choose
block.
|
| public static final String | I18N_PARAM_ELEMENT | i18n:param is used with i18n:translate to provide
substitution params. The param can have i18n:text as
its value to provide multilungual value. Parameters can have
additional attributes to be used for formatting:
|
| public static final String | I18N_PARAM_NAME_ATTRIBUTE | This attribute affects a name to the param that could be used
for substitution.
|
| public static final String | I18N_DATE_ELEMENT | i18n:date is used to provide a localized date string.
Allowed attributes are: pattern, src-pattern, locale,
src-locale. Usage examples:
<i18n:date src-pattern="short" src-locale="en_US" locale="de_DE"> 12/24/01 </i18n:date> <i18n:date pattern="dd/MM/yyyy" />If no value is specified then the current date will be used. E.g.: <i18n:date />Displays the current date formatted with default pattern for the current locale. |
| public static final String | I18N_DATE_TIME_ELEMENT | i18n:date-time is used to provide a localized date and
time string. Allowed attributes are: pattern, src-pattern,
locale, src-locale. Usage examples:
<i18n:date-time src-pattern="short" src-locale="en_US" locale="de_DE"> 12/24/01 1:00 AM </i18n:date> <i18n:date-time pattern="dd/MM/yyyy hh:mm" />If no value is specified then the current date and time will be used. E.g.: <i18n:date-time />Displays the current date formatted with default pattern for the current locale. |
| public static final String | I18N_TIME_ELEMENT | i18n:time is used to provide a localized time string.
Allowed attributes are: pattern, src-pattern, locale,
src-locale. Usage examples:
<i18n:time src-pattern="short" src-locale="en_US" locale="de_DE"> 1:00 AM </i18n:time> <i18n:time pattern="hh:mm:ss" />If no value is specified then the current time will be used. E.g.: <i18n:time />Displays the current time formatted with default pattern for the current locale. |
| public static final String | I18N_NUMBER_ELEMENT | i18n:number is used to provide a localized number string.
Allowed attributes are: pattern, src-pattern, locale, src-locale,
type. Usage examples:
<i18n:number src-pattern="short" src-locale="en_US" locale="de_DE"> 1000.0 </i18n:number> <i18n:number type="currency" />If no value is specifies then 0 will be used. |
| public static final String | I18N_CURRENCY_ELEMENT | Currency element name |
| public static final String | I18N_PERCENT_ELEMENT | Percent element name |
| public static final String | I18N_INT_CURRENCY_ELEMENT | Integer currency element name |
| public static final String | I18N_CURRENCY_NO_UNIT_ELEMENT | Currency without unit element name |
| public static final String | I18N_INT_CURRENCY_NO_UNIT_ELEMENT | Integer currency without unit element name |
| public static final String | I18N_KEY_ATTRIBUTE | This attribute is used with i18n:text element to indicate the key of
the according message. The character data of the element will be used
if no message is found by this key. E.g.:
<i18n:text i18n:key="a_key">article_text1</i18n:text> |
| public static final String | I18N_ATTR_ATTRIBUTE | This attribute is used with any element (even not i18n)
to translate attribute values. Should contain whitespace separated
attribute names that should be translated:
<para title="first" name="article" i18n:attr="title name"/>Attribute value considered as key in message catalogue. |
| public static final String | I18N_EXPR_ATTRIBUTE | This attribute is used with any element (even not i18n)
to evaluate attribute values. Should contain whitespace separated
attribute names that should be evaluated:
<para title="first" name="{one} {two}" i18n:attr="name"/>
Attribute value considered as expression containing text and catalogue
keys in curly braces. |
| public static final String | I18N_SRC_PATTERN_ATTRIBUTE | This attribute is used with date and number formatting elements to indicate the pattern that should be used to parse the element value. |
| public static final String | I18N_PATTERN_ATTRIBUTE | This attribute is used with date and number formatting elements to indicate the pattern that should be used to format the element value. |
| public static final String | I18N_LOCALE_ATTRIBUTE | This attribute is used with date and number formatting elements to indicate the locale that should be used to format the element value. Also used for in-place translations. |
| public static final String | I18N_SRC_LOCALE_ATTRIBUTE | This attribute is used with date and number formatting elements to indicate the locale that should be used to parse the element value. |
| public static final String | I18N_VALUE_ATTRIBUTE | This attribute is used with date and number formatting elements to indicate the value that should be parsed and formatted. If value attribute is not used then the character data of the element will be used. |
| public static final String | I18N_TYPE_ATTRIBUTE | This attribute is used with i18:param to
indicate the parameter type: date, time, date-time or
number, currency, percent, int-currency, currency-no-unit,
int-currency-no-unit.
Also used with i18:translate to indicate inplace
translations: inplace |
| public static final String | CURRENCY_LOCALE_ATTRIBUTE | This attribute is used to specify a different locale for the currency. When specified, this locale will be combined with the "normal" locale: e.g. the seperator symbols are taken from the normal locale but the currency symbol and possition will be taken from the currency locale. This enables to see a currency formatted for Euro but with US grouping and decimal char. |
| public static final String | I18N_CATALOGUE_ATTRIBUTE | This attribute can be used on i18n:text to indicate the catalogue
from which the key should be retrieved. This attribute is optional,
if it is not mentioned the default catalogue is used. |
| public static final String | I18N_LOCALE | This configuration parameter specifies the default locale to be used. |
| public static final String | I18N_DEFAULT_CATALOGUE_ID | This configuration parameter specifies the id of the catalogue to be used as default catalogue, allowing to redefine the default catalogue on the pipeline level. |
| public static final String | I18N_UNTRANSLATED | This configuration parameter specifies the message that should be displayed in case of a not translated text (message not found). |
| public static final String | I18N_PRELOAD | This configuration parameter specifies locale for which catalogues should be preloaded. |
| public static final String | I18N_FRACTION_DIGITS_ATTRIBUTE | fraction-digits attribute is used with
i18:number to
indicate the number of digits behind the fraction |
| protected ServiceManager | manager | Component (service) manager |
| protected BundleFactory | factory | Message bundle loader factory component (service) |
| protected Map | objectModel | |
| protected Locale | locale | Locale |
| Fields inherited from org.apache.cocoon.xml.AbstractXMLProducer: |
|---|
| EMPTY_CONTENT_HANDLER, xmlConsumer, contentHandler, lexicalHandler |
| Method from org.apache.cocoon.transformation.I18nTransformer Summary: |
|---|
| characters, configure, dispose, endElement, getKey, getLocale, getMessage, getValidity, recycle, service, setup, startElement |
| Methods from org.apache.cocoon.xml.AbstractXMLPipe: |
|---|
| characters, comment, endCDATA, endDTD, endDocument, endElement, endEntity, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startCDATA, startDTD, startDocument, startElement, startEntity, startPrefixMapping |
| Methods from org.apache.cocoon.xml.AbstractXMLProducer: |
|---|
| recycle, setConsumer, setContentHandler, setLexicalHandler |
| Methods from java.lang.Object: |
|---|
| equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method from org.apache.cocoon.transformation.I18nTransformer Detail: |
|---|
|
|
|
|
|
|
|
null
if this instance is not cacheable. |
|
|
|
|