This document discusses using Sphinx to generate documentation in multiple languages. It introduces Sphinx and the Sphinx-intl extension for internationalization. The workflow involves configuring Sphinx with locale directories and languages, generating POT files with sphinx-intl, translating strings externally with Transifex or by building PO files, and building the documentation for different languages by setting the language variable. It provides tips for translating like handling code snippets, URLs, and special cases using directives like ifconfig.
6. gettext Example
import gettext
t = gettext.translation('example', 'locale', fallback=True)
_ = t.gettext
print(_('Always look on the bright side of life'))
7. Why use gettext for
translated documentation?
Untranslated strings are displayed in the
source language
Markup is not duplicated
Professional translation tools can be used
Contributions possible without using a VCS
18. Using code inside
the documentation
All text inside the code should be English:
!
{% extends "marcador/bookmark_list.html" %}
!
{% block title %}{{ owner.username }}'s bookmarks{% endblock %}
!
{% block heading %}
<h2>{{ owner.username }}'s bookmarks<br>
<small>{{ bookmarks.count }} bookmarks in total</small>
</h2>
{% endblock %}
19. How to handle URLs
Always use the inline syntax:
!
Alternatively, you can get the `Python Sources <http://python.org/
download/>`_ 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/
20. 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 <ref/
models/querysets/#queryset-api>`.
!
Download the :djangopdf:`Django Offline PDF Documentation <>` which has currently more
than 1,200 pages.
21. 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 <http://django-de.org/>`_
22. Link checking
You can check the links for each language separately:
!
$ make SPHINXOPTS="-Dlanguage=de" linkcheck
23. What is still missing?
A translations setting to build all languages
with a single command
A way to add a „landing page“
Use gettext_compact to create a single catalog
Collect all indices into a single .po file
A language switch template