I18n

Internationalisation (i18n) aka translation services

We "ported" most of the cocoon i18n transformer to popoon. See http://cocoon.apache.org/2.1/userdocs/i18nTransformer.html for some introduction.

If it's not already in the sitemap, you should add the following directives to your sitemap

<map:transform type="i18n" src="xml/catalog">
     <map:parameter name="locale" value="{lang}"/>
     <map:parameter name="driver" value="xml"/>
  </map:transform>

The catalog xml file with the translations then go into "xml/catalog_$lang.xml"

How to actually use the i18n feature in your XML/XSLT files is quite well described on the cocoon page (i18n:translate isn't integrated yet, but the rest should be)

You can also interface with the i18n classes directly from within PHP

$i18n = popoon_classes_i18n::getDriverInstance($srcfile, $GLOBALS['POOL']->config->getOutputLocale());
 $translated_key = $i18n->getText($key);

You can use i18n:attr to translate attributes.

ex1: <input type="submit" value="FormContinue" i18n:attr="value"/>  
(value will get i18n text from FormContinue)
ex2: ... <xsl:attribute name="i18n:attr">value</xsl:attribute> ...  
(name will get i18n text from value)

How to get all my i18n keys from a website?

How to get all my i18n keys from a website?

Get i18n in JavaScript

First, add the attribute 'ref="js"' to every key you want to use in javascript, like:

<message ref="js" key="Related Entries">Ähnliche Beiträge</message>

Then, add the following line somewhere to <head> in the xslt file you need that (master.xsl, if it's general)

<script  type="text/javascript" src="{$webroot}/inc/bx/php/i18njs.php?lang={$lang}"></script>

In the global Javascript array i18n you have now all the keys marked with _ref="js", eg.

var RelatedEntriesText = i18n['Related Entries']

Other example with JS

<head>	
<script type="text/javascript">
       EN = "<i18n:text>EN</i18n:text>";
       DE = "<i18n:text>DE</i18n:text>";
</script>
</head>

<a onclick="document.getElementById('langtitle').innerHTML = EN;" href="#"><i18n:text>EN</i18n:text></a>

<h2 id="langtitle"></h2>
Improvable script

The script in inc/bx/php/i18njs.php is far from beautiful, improvements are welcome, eg. sending correct cache headers so that it won't be fetched everytime

Labels:

Enter labels to add to this page:
Wait Image 
Looking for a label? Just start typing.
These projects are supported by Liip AG