|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.avalon.framework.logger.AbstractLoggable | +--org.apache.cocoon.xml.AbstractXMLProducer | +--org.apache.cocoon.xml.AbstractXMLPipe | +--org.apache.cocoon.transformation.AbstractTransformer | +--org.apache.cocoon.transformation.I18nTransformer
Internationalization transformer is used to transform i18n markup into text based on a particular locale.
The i18n transformer works by obtaining the users locale
based on request, session attributes or a cookie data. See
LocaleAction.getLocaleAttribute(Map)
for details.
It then attempts to find a message catalogue that satisifies
the particular locale, and use it for for text replacement within i18n markup.
Catalogues are maintained in separate files, with a naming convention
similar to that of ResourceBundle (See java.util.ResourceBundle).
ie.
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</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:
<map:transformer name="i18n" src="org.apache.cocoon.transformation.I18nTransformer"> <catalogue-name>messages</catalogue-name> <catalogue-location>translations</catalogue-location> <untranslated-text>untranslated</untranslated-text> <cache-at-startup>true</cache-at-startup> </map:transformer>where:
To use the transformer in a pipeline, simply specify it in a particular transform. eg:
<map:match pattern="file"> <map:generate src="file.xml"/> <map:transform type="i18n"/> <map:serialize/> </map:match>
Note, catalogue-name, catalogue-location and untranslated-text can all be overridden at the pipeline level by specifying them as parameters to the transform statement.
For date, time and number formatting use the following tags:
date
, date-time
and time
the
pattern
and src-pattern
attribute may have also
values of: short
, medium
, long
or
full
. (See java.text.DateFormat for more info on this).
For 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
short, medium, long, full
) overwrites the
locale
and src-locale
Future work coming:
Field Summary | |
static java.lang.String |
I18N_ATTR_ATTRIBUTE
This attribute is used with any element (even not i18n) to translate attribute values. |
static java.lang.String |
I18N_CACHE_STARTUP
This configuration parameter specifies if the message catalog should be cached at startup. |
static java.lang.String |
I18N_CATALOGUE_LOCATION
This configuration parameter specifies the message catalog location relative to the current sitemap. |
static java.lang.String |
I18N_CATALOGUE_NAME
This configuration parameter specifies the message catalog name. |
static java.lang.String |
I18N_CATALOGUE_PREFIX
This constant specifies the XPath prefix that will be used to retrieve a value from a message catalogue. |
static java.lang.String |
I18N_CURRENCY_ELEMENT
currency element |
static java.lang.String |
I18N_CURRENCY_NO_UNIT_ELEMENT
currency without unit element |
static java.lang.String |
I18N_DATE_ELEMENT
i18n:date is used to provide a localized date string. |
static java.lang.String |
I18N_DATE_TIME_ELEMENT
i18n:date-time is used to provide a localized date and time string. |
static java.lang.String |
I18N_FRACTION_DIGITS_ATTRIBUTE
fraction-digits attribute is used with
i18:number to
indicate the number of digits behind the fraction |
static java.lang.String |
I18N_INT_CURRENCY_ELEMENT
integer currency element |
static java.lang.String |
I18N_INT_CURRENCY_NO_UNIT_ELEMENT
integer currency without unit element |
static java.lang.String |
I18N_KEY_ATTRIBUTE
This attribute is used with i18n:text element to indicate the key of the according message. |
static java.lang.String |
I18N_LOCALE
This configuration parameter specifies the default locale to be used. |
static java.lang.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. |
static java.lang.String |
I18N_NAMESPACE_URI
The namespace for i18n is "http://apache.org/cocoon/i18n/2.0". |
static java.lang.String |
I18N_NUMBER_ELEMENT
i18n:number is used to provide a localized number string. |
static java.lang.String |
I18N_PARAM_ELEMENT
i18n:param is used with i18n:translate to provide substitution params. |
static java.lang.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. |
static java.lang.String |
I18N_PERCENT_ELEMENT
percent element |
static java.lang.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. |
static java.lang.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. |
static java.lang.String |
I18N_TEXT_ELEMENT
i18n:text element is used to translate simple text, e.g.: <i18n:text>This is a multilanguage string</i18n:text> |
static java.lang.String |
I18N_TIME_ELEMENT
i18n:time is used to provide a localized time string. |
static java.lang.String |
I18N_TRANSLATE_ELEMENT
i18n:translate element is used to translate text with parameter substitution, e.g.: <i18n:translate> This is a multilanguage string with {0} param <i18n:param>1</i18n:param> </i18n:translate> |
static java.lang.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 . |
static java.lang.String |
I18N_UNTRANSLATED
This configuration parameter specifies the message that should be displayed in case of a not translated text (message not found). |
static java.lang.String |
I18N_VALUE_ATTRIBUTE
This attribute is used with date and number formatting elements to indicate the value that should be parsed and formatted. |
Fields inherited from class org.apache.cocoon.xml.AbstractXMLProducer |
contentHandler, lexicalHandler, xmlConsumer |
Fields inherited from interface org.apache.cocoon.transformation.Transformer |
ROLE |
Constructor Summary | |
I18nTransformer()
|
Method Summary | |
void |
characters(char[] ch,
int start,
int len)
Receive notification of character data. |
void |
compose(org.apache.avalon.framework.component.ComponentManager manager)
|
void |
configure(org.apache.avalon.framework.configuration.Configuration conf)
Configure this transformer. |
void |
dispose()
|
void |
endElement(java.lang.String uri,
java.lang.String name,
java.lang.String raw)
Receive notification of the end of an element. |
java.util.Locale |
getLocale()
Returns the current locale setting of this transformer instance. |
void |
recycle()
Recycle the producer by removing references |
void |
setup(SourceResolver resolver,
java.util.Map objectModel,
java.lang.String source,
org.apache.avalon.framework.parameters.Parameters parameters)
Uses org.apache.cocoon.acting.LocaleAction.getLocale()
to get language user has selected.
|
void |
startElement(java.lang.String uri,
java.lang.String name,
java.lang.String raw,
org.xml.sax.Attributes attr)
Receive notification of the beginning of an element. |
Methods inherited from class org.apache.cocoon.xml.AbstractXMLPipe |
comment, endCDATA, endDocument, endDTD, endEntity, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startCDATA, startDocument, startDTD, startEntity, startPrefixMapping |
Methods inherited from class org.apache.cocoon.xml.AbstractXMLProducer |
setConsumer, setContentHandler, setLexicalHandler |
Methods inherited from class org.apache.avalon.framework.logger.AbstractLoggable |
getLogger, setLogger, setupLogger, setupLogger, setupLogger |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.xml.sax.ContentHandler |
endDocument, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping |
Methods inherited from interface org.xml.sax.ext.LexicalHandler |
comment, endCDATA, endDTD, endEntity, startCDATA, startDTD, startEntity |
Methods inherited from interface org.apache.cocoon.xml.XMLProducer |
setConsumer |
Field Detail |
public static final java.lang.String I18N_NAMESPACE_URI
public static final java.lang.String I18N_TEXT_ELEMENT
<i18n:text>This is a multilanguage string</i18n:text>
public static final java.lang.String I18N_TRANSLATE_ELEMENT
<i18n:translate> This is a multilanguage string with {0} param <i18n:param>1</i18n:param> </i18n:translate>
I18N_TEXT_ELEMENT
,
I18N_PARAM_ELEMENT
public static final java.lang.String I18N_PARAM_ELEMENT
type
- can be date, date-time, time,
number, currency, currency-no-unit or percent
.
Used to format params before substitution.
value
- the value of the param. If no value is
specified then the text inside of the param element will be used.
locale
- used only with number, date, time,
date-time
types and used to override the current locale to
format the given value.
src-locale
- used with number, date, time,
date-time
types and specify the locale that should be used to
parse the given value.
pattern
- used with number, date, time,
date-time
types and specify the pattern that should be used
to format the given value.
src-pattern
- used with number, date, time,
date-time
types and specify the pattern that should be used
to parse the given value.
I18N_TRANSLATE_ELEMENT
,
I18N_DATE_ELEMENT
,
I18N_TIME_ELEMENT
,
I18N_DATE_TIME_ELEMENT
,
I18N_NUMBER_ELEMENT
public static final java.lang.String I18N_DATE_ELEMENT
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.
I18N_PARAM_ELEMENT
,
I18N_DATE_TIME_ELEMENT
,
I18N_TIME_ELEMENT
,
I18N_NUMBER_ELEMENT
public static final java.lang.String I18N_DATE_TIME_ELEMENT
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.
I18N_PARAM_ELEMENT
,
I18N_DATE_ELEMENT
,
I18N_TIME_ELEMENT
,
I18N_NUMBER_ELEMENT
public static final java.lang.String I18N_TIME_ELEMENT
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.
I18N_PARAM_ELEMENT
,
I18N_DATE_TIME_ELEMENT
,
I18N_DATE_ELEMENT
,
I18N_NUMBER_ELEMENT
public static final java.lang.String I18N_NUMBER_ELEMENT
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.
I18N_PARAM_ELEMENT
,
I18N_DATE_TIME_ELEMENT
,
I18N_TIME_ELEMENT
,
I18N_DATE_ELEMENT
public static final java.lang.String I18N_CURRENCY_ELEMENT
public static final java.lang.String I18N_PERCENT_ELEMENT
public static final java.lang.String I18N_INT_CURRENCY_ELEMENT
public static final java.lang.String I18N_CURRENCY_NO_UNIT_ELEMENT
public static final java.lang.String I18N_INT_CURRENCY_NO_UNIT_ELEMENT
public static final java.lang.String I18N_KEY_ATTRIBUTE
<i18n:text i18n:key="a_key">article_text1</i18n:text>
public static final java.lang.String I18N_ATTR_ATTRIBUTE
<para title="first" name="article" i18n:attr="title name" />
public static final java.lang.String I18N_SRC_PATTERN_ATTRIBUTE
I18N_PARAM_ELEMENT
,
I18N_DATE_TIME_ELEMENT
,
I18N_DATE_ELEMENT
,
I18N_TIME_ELEMENT
,
I18N_NUMBER_ELEMENT
public static final java.lang.String I18N_PATTERN_ATTRIBUTE
I18N_PARAM_ELEMENT
,
I18N_DATE_TIME_ELEMENT
,
I18N_DATE_ELEMENT
,
I18N_TIME_ELEMENT
,
I18N_NUMBER_ELEMENT
public static final java.lang.String I18N_LOCALE_ATTRIBUTE
I18N_PARAM_ELEMENT
,
I18N_DATE_TIME_ELEMENT
,
I18N_DATE_ELEMENT
,
I18N_TIME_ELEMENT
,
I18N_NUMBER_ELEMENT
public static final java.lang.String I18N_SRC_LOCALE_ATTRIBUTE
I18N_PARAM_ELEMENT
,
I18N_DATE_TIME_ELEMENT
,
I18N_DATE_ELEMENT
,
I18N_TIME_ELEMENT
,
I18N_NUMBER_ELEMENT
public static final java.lang.String I18N_VALUE_ATTRIBUTE
I18N_PARAM_ELEMENT
,
I18N_DATE_TIME_ELEMENT
,
I18N_DATE_ELEMENT
,
I18N_TIME_ELEMENT
,
I18N_NUMBER_ELEMENT
public static final java.lang.String I18N_TYPE_ATTRIBUTE
i18:param
to
indicate the parameter type: date, time, date-time
or
number, currency, percent, int-currency, currency-no-unit,
int-currency-no-unit
.public static final java.lang.String I18N_LOCALE
public static final java.lang.String I18N_CATALOGUE_NAME
public static final java.lang.String I18N_CATALOGUE_LOCATION
public static final java.lang.String I18N_UNTRANSLATED
public static final java.lang.String I18N_CACHE_STARTUP
public static final java.lang.String I18N_CATALOGUE_PREFIX
/catalogue/message[@key='key_value']
public static final java.lang.String I18N_FRACTION_DIGITS_ATTRIBUTE
fraction-digits
attribute is used with
i18:number
to
indicate the number of digits behind the fractionConstructor Detail |
public I18nTransformer()
Method Detail |
public java.util.Locale getLocale()
public void configure(org.apache.avalon.framework.configuration.Configuration conf) throws org.apache.avalon.framework.configuration.ConfigurationException
configure
in interface org.apache.avalon.framework.configuration.Configurable
public void setup(SourceResolver resolver, java.util.Map objectModel, java.lang.String source, org.apache.avalon.framework.parameters.Parameters parameters) throws ProcessingException, org.xml.sax.SAXException, java.io.IOException
org.apache.cocoon.acting.LocaleAction.getLocale()
to get language user has selected.
FIXME (KP): Why should I18nTransformer depend on an action?public void compose(org.apache.avalon.framework.component.ComponentManager manager)
compose
in interface org.apache.avalon.framework.component.Composable
public void startElement(java.lang.String uri, java.lang.String name, java.lang.String raw, org.xml.sax.Attributes attr) throws org.xml.sax.SAXException
AbstractXMLPipe
startElement
in class AbstractXMLPipe
org.apache.cocoon.xml.AbstractXMLPipe
uri
- The Namespace URI, or the empty string if the element has no
Namespace URI or if Namespace
processing is not being performed.loc
- The local name (without prefix), or the empty string if
Namespace processing is not being performed.raw
- The raw XML 1.0 name (with prefix), or the empty string if
raw names are not available.a
- The attributes attached to the element. If there are no
attributes, it shall be an empty Attributes object.public void endElement(java.lang.String uri, java.lang.String name, java.lang.String raw) throws org.xml.sax.SAXException
AbstractXMLPipe
endElement
in class AbstractXMLPipe
org.apache.cocoon.xml.AbstractXMLPipe
uri
- The Namespace URI, or the empty string if the element has no
Namespace URI or if Namespace
processing is not being performed.loc
- The local name (without prefix), or the empty string if
Namespace processing is not being performed.raw
- The raw XML 1.0 name (with prefix), or the empty string if
raw names are not available.public void characters(char[] ch, int start, int len) throws org.xml.sax.SAXException
AbstractXMLPipe
characters
in class AbstractXMLPipe
org.apache.cocoon.xml.AbstractXMLPipe
c
- The characters from the XML document.start
- The start position in the array.len
- The number of characters to read from the array.public void recycle()
AbstractXMLProducer
recycle
in class AbstractXMLProducer
public void dispose()
dispose
in interface org.apache.avalon.framework.activity.Disposable
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |