I18N (Internationalization) of static webpages with TAL (Template Attribute Language) and Perl


Preparing your code

First you have to convert/write your code as XHTML. This means:

Now you can add the additional attribute to your code. The attribute is named i18n:translate and its value can be a key or empty (then the string is the id). Here is an example how it should look like:

<span i18n:translate="">Welcome here</span>

Attention: If text which should be translated contains other tags you will get a reference instead of the tag. You have to add a own i18n:translate attribute for the tag.

Preparing directory structure

  1. create a directory named locale. It holds the untranslated translation template and contains the message catalogs of each language in own directory.
  2. create for each language the directory where the message catalog will be stored: <language code>>/LC_MESSAGES (for example: de_DE/LC_MESSAGES)

String extraction

After writing your code its time to extract all strings from your code. Go into the locale directory and run the following command:

i18nfool-extract ../*.html
msginit -i default.pot --no-translator -l "UTF-8" -o default.pot

This will create a file named messages.pot which holds the strings of your pages. This file you should give the translators which can edit it with special tools for translating like KBabel or PoEdit. If you got it back save the translated file in the corresponding language directory. After that you have to compile the translations. Now the pages ready for release.

Updating message catalogs

For updating the translations run:


in the locale directory.

Compiling translations

For compiling the translations run:


This will create .mo files in then language directories.

Creating the localized HTML files

First adjust output path and languages in the script (create_localized_html.sh)

Now you have to run the following command:


This transforms the html files using the translation files using create_localized_html.pl. The publishing directory will be filled with english (without translation) and localized files. The localized files will be put in a subdirectory named the language code (e.g. de_DE for German).


This text is distributed under the terms of the GNU Free Documentation License (FDL). Free pubilishing in modified or not modified form are permitted. Modifications have to marked and have to distributed under the FDL too.

&copy; 2005 Christoph Thielecke <crissi99_TA_gmx_PT_de>