Transifex for your Django projects

· i18n

I am assuming you already created a project on Transifex (in this example is TxProject), either on the hosted version or on the downloadable version, and all the users you need are on there (just one to start is enough). I am also assuming i18n is already setup and you have at least 2 languages already in your project.

The aim of integrating Transifex libraries into your code is to make it really easy to push/pull translations of a project to their web front-end.

pip install transifex-client

First thing is to install their python client, make things much easier instead of manually uploading PO files.

user@host:/workspace/project$ tx init

This creates a .tx folder in your project root to store all tx configuration. You should include this in the repository.

Now suppose you have multiple apps in your django project. For each of those, you should have a locale/ folder inside it with all the application PO files. You need to generate a source language PO file before linking to transifex.

user@host:/workspace/project/apps/main$ ../../ makemessages -l en

user@host:/workspace/project$ tx set –auto-local -r TxProject.main ‘apps/main/locale//LC_MESSAGES/django.po’ –source-lang en –source-file apps/main/locale/en/LC_MESSAGES/django.po -t PO

Repeat the last command for every app you have in your project, changing the resource name (-r option) in TxProject.APPNAME. Next step is to push all your PO files to transifex.

user@host:/workspace/project$ tx push -s -t

After the translations have been done on Transifex, you can pull them into your project by typing.

user@host:/workspace/project$ tx pull

All very nice and easy!

Vote on Hacker News