In this article I will explain how to create a Plone 3 theme basic skeleton and then, create i18n translation files to use them in our templates, in the Zope 3 way.
First step is to create the theme in the ZopeSkel way:
paster create -t plone3_theme plonetheme.yourtheme
Now, assuming that you already know how to create the Plone templates, let’s make the basic folder structure for i18n translation files, for example, we are gonna create English and Catalan translation for our template.
Edit the main configure.zcml file and add this line:
<i18n:registerTranslations directory=”locales”/>
By doing this, you are indication Plone to search translations inside locales folder, so now lets create the folders structure necessary for our .po/.mo files.
Inside /locales, we need a folder containing the code of every language we want to create translations for, and inside them the LC_MESSAGES containing .po/.mo
/plonetheme.yourtheme
/plonetheme.yourtheme/locales/plonetheme.yourtheme.pot
/plonetheme.yourtheme/locales/en/LC_MESSAGES/plonetheme.yourtheme.po
/plonetheme.yourtheme/locales/es/LC_MESSAGES/plonetheme.yourtheme.po
Now we need to manually compile the .po files into .mo, because doing the translations in this way, Zope does not compile .po files in startup, so now, using msgfmt…
msgfmt -o plonetheme.yourtheme.mo plonetheme.yourtheme.po
msgfmt -o plonetheme.yourtheme.mo plonetheme.yourtheme.po
Plone will find now the translations and we can use them in our templates, to do that, we have to indicate the correct i18n domain in templates
<div i18n:domain=”plonetheme.yourtheme”>
That’s all! it works, seriously :)