Internationalization ¶
Tipfy has a very complete set of tools to internationalize apps and offer different translations for the pages with localized date, time and numbers, and even more.
Extracting, compiling and updating translations¶
We use the babel command line interface to extract, initialize, compile and update translations. Refer to the manual for a complete description of the options.
The babel extract function can extract not only {% trans %} and {{ _() }}
tags from templates but also gettext() and its variants from .py files. Access
your project directory in the command line and follow this quick how-to:
- Extract all translations. Here we pass two directories to be scanned: the
templatesdir and theappsdir. This will create amessages.potfile in the/app/localedirectory with all strings found in these directories:$ bin/pybabel extract -F ./babel.cfg -o ./app/locale/messages.pot ./app/templates/ ./app/apps
- To add a new translation, initialize its directory. This is done only once per
translation. It will use the
messages.potfile created on step 1. Here we initialize three translations,en_US,es_ESandpt_BR:$ bin/pybabel init -l en_US -d ./app/locale -i ./app/locale/messages.pot $ bin/pybabel init -l es_ES -d ./app/locale -i ./app/locale/messages.pot $ bin/pybabel init -l pt_BR -d ./app/locale -i ./app/locale/messages.pot
- Now the translation catalogs are created in
/app/locale/. Open each.pofile and translate them (for example,/app/locale/en_US/LC_MESSAGES/messages.po). - After all locales are translated, compile them:
$ bin/pybabel compile -f -d ./app/locale
That's it. Later, if translations change, repeat step 1 and update them using the
new .pot file:
$ bin/pybabel update -l pt_BR -d ./app/locale/ -i ./app/locale/messages.pot
- Version: latest
- Edited by moraes on 5/17/10 9:23 PM
- Save on Delicious | Submit to Reddit
- History
- Edit
