Log in

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:

  1. Extract all translations. Here we pass two directories to be scanned: the templates dir and the apps dir. This will create a messages.pot file in the /app/locale directory with all strings found in these directories:
    $ bin/pybabel extract -F ./babel.cfg -o ./app/locale/messages.pot ./app/templates/ ./app/apps
      
    
  2. To add a new translation, initialize its directory. This is done only once per translation. It will use the messages.pot file created on step 1. Here we initialize three translations, en_US, es_ES and pt_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 
      
    
  3. Now the translation catalogs are created in /app/locale/. Open each .po file and translate them (for example, /app/locale/en_US/LC_MESSAGES/messages.po).
  4. 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

Powered by Moe. Yeah, the name is Moe. Powered by Google App Engine