Slide 1

Slide 1 text

Writing multi-language Documentation using Sphinx Markus Zapke-Gründemann Write The Docs Europe 2014

Slide 2

Slide 2 text

Markus Zapke-Gründemann Software Developer since 2001 Python, Django, Open Data and Training Independent since 2008 Owner of transcode keimlink.de // @keimlink

Slide 3

Slide 3 text

Basics

Slide 4

Slide 4 text

Sphinx Python Documentation Generator Markup Language: reStructuredText Output Formats: HTML, LaTeX (PDF), ePub, Texinfo, manual pages, plain text sphinx-doc.org

Slide 5

Slide 5 text

Internationalization Often referred to as i18n Translating into other languages without changing the code GNU gettext is used frequently

Slide 6

Slide 6 text

gettext Example import gettext t = gettext.translation('example', 'locale', fallback=True) _ = t.ugettext print _('Write the Docs')

Slide 7

Slide 7 text

Sphinx Internationalization

Slide 8

Slide 8 text

Sphinx i18n Workflow Source: http://sphinx-doc.org/intl.html

Slide 9

Slide 9 text

Sphinx i18n Configuration docs/conf.py language = 'en' locale_dirs = ['locale/'] # New in version 1.1 gettext_compact = True

Slide 10

Slide 10 text

Sphinx i18n Process $ make gettext $ msginit --no-translator -l de_DE \ -i _build/locale/setup.pot \ -o locale/de/LC_MESSAGES/setup.po # Translate documentation $ msgfmt --check-format \ -D locale/de/LC_MESSAGES setup.po \ -o locale/de/LC_MESSAGES/setup.mo $ make SPHINXOPTS="-Dlanguage=de" html

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

sphinx-intl $ pip install sphinx-intl https://pypi.python.org/pypi/sphinx-intl

Slide 13

Slide 13 text

sphinx-intl $ make gettext $ sphinx-intl update -l de -p _build/locale # Translate documentation $ sphinx-intl build $ make SPHINXOPTS="-Dlanguage=de" html

Slide 14

Slide 14 text

Transifex

Slide 15

Slide 15 text

www.transifex.com

Slide 16

Slide 16 text

Transifex Setup $ pip install transifex-client $ tx init --user= --pass=

Slide 17

Slide 17 text

Transifex and sphinx-intl $ sphinx-intl update-txconfig-resources \ --pot-dir _build/locale \ --transifex-project-name $ tx push -s # Translate documentation on Transifex $ tx pull -l de $ sphinx-intl build $ make SPHINXOPTS="-Dlanguage=de" html

Slide 18

Slide 18 text

Handy tips for translating Sphinx documentation

Slide 19

Slide 19 text

Using code inside the documentation All text inside the code should be English: ! class Bookmark(models.Model): url = models.URLField() title = models.CharField('title', max_length=255) description = models.TextField('description', blank=True)

Slide 20

Slide 20 text

How to handle URLs Always use the inline syntax: ! Alternatively, you can get the `Python Sources `_ from the website and compile it yourself. ! Because this way the URL will get lost: ! Alternatively, you can get the `Python Sources`_ from the website and compile it yourself. ! .. _Python Sources: http://python.org/download/

Slide 21

Slide 21 text

How to maintain versoined URLs You can use the extlinks extension to define URLs in the configuration: ! extlinks = { 'djangodocs': ('https://docs.djangoproject.com/en/1.5/%s', None), 'djangopdf': ('http://media.readthedocs.org/pdf/django/1.5.x/django.pdf%s', None) } ! You can find a list of all ``QuerySet`` methods in the :djangodocs:`documentation `. ! Download the :djangopdf:`Django Offline PDF Documentation <>` which has currently more than 1,200 pages.

Slide 22

Slide 22 text

How to handle special cases ifconfig can be used to handle special cases: ! .. ifconfig:: language == 'de' ! Nützliche Links für deutschsprachige Django-Nutzer: ! - `Deutschsprachige Django-Community `_

Slide 23

Slide 23 text

Link checking You can check the links for each language separately: ! $ make SPHINXOPTS="-Dlanguage=de" linkcheck

Slide 24

Slide 24 text

What is still missing? It’s not possible to build all languages at once A way to add a „landing page“ A translations setting Use gettext_compact to create a single catalog A language switch template

Slide 25

Slide 25 text

Sphinx 1.3 Merge sphinx-intl into Sphinx Move Transifex support from sphinx-intl to a new extension Allow to build all languages with a single command

Slide 26

Slide 26 text

Thanks! ! www.transcode.de @keimlink