A document has been updated:
http://cocoon.zones.apache.org/daisy/legacydocs/463.html
Document ID: 463
Branch: main
Language: default
Name: I18n Transformer (unchanged)
Document Type: Document (unchanged)
Updated on: 10/4/05 2:05:35 PM
Updated by: Helma van der Linden
A new version has been created, state: publish
Parts
=====
Content
-------
This part has been updated.
Mime type: text/xml (unchanged)
File name: (unchanged)
Size: 20672 bytes (previous version: 20640 bytes)
Content diff:
(16 equal lines skipped)
<p>This approach for internationalization (further - i18n) of XML documents
within Cocoon is based on a transformer -
--- <a href="apidocs/org/apache/cocoon/transformation/I18nTransformer.html">
+++ <a
href="http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/transformation/I18nTransformer.html">
<tt>I18nTransformer</tt> </a> , which uses XML dictionaries for all the
multilingual data. The namespace URI of i18n transformer is defined as
follows:
</p>
(22 equal lines skipped)
<p>A simple example of i18n markup:</p>
--- <pre>
--- <para title="first" name="article" i18n:attr="title name">
+++ <pre><para title="first" name="article" i18n:attr="title name">
<i18n:text>This text will be translated.</i18n:text>
</para></pre>
(16 equal lines skipped)
<p>Tags list</p>
<table>
+++ <tbody>
<tr>
<th>
<p>Element</p>
(51 equal lines skipped)
<p>Formats numbers, currencies and percent in localized manner</p>
</td>
</tr>
+++ </tbody>
</table>
<h2 id="i18n_text">i18n:text</h2>
<p>To translate some simple text we use the <tt><i18n:text></tt>
tag:</p>
--- <pre>
--- <i18n:text>Text to be translated</i18n:text></pre>
+++ <pre><i18n:text>Text to be translated</i18n:text></pre>
<p>The text between the <tt><i18n:text></tt>-tags is used as a key to
find
the translation in the dictionary.</p>
(4 equal lines skipped)
find the translation and the text itself is used as the default value, if no
translation can be found.</p>
--- <pre>
--- <i18n:text i18n:key="key_text">Default value</i18n:text></pre>
+++ <pre><i18n:text i18n:key="key_text">Default
value</i18n:text></pre>
<p>Messages can be taken from multiple dictionaries. The dictionaries are
configured in the sitemap (see further on), and each dictionary is assigned
an
id. There is one dictionary that serves as the default one. To translate a
key
using a non-default dictionary, mention the id of the dictionary in an
i18n:catalogue attribute:</p>
--- <pre>
--- <i18n:text i18n:catalogue="menu">key_text</i18n:text></pre>
+++ <pre><i18n:text i18n:catalogue="menu">key_text</i18n:text></pre>
<h2 id="i18n_translate">Translation with param substitution</h2>
(29 equal lines skipped)
can simply be done by marking up the parameters with
<tt><i18n:text></tt>
again:</p>
--- <pre>
--- <i18n:translate>
+++ <pre><i18n:translate>
<i18n:text>Some {0} was inserted {1}.</i18n:text>
<i18n:param><i18n:text>text</i18n:text></i18n:param>
<i18n:param><i18n:text>here</i18n:text></i18n:param>
(17 equal lines skipped)
list of attributes, which should be translated, separated by spaces. An
example:
</p>
--- <pre>
--- <INPUT type="submit" value="Submit" i18n:attr="value"/></pre>
+++ <pre><INPUT type="submit" value="Submit" i18n:attr="value"/></pre>
<p>The attribute, which will be translated is 'value'. Parameter
replacement is
not available for attributes at this time.</p>
(7 equal lines skipped)
multiple dictionaries. To use a specific dictionary, add the id of the
dictionary before the key, separated by a colon:</p>
--- <pre>
--- <INPUT type="submit" value="form:Submit" i18n:attr="value"/></pre>
+++ <pre><INPUT type="submit" value="form:Submit"
i18n:attr="value"/></pre>
<h2 id="i18n_date">Date, time and number formatting</h2>
(60 equal lines skipped)
<tt>type</tt> attribute must be used with params to indicate the param type
(date, number, currency, ...). Default type is <tt>string</tt>.</p>
--- <pre>
--- <i18n:translate>
+++ <pre><i18n:translate>
<i18n:text>
You have to pay {0} for {1} pounds or {2} of your profit. Valid from {3}
</i18n:text>
(17 equal lines skipped)
<p>A single message catalogue file contains translations for a particular
language, e.g.:</p>
--- <pre>
--- <?xml version="1.0"?>
+++ <pre><?xml version="1.0"?>
<!-- message catalogue file for locale ... -->
<catalogue xml:lang="locale">
<message key="key">text</message>
(40 equal lines skipped)
<h2>Sitemap configuration</h2>
--- <pre>
--- <map:transformer name="i18n"
+++ <pre><map:transformer name="i18n"
src="org.apache.cocoon.transformation.I18nTransformer">
<catalogues default="messages">
(34 equal lines skipped)
<p>To use the transformer in a pipeline, simply specify it in a particular
transform and indicate the needed locale. eg:</p>
--- <pre>
--- <map:match pattern="file">
+++ <pre><map:match pattern="file">
<map:generate src="file.xml"/>
<map:transform type="i18n">
<map:parameter name="locale" value="en_AU"/>
(56 equal lines skipped)
<p>Command line for Xalan (Of course, Xerces and Xalan must be in your
classpath):</p>
--- <pre>
--- java org.apache.xalan.xslt.Process -IN simple_dict.xml -XSL merge.xsl \
+++ <pre>java org.apache.xalan.xslt.Process -IN simple_dict.xml -XSL merge.xsl \
-OUT simple_dict_es.xml -PARAM mode keys -PARAM new-lang es -PARAM
keep-lang en
</pre>
(12 equal lines skipped)
<p>Use the same stylesheet for this purpose with this params:</p>
--- <pre>
--- mode = merge
+++ <pre>mode = merge
new-lang = es
new-dict = simple_dict_es.xml
</pre>
<p>Command line for Xalan:</p>
--- <pre>
--- java org.apache.xalan.xslt.Process -IN simple_dict.xml -XSL merge.xsl \
+++ <pre>java org.apache.xalan.xslt.Process -IN simple_dict.xml -XSL merge.xsl \
-OUT simple_dict_new.xml -PARAM mode merge -PARAM new-lang es \
-PARAM new-dict simple_dict_es.xml
</pre>
(27 equal lines skipped)
Fields
======
no changes
Links
=====
no changes
Custom Fields
=============
no changes
Collections
===========
no changes