The goal

With a plone site you can do a lot of localization using the linguaPlone product. This is a great tool even if it still has some problems with the localization of folder default pages (folders which have a page as custom view). But in a custom skin there are also elements which need some localization. In my case it was the left side portlet which needed romanian and english localization.

Your product skin structure

In order to add localization to your plone product first you have to add an i18n directory to the product root. Don’t worry you will not need to change the config.py script.

...Theme$ ls<br></br>config.py   Extensions   __init__.py   README.txt   tests<br></br>config.pyc  HISTORY.txt  __init__.pyc  refresh.txt  version.txt<br></br>CVS         i18n         LICENSE.txt   skins

Localization of your template

You can then use the i18n:… tags as described in the plone book internationalization section

<html><br></br>  <body i18n:domain="solis"><br></br><div metal:define-macro="portlet"><br></br>    <div class="prezentarePortlet" i18n:translate="prezentare_string"><br></br>      Schedule a free presentation for SOLIS<br></br>    </div><br></br></div>  <br></br></body><br></br></html><br></br><br></br>

There are 2 elements here:

  • i18n:domain=”solis” which represent a localization domain which is in fact a translation group of files. By default plone uses the “plone” domain but this means you whould have to modify the ./PloneTranslations/i18n/plone_xx.po files which is not nice as your product must be self contained. As such I defined a domain specially for this product. This will correspond to a solis.pot and some solis_xx.po files in the created i18n directory.
  • the i18n:translate=”prezentare_string” defines a translation key or id. If the translation key is found in the solis domain it will be used to replace the div content.

The localization tool

You can create the files localization files by hand or you can use the i18ndude tool. You can download the tool from the plone site as an .egg package. On debian based distros you can install the egg with these commands:

#install the easy_install tools<br></br>apt-get install python-setuptools<br></br>#install the egg<br></br>easy_install i18ndude-2.1.1-py2.4.egg<br></br>

Then you can create the localization file with a command similar to

i18ndude rebuild-pot --pot solis.pot --create solis ../skins/solistheme_templates/prezentarePortlet.pt<br></br>

The localization files

Now all you need is to copy the solis.pot to the solis_xx.po file according to your localization and modify the entries inside (including the header). xx is of course your locale short code (en and ro in my case).
The file format is very simple, key (msgid) and value (msgstr) separated on different lines:

msgid "prezentare_string"<br></br>msgstr "this is the text"<br></br>

Verification

If everything was ok you should see your translation files after restart in the zope Control Panel > Translation manager page and you should see the template change according to the linguaPlone language along with your other content.