|
|
Developing and maintaining multi-language sites is a common problem for web developers.
The usage of XML and XSL makes this task much more easier, especially with Cocoon's
content, logic and presentation separation concept.
This approach for internationalization (further - i18n) of XML documents within Cocoon
is based on a transformer -
I18nTransformer
, which uses XML dictionaries for all the i18n data. The namespace of i18n is defined as follows:
xmlns:i18n="http://apache.org/cocoon/i18n/2.0"
The first implementation was developed by Lassi Immonen. In this implementation the syntax was changed according to the Infozone Group's i18n proposal (with small changes) and some new features were implemented.
Enhancements for number, date and time have been contributed by Michael Enke.
- Name : i18n
- Class: org.apache.cocoon.transformation.I18nTransformer
- Cacheable: no.
|
 |  |  |
 | Markup content for translation |  |
 |  |  |
 |  |  |
 | Translation with param substitution |  |
 |  |  |
 |  |  |
 | Date, time and number formatting |  |
 |  |  |
To format dates according to the current locale use <i18n:date src-pattern="dd/MM/yyyy" pattern="dd:MMM:yyyy" value="01/01/2001" /> . The 'src-pattern' attribute will be used to parse the 'value' , then the date will be formatted according to the current locale using the format specified by 'pattern' attribute.
To format time for a locale (e.g. de_DE) use <i18n:time src-pattern="dd/MM/yyyy" locale="de_DE" value="01/01/2001" /> . The 'src-pattern' and 'pattern' attribute may also contain 'short' , 'medium' , 'long' or 'full' . The date will be formatted according to this format.
To format date and time use <i18n:date-time /> .
It is also possible to specify a src-locale: <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 short, medium, long, full) overwrites the locale and src-locale .
If no pattern was specified then the date will be formatted with the DateFormat.DEFAULT format (both date and time). If no value for the date is specified then the current date will be used. E.g.: <i18n:date/> will result in the current date, formatted with default localized pattern.
To format numbers in locale sensitive manner use <i18n:number pattern="0.##" value="2.0" /> . This will be useful for Arabic, Indian, etc. number formatting. Additionally, currencies and percent formatting can be used. E.g.:
-
<i18n:number sub-type="currency" value="1703.74" /> will result in localized presentation of the value - $1,703.74 for US locale.
-
<i18n:number sub-type="int-currency" value="170374" /> will result in localized presentation of the value - $1,703.74 for US locale, 170374 for a currency without subunit.
-
<i18n:number sub-type="percent" value="1.2" /> will result in localized percent value - %120 for most of the locales.
Also, date and number formatting can be used with substitution params. Additional type attribute must be used with params to indicate the param type (date or number). Default type is string .
 |  |  |
 |
<i18n:translate>
<i18n:text>
You have to pay {0} for {1} pounds or {2} of your profit. Valid from {3}
</i18n:text>
<i18n:param type="number" sub-type="currency"
pattern="$#,##0.00">102.5</i18n:param>
<i18n:param type="number" value="2.5">
<i18n:param type="number" sub-type="percent" value="0.10" />
<i18n:param type="date" pattern="dd-MMM-yy" />
</i18n:translate>
|  |
 |  |  |
Result will be like this: You have to pay $102.5 for 2.5 pounds or 10% of your profit. Valid from 13-Jun-01
|
 |  |  |
 | How to migrate from the old I18nTransformer |  |
 |  |  |
|
 |
To make attribute translation work the newer than 1.3.0 version of Xerces is needed, where the removeAttribute()
bug is fixed.
|
|
 |  |  |
 | Usage Pattern for Dictionary Generator Stylesheet |  |
 |  |  |
- Multiple dictionary support
- Dictionary import and include capabilities (like in XSLT)
- Command line dictionary-from-source generation
- Dictionary caching
|
|
|
|