# Internationalization¶

New in version 1.1.

Complementary to translations provided for Sphinx-generated messages such as navigation bars, Sphinx provides mechanisms facilitating document translations in itself. See the Options for internationalization for details on configuration.

## Sphinx internationalization details¶

gettext [1] is an established standard for internationalization and localization. It naively maps messages in a program to a translated string. Sphinx uses these facilities to translate whole documents.

Initially project maintainers have to collect all translatable strings (also referred to as messages) to make them known to translators. Sphinx extracts these through invocation of sphinx-build -b gettext.

Every single element in the doctree will end up in a single message which results in lists being equally split into different chunks while large paragraphs will remain as coarsely-grained as they were in the original document. This grants seamless document updates while still providing a little bit of context for translators in free-text passages. It is the maintainer’s task to split up paragraphs which are too large as there is no sane automated way to do that.

After Sphinx successfully ran the MessageCatalogBuilder you will find a collection of .pot files in your output directory. These are catalog templates and contain messages in your original language only.

They can be delivered to translators which will transform them to .po files — so called message catalogs — containing a mapping from the original messages to foreign-language strings.

Gettext compiles them into a binary format known as binary catalogs through msgfmt for efficiency reasons. If you make these files discoverable with locale_dirs for your language, Sphinx will pick them up automatically.

An example: you have a document usage.rst in your Sphinx project. The gettext builder will put its messages into usage.pot. Imagine you have Spanish translations [2] on your hands in usage.po — for your builds to be translated you need to follow these instructions:

• Compile your message catalog to a locale directory, say locale, so it ends up in ./locale/es/LC_MESSAGES/usage.mo in your source directory (where es is the language code for Spanish.)

msgfmt "usage.po" -o "locale/es/LC_MESSAGES/usage.mo"

• Set locale_dirs to ["locale/"].

• Set language to es (also possible via -D).

## Translating with sphinx-intl¶

### Quick guide¶

sphinx-intl is a useful tool to work with Sphinx translation flow. This section describe an easy way to translate with sphinx-intl.

1. Install sphinx-intl by pip install sphinx-intl or easy_install sphinx-intl.

locale_dirs = ['locale/']   # path is example but recommended.
gettext_compact = False     # optional.


This case-study assumes that locale_dirs is set to ‘locale/’ and gettext_compact is set to False (the Sphinx document is already configured as such).

3. Extract document’s translatable messages into pot files:

$make gettext  As a result, many pot files are generated under _build/gettext directory. 4. Setup/Update your locale_dir: $ sphinx-intl update -p _build/gettext -l de -l ja


Done. You got these directories that contain po files:

• ./locale/de/LC_MESSAGES/
• ./locale/ja/LC_MESSAGES/
5. Translate your po files under ./locale/<lang>/LC_MESSAGES/.

6. make translated document.

You need a language parameter in conf.py or you may also specify the parameter on the command line (for BSD/GNU make):



## Using Transifex service for team translation¶

Transifex is one of several services that allow collaborative translation via a web interface. It has a nifty Python-based command line client that makes it easy to fetch and push translations.

1. Install transifex-client

You need tx command to upload resources (pot files).

$pip install transifex-client  2. Create your transifex account and create new project for your document Currently, transifex does not allow for a translation project to have more than one version of the document, so you’d better include a version number in your project name. For example: Project ID: sphinx-document-test_1_0 https://www.transifex.com/projects/p/sphinx-document-test_1_0/ 3. Create config files for tx command This process will create .tx/config in the current directory, as well as a ~/.transifexrc file that includes auth information. $ tx init
Creating .tx folder...
Transifex instance [https://www.transifex.com]:
...
...
Done.

4. Upload pot files to transifex service

Register pot files to .tx/config file:

$cd /your/document/root$ sphinx-intl update-txconfig-resources --pot-dir _build/locale \
--transifex-project-name sphinx-document-test_1_0


$tx push -s Pushing translations for resource sphinx-document-test_1_0.builders: Pushing source file (locale/pot/builders.pot) Resource does not exist. Creating... ... Done.  5. Forward the translation on transifex 6. Pull translated po files and make translated html Get translated catalogs and build mo files (ex. for ‘de’): $ cd /your/document/root
$tx pull -l de Pulling translations for resource sphinx-document-test_1_0.builders (...) -> de: locale/de/LC_MESSAGES/builders.po ... Done.  Invoke make html (for BSD/GNU make): $ make -e SPHINXOPTS="-D language='de'" html


That’s all!

Tip

Translating locally and on Transifex

If you want to push all language’s po files, you can be done by using tx push -t command. Watch out! This operation overwrites translations in transifex.

In other words, if you have updated each in the service and local po files, it would take much time and effort to integrate them.

## Contributing to Sphinx reference translation¶

The recommended way for new contributors to translate Sphinx reference is to join the translation team on Transifex.

There is sphinx translation page for Sphinx (master) documentation.

3. Click Request language and fill form.