Transifex CLI and xgettext mini how-to

DEPRECATED

A merge between this page and pre-existing documentation under git repository is in progress. https://github.com/DAViCal/davical/tree/master/docs/translation.rst

DAViCal: working with Transifex

Transifex provides a CLI tool to synchronize translations from the web. It's called tx.

Installation
Some Linux distros provide a transifex-client package, but it's usually an outdated version. For instance, Ubuntu 12.04 repos offer transifex-client v0.6, but the latest release of transifex client is 0.10.

Installing the latest version of transifex client can be done with pip:

# pip install transifex-client

If you want to upgrade, just run:

# pip install --upgrade transifex-client

Client configuration
Set up your Transifex account details at ~/.transifexrc :

 hostname = https://www.transifex.com password =  token = username = 

Make sure you give it 0600 permissions.

Project configuration
Transifex client will know how to synchronize DAViCal translations by reading the .tx/config file inside the project root directory.

These are the contents of the file:

[main] host = https://www.transifex.com

[davical.messagespot] file_filter = po/ .po   source_file = po/messages.pot source_lang = en   type = PO

Pulling translations from the web
tx supports downloading latest translations from Transifex for every registered language:

$ tx pull -a New translations found for the following languages: ca, ko_KR, id_ID, cs_CZ, ar, sk_SK, fi   Pulling translations for resource davical.messagespot (source: po/messages.pot) -> fr: po/fr.po   -> pt_BR: po/pt_BR.po    -> pt_PT: po/pt_PT.po    -> de: po/de.po    -> it: po/it.po    -> hu: po/hu.po    -> et: po/et.po    -> es_MX: po/es_MX.po    -> ja: po/ja.po    -> ru: po/ru.po    -> nl: po/nl.po    -> es_VE: po/es_VE.po    -> sv: po/sv.po    -> es_AR: po/es_AR.po    -> es_ES: po/es_ES.po    -> nb_NO: po/nb_NO.po    -> pl: po/pl.po    Pulling new translations for resource davical.messagespot (source: po/messages.pot) -> ca: po/ca.po   -> ko_KR: po/ko_KR.po    -> id_ID: po/id_ID.po    -> cs_CZ: po/cs_CZ.po    -> ar: po/ar.po    -> sk_SK: po/sk_SK.po    -> fi: po/fi.po    Done.

Extracting English strings (messages.pot)
As DAViCal uses gettext translation files, the tool to extract base strings (in English) from its source code is gettext.

DAViCal uses a custom function called `translate` instead of the default `_`, so our xgettext call needs some additional parameters:

$ xgettext -o po/messages.pot -L php -j --keyword=translate $(find htdocs inc scripts -name '*.php')

This generates a new po/messages.pot, merging (-j) with existing strings.

Uploading English strings to Transifex
To upload a new messages.pot to Transifex the tx client can be used as follows:

$ tx push -s

The '-s' switch tells tx to upload the source files.