Skip to content

Commit a59c87f

Browse files
authored
Merge pull request #4470 from rtfd/humitos/docs/translations
Documentation for Manage Translations
2 parents 156e76e + 30474ca commit a59c87f

File tree

3 files changed

+240
-1
lines changed

3 files changed

+240
-1
lines changed

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
default_role = 'obj'
4747
intersphinx_mapping = {
4848
'python': ('http://python.readthedocs.io/en/latest/', None),
49-
'django': ('http://django.readthedocs.io/en/1.8.x/', None),
49+
'django': ('http://django.readthedocs.io/en/1.9.x/', None),
5050
'sphinx': ('http://sphinx.readthedocs.io/en/latest/', None),
5151
}
5252
htmlhelp_basename = 'ReadTheDocsdoc'

docs/guides/manage-translations.rst

+236
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
Manage Translations
2+
===================
3+
4+
This guide walks through the process needed to manage translations of your documentation.
5+
Once this work is done, you can setup your project under Read the Docs to build each language of your documentation by reading :doc:`/localization`.
6+
7+
Overview
8+
--------
9+
10+
There are many different ways to manage documentation in multiple languages by using different tools or services.
11+
All of them have their pros and cons depending on the context of your project or organization.
12+
13+
In this guide we will focus our efforts around two different methods: manual and using Transifex_.
14+
15+
In both methods, we need to follow these steps to translate our documentation:
16+
17+
#. Create translatable files (``.pot`` and ``.po`` extensions) from source language
18+
#. Translate the text on those files from source language to target language
19+
#. Build the documentation in *target language* using the translated texts
20+
21+
Besides these steps, once we have published our first translated version of our documentation,
22+
we will want to keep it updated from the source language. At that time, the workflow would be:
23+
24+
#. Update our translatable files from source language
25+
#. Translate only *new* and *modified* texts in source language into target language
26+
#. Build the documentation using the most up to date translations
27+
28+
29+
Create translatable files
30+
-------------------------
31+
32+
To generate these ``.pot`` files it's needed to run this command from your ``docs/`` directory:
33+
34+
.. code-block:: console
35+
36+
$ sphinx-build -b gettext . _build/gettext
37+
38+
39+
.. tip::
40+
41+
We recommend configuring Sphinx to use :ref:`gettext_uuid <sphinx:gettext_uuid>` as ``True``
42+
and also :ref:`gettext_compact <sphinx:gettext_compact>` as ``False`` to generate ``.pot`` files.
43+
44+
45+
This command will leave the generated files under ``_build/gettext``.
46+
47+
48+
Translate text from source language
49+
-----------------------------------
50+
51+
Manually
52+
~~~~~~~~
53+
54+
We recommend using `sphinx-intl`_ tool for this workflow.
55+
56+
.. _sphinx-intl: https://pypi.org/project/sphinx-intl/
57+
58+
First, you need to install it:
59+
60+
.. code-block:: console
61+
62+
$ pip install sphinx-intl
63+
64+
65+
As a second step, we want to create a directory with each translated file per target language
66+
(in this example we are using Spanish/Argentina and Portuguese/Brazil).
67+
This can be achieved with the following command:
68+
69+
.. code-block:: console
70+
71+
$ sphinx-intl update -p _build/gettext -l es_AR -l pt_BR
72+
73+
This command will create a directory structure similar to the following
74+
(with one ``.po`` file per ``.rst`` file in your documentation)::
75+
76+
locale
77+
├── es_AR
78+
│ └── LC_MESSAGES
79+
│ └── index.po
80+
└── pt_BR
81+
└── LC_MESSAGES
82+
└── index.po
83+
84+
85+
Now, you can just open those ``.po`` files with a text editor and translate them taking care of no breaking the reST notation.
86+
Example:
87+
88+
.. code-block:: po
89+
90+
# b8f891b8443f4a45994c9c0a6bec14c3
91+
#: ../../index.rst:4
92+
msgid ""
93+
"Read the Docs hosts documentation for the open source community."
94+
"It supports :ref:`Sphinx <sphinx>` docs written with reStructuredText."
95+
msgstr ""
96+
"FILL HERE BY TARGET LANGUAGE FILL HERE BY TARGET LANGUAGE FILL HERE "
97+
"BY TARGET LANGUAGE :ref:`Sphinx <sphinx>` FILL HERE."
98+
99+
100+
Using Transifex
101+
~~~~~~~~~~~~~~~
102+
103+
Transifex_ is a platform that simplifies the manipulation of ``.po`` files and offers many useful features to make the translation process as smooth as possible.
104+
These features includes a great web based UI, `Translation Memory`_, collaborative translation, etc.
105+
106+
.. _Transifex: https://www.transifex.com/
107+
.. _Translation Memory: https://docs.transifex.com/setup/translation-memory
108+
109+
You need to create an account in their service and a new project before start.
110+
111+
After that, you need to install the `transifex-client`_ tool which will help you in the process to upload source files, update them and also download translated files.
112+
To do this, run this command:
113+
114+
.. _transifex-client: https://docs.transifex.com/client/introduction
115+
116+
.. code-block:: console
117+
118+
$ pip install transifex-client
119+
120+
After installing it, you need to configure your account.
121+
For this, you need to create an API Token for your user to access this service through the command line.
122+
This can be done under your `User's Settings`_.
123+
124+
.. _User's Settings: https://www.transifex.com/user/settings/api/
125+
126+
127+
Now, you need to setup it to use this token:
128+
129+
.. code-block:: console
130+
131+
$ tx init --token $TOKEN --no-interactive
132+
133+
134+
The next step is to map every ``.pot`` file you have created in the previous step to a resource under Transifex.
135+
To achieve this, you need to run this command:
136+
137+
.. code-block:: console
138+
139+
$ tx config mapping-bulk \
140+
--project $TRANSIFEX_PROJECT \
141+
--file-extension '.pot' \
142+
--source-file-dir docs/_build/gettext \
143+
--source-lang en \
144+
--type PO \
145+
--expression 'locale/<lang>/LC_MESSAGES/{filepath}/{filename}.po' \
146+
--execute
147+
148+
This command will generate a file at ``.tx/config`` with all the information needed by the ``transifext-client`` tool to keep your translation synchronized.
149+
150+
Finally, you need to upload these files to Transifex platform so translators can start their work.
151+
To do this, you can run this command:
152+
153+
.. code-block:: console
154+
155+
$ tx push --source
156+
157+
158+
Now, you can go to your Transifex's project and check that there is one resource per ``.rst`` file of your documentation.
159+
After the source files are translated using Transifex, you can download all the translations for all the languages by running:
160+
161+
.. code-block:: console
162+
163+
$ tx pull --all
164+
165+
This command will leave the ``.po`` files needed for building the documentation in the target language under ``locale/<lang>/LC_MESSAGES``.
166+
167+
.. warning::
168+
169+
It's important to use always the same method to translate the documentation and do not mix them.
170+
Otherwise, it's very easy to end up with inconsistent translations or loosing already translated text.
171+
172+
173+
Build the documentation in target language
174+
------------------------------------------
175+
176+
177+
Finally, to build our documentation in Spanish(Argentina) we need to tell Sphinx builder the target language with the following command:
178+
179+
.. code-block:: console
180+
181+
$ sphinx-build -b html -D language=es_AR . _build/html/es_AR
182+
183+
.. note::
184+
185+
There is no need to create a new ``conf.py`` to redefine the ``language`` for the Spanish version of this documentation.
186+
187+
After running this command, the Spanish(Argentina) version of your documentation will be under ``_build/html/es_AR``.
188+
189+
190+
Summary
191+
-------
192+
193+
Update sources to be translated
194+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
195+
196+
Once you have done changes in your documentation, you may want to make these additions/modifications available for translators so they can update it:
197+
198+
#. Create the ``.pot`` files:
199+
200+
.. code-block:: console
201+
202+
$ sphinx-build -b gettext . _build/gettext
203+
204+
205+
.. For the manual workflow, we need to run this command
206+
207+
$ sphinx-intl update -p _build/gettext -l es_AR -l pt_BR
208+
209+
210+
#. Push new files to Transifex
211+
212+
.. code-block:: console
213+
214+
$ tx push --sources
215+
216+
217+
Build documentation from up to date translation
218+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
219+
220+
When translators have finished their job, you may want to update the documentation by pulling the changes from Transifex:
221+
222+
#. Pull up to date translations from Transifex:
223+
224+
.. code-block:: console
225+
226+
$ tx pull --all
227+
228+
#. Commit and push these changes to our repo
229+
230+
.. code-block:: console
231+
232+
$ git add locale/
233+
$ git commit -m "Update translations"
234+
$ git push
235+
236+
The last ``git push`` will trigger a build per translation defined as part of your project under Read the Docs and make it immediately available.

docs/localization.rst

+3
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,7 @@ It also gets included in the Read the Docs flyout:
5151
.. note:: The default language of any CNAME will be the language of the project the Domain object was set on. See :doc:`alternate_domains` for more information.
5252

5353
.. note:: You can include multiple translations in the same repository,
54+
with same ``conf.py`` and ``.rst`` files,
5455
but each project must specify the language to build for those docs.
56+
57+
.. note:: You can read :doc:`guides/manage-translations` to understand the whole process for a documentation with multiples languages in the same repository and how to keep the translations updated on time.

0 commit comments

Comments
 (0)