Skip to content

Commit 9695c1d

Browse files
Updates to commands.rst (#126)
* Updates to commands.rst * Adittoanl typo * Versions in "Merging translations into another branch" * Manually updated versions
1 parent bb02496 commit 9695c1d

File tree

2 files changed

+107
-73
lines changed

2 files changed

+107
-73
lines changed

docs/commands.rst

Lines changed: 96 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,49 @@
1-
============================================
2-
Commands for maintaining language repository
3-
============================================
1+
==============================================
2+
Commands for maintaining a language repository
3+
==============================================
44

5-
This document contains instructions to guide you on managing your language repository, hence helping you to translate
6-
Python's documentation to your language.
5+
This document contains instructions to guide you on managing your language
6+
repository, hence helping you translate Python's documentation to your language.
77

8-
These commands are written as in Linux Shell, and should work in Windows Subsystem Linux (WSL), but feel free to use the
9-
same logic in other languages e.g. Python.
8+
These commands are written in Linux Shell, and should work in Windows Subsystem
9+
Linux (WSL), but feel free to use the same logic in other languages e.g. Python.
1010

11-
Note: Where you see ``${LANGCODE}`` in the commands below, replace it with your language code (e.g. 'uk', 'pt_BR') or
12-
set that variable (e.g. ``LANGCODE=pt_BR``) before running the commands.
11+
.. note::
12+
Where you see ``${LANGCODE}`` in the commands below, replace it with your
13+
language code (e.g. 'uk', 'pt_BR') or set the variable
14+
(e.g. ``LANGCODE=pt_BR``) before running the commands.
1315

1416

1517
Clone CPython repository
1618
------------------------
1719

18-
It is necessary to have a local clone of CPython's source code repository in order to update translation files and to
19-
build translated documentation.
20+
It is necessary to have a local clone of `CPython's source code repository <https://github.com/python/cpython>`_
21+
in order to update translation files and to build translated documentation.
2022

2123
From inside your language repository, run:
2224

2325
.. code-block:: shell
2426
25-
BRANCH=3.12
27+
BRANCH=|py_new|
2628
git clone --depth 1 https://github.com/python/cpython --branch $BRANCH
2729
28-
``--depth 1`` do a shallow clone, which avoid downloading all the 800 MB of data from CPython's repository.
30+
Use ``--depth 1`` to shallow clone, which avoids downloading all the 800 MB of data
31+
from CPython's repository.
2932

30-
Optionally, you could also add ``--no-single-branch`` to git clone command which would make all branches available,
31-
allowing to switch between one branch and another. But there is no need if you are working in the translation of a
32-
single branch.
33+
Optionally, you could also add ``--no-single-branch`` to ``git clone`` command which
34+
would make all branches available, allowing to switch between one branch and
35+
another. But this is not needed if you are working on the translation of a single branch.
3336

3437

3538
Install requirements
3639
--------------------
3740

38-
Creating virtual environment
39-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
41+
Creating a virtual environment
42+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4043

41-
Optionally, create a virtual environment (short: venv) to keep all Python package installations in it, then activate
42-
this venv to make sure commands are run from it:
44+
Optionally, create a `virtual environment <https://docs.python.org/3/library/venv.html>`_
45+
(short: *venv*) to keep all Python package installations in it, then activate
46+
this venv to ensure commands are run from it:
4347

4448
.. code-block:: shell
4549
@@ -49,14 +53,15 @@ this venv to make sure commands are run from it:
4953
Install Python packages
5054
^^^^^^^^^^^^^^^^^^^^^^^
5155

52-
Update pip and then install the Python requirements:
56+
Update pip and then install the required packages:
5357

5458
.. code-block:: shell
5559
5660
python -m pip install --upgrade pip
5761
python -m pip install sphinx-intl>=2.1.0 pomerge powrap sphinx-lint
5862
59-
Alternatively, put all Python packages inside a requirements.txt file and install it using pip's ``-r`` flag.
63+
Alternatively, put all Python packages inside a requirements.txt file and install
64+
it using pip's ``-r`` flag.
6065

6166
Transifex CLI tool
6267
^^^^^^^^^^^^^^^^^^
@@ -69,37 +74,42 @@ Install the Transifex CLI client, required to interact with Transifex:
6974
curl -s -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh
7075
cd ../..
7176
72-
Note: the above statements cause ``tx`` binary to be downloaded into .venv/bin directory. Feel free to install this
73-
tool wherever you want, but preferably in a directory already in the PATH so that issuing ``tx`` works without its
74-
full path.
75-
77+
.. note::
78+
The above commands result in the ``tx`` binary being downloaded into the ``.venv/bin`` directory.
79+
Feel free to install this tool wherever you want, but preferably in a
80+
directory already in the PATH so that ``tx`` works without its full path.
7681

7782
Updating the translations
7883
-------------------------
7984

80-
For language teams that coordinate translation efforts in Transifex, updating translation means pulling the translation
81-
strings.
85+
For language teams that coordinate translation efforts on Transifex, updating
86+
translation means pulling the translation strings.
8287

83-
Recommended: Before pulling translations, consider updating the .tx/config to have an up-to-date mapping of
84-
project/resources. For this, it is required to generate the documentation's pot files (template of po files),
85-
so start with the pot. Alternatively, you can skip it and pull translations, but new translation resources in Transifex
86-
could be not mapped, hence wouldn't be pulled.
88+
.. admonition:: Recommendation
89+
Before pulling translations, consider updating the .tx/config to
90+
have an up-to-date mapping of project/resources. For this, it is required to
91+
generate the documentation's pot files (template of po files), so start
92+
with the pot. Alternatively, you can skip it and pull translations, but new
93+
translation resources in Transifex could be not mapped, and hence wouldn't be pulled.
94+
95+
.. _generate-pot::
8796

8897
Generating pot files
8998
^^^^^^^^^^^^^^^^^^^^
9099

91-
Let's use Sphinx's gettext builder for generating pot files:
100+
Sphinx's gettext builder can be used for generating pot files:
92101

93102
.. code-block:: shell
94103
95104
make -C cpython/Doc/ ALLSPHINXOPTS='-E -b gettext -D gettext_compact=0 -d build/.doctrees . locales/pot' build
96105
97-
Now, there should be a cpython/Doc/locales/pot/ containing all the pot files.
106+
There should now be a ``cpython/Doc/locales/pot/`` directory containing all of the
107+
pot files.
98108

99-
Generating .tx/config file
100-
^^^^^^^^^^^^^^^^^^^^^^^^^^
109+
Generating a .tx/config file
110+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
101111

102-
Having the pot files, make use of sphinx-intl to generate the .tx/config:
112+
Once you have the pot files, make use of sphinx-intl to generate the .tx/config:
103113

104114
.. code-block:: shell
105115
@@ -110,11 +120,13 @@ Having the pot files, make use of sphinx-intl to generate the .tx/config:
110120
--transifex-project-name=python-newest \
111121
--locale-dir . --pot-dir pot
112122
113-
This step should take some time to finish. Once it is done, there should be a cpython/Doc/locales/.tx/config containing
114-
the list of resources based on the pot files previously generated.
123+
This step should take some time to finish. Once it is complete, there should be
124+
a ``cpython/Doc/locales/.tx/config`` file containing a list of resources based
125+
on the previously :ref:`generated pot files <generate-pot>`.
115126

116-
As a final touch, we copy the .tx/config into the language repository making proper tweaks so one can download
117-
translations from Transifex or upload local translation changes, all this from repository's root directory:
127+
As a final touch, we copy the ``.tx/config`` to the language repository making
128+
proper tweaks so one can download translations from Transifex or upload local
129+
translation changes, all this from repository's root directory:
118130

119131
.. code-block:: shell
120132
@@ -127,18 +139,18 @@ translations from Transifex or upload local translation changes, all this from r
127139
sed -i .tx/config \
128140
-e "s|^xfile_filter = ./<lang>/LC_MESSAGES/|trans.${LANGCODE} = |;"
129141
130-
Remapping translation and Transifex resources is done.
142+
Remapping translation and Transifex resources is complete.
131143

132-
Pulling the translations
133-
^^^^^^^^^^^^^^^^^^^^^^^^
144+
Pulling translations
145+
^^^^^^^^^^^^^^^^^^^^
134146

135-
Finally, let's download translations from Transifex using Transifex CLI tool:
147+
To download translations from Transifex using Transifex CLI tool:
136148

137149
.. code-block:: shell
138150
139151
tx pull -l ${LANGCODE} -t -f
140152
141-
Command explanations:
153+
Argument explanations:
142154

143155
* ``-l ${LANGCODE}`` – specify the language code so that tx doesn't pull all languages.
144156
* ``-t`` – specify that we want translations
@@ -147,43 +159,50 @@ Command explanations:
147159
Wrapping the translation files
148160
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
149161

150-
After pulling, it is highly recommended to use powrap in the po files to keep a better look:
162+
After pulling, it is highly recommended to use `powrap <https://pypi.org/project/powrap/>`_
163+
on the po files to make them look better:
151164

152165
.. code-block:: shell
153166
154167
powrap --quiet *.po **/*.po
155168
156-
Alternatively, you can use ``--modified`` flag to save time and apply only to changed files.
169+
Alternatively, you can use ``--modified`` flag to save time and apply only to
170+
changed files.
157171

158172

159173
Commit and push translation changes
160174
-----------------------------------
161175

162-
The following commands are recommended for committing and pushing your translations to the your language repository.
176+
The following commands are recommended for committing and pushing your
177+
translations to your language repository.
163178

164179
.. code-block:: shell
165180
166181
git diff -I'^"POT-Creation-Date: ' --numstat *.po **/*.po | cut -f3 | xargs -r git add
167182
git add $(git ls-files -o --exclude-standard *.po **/*.po) .tx/config
168183
git diff-index --quiet HEAD || { git commit -m "Update translations" && git push; }
169184
170-
It is not recommended to simply "git add" (stage) all PO files because this would also staged and commit the translation
171-
files that have only irrelevant changes in their POT-Creation-Date header field (i.e. date when the PO was updated against
172-
the POT).
185+
It is not recommended to simply ``git add`` (stage) all PO files because this would
186+
also stage (and then commit) the translation files that have only irrelevant
187+
changes in their ``POT-Creation-Date`` header field (i.e. date when the PO was
188+
updated against the POT).
173189

174-
The first command first git-add modified tracked files that does **not** exclusively match changes in POT-Creation-Date
175-
header, hence relevant changes are included.
190+
The first command first git-add modified tracked files that does **not**
191+
exclusively match changes in POT-Creation-Date header, hence relevant changes
192+
are included.
176193

177-
The second command will git-add untracked po files that may have been newly created on the latest 'tx pull' run. It also
178-
adds .tx/config file.
194+
The second command will git-add untracked po files that may have been newly
195+
created on the latest 'tx pull' run. It also adds .tx/config file.
179196

180-
The last command will only commit and push if any file was git-added in the above commands.
197+
The last command will only commit and push if any file was git-added in the
198+
above commands.
181199

182200

183201
Build translated documentation
184202
------------------------------
185203

186-
Useful for testing the translations, spotting syntax errors and viewing the result of your contribution.
204+
Useful for testing the translations, spotting syntax errors and viewing the
205+
result of your contribution.
187206

188207
To build translated documentation, run:
189208

@@ -193,11 +212,13 @@ To build translated documentation, run:
193212
make -C cpython/Doc venv
194213
make -C cpython/Doc SPHINXOPTS="--keep-going -D gettext_compact=0 -D language=${LANGCODE}" html
195214
196-
The first command copies the translation files (.po) into cpython's locale_dir, which is required for it to be recognized.
215+
The first command copies the translation files (.po) into cpython's locale_dir,
216+
which is required for it to be recognized.
197217

198-
Then create CPython's virtual environment using the Makefile from CPython's Doc directory:
218+
The second command creates a pre-configured virtual environment using the
219+
Makefile from CPython's Doc directory.
199220

200-
Finally, build using the Makefile from CPython's Doc directory. Here is an explanation of the arguments used:
221+
Finally, build using the Makefile. Here is an explanation of the arguments used:
201222

202223
* ``-C cpython/Doc`` – changes the current directory to run the make command
203224
* ``SPHINXOPTS`` – this variable should contain any CLI modifier command you want to pass
@@ -208,23 +229,24 @@ Finally, build using the Makefile from CPython's Doc directory. Here is an expla
208229

209230

210231
Viewing the documentation in a web browser
211-
-----------------------------------------
232+
------------------------------------------
212233

213-
Just build translated documentation and then open in the browser, no secrets. See below a one-line command to use your
214-
default web browser to open the index.html:
234+
Just build translated documentation and then open in a browser, no secrets.
235+
See below a one-line command to use your default web browser to open the index.html:
215236

216237
.. code-block:: shell
217238
218239
python -c "import os, webbrowser; webbrowser.open('file://cpython/Doc/build/html/index.html')"
219240
220-
Notice how index.html could be replaced with any page, e.g. 'library/os.html'.
241+
Notice ``index.html`` can be replaced with any file, e.g. ``'library/os.html'``.
221242

222243

223244
Linting the translation files
224245
-----------------------------
225246

226-
``sphinx-lint`` is great to spot translation errors that will didn't spot e.g. trailing whitespace in the string, reST
227-
directive not properly surrounded with whitespace, etc. It's highly recommended.
247+
``sphinx-lint`` is great to spot translation errors that will didn't spot e.g.
248+
trailing whitespace in the string, reST directive not properly surrounded with
249+
whitespace, etc. It's highly recommended.
228250

229251
.. code-block:: shell
230252
@@ -234,20 +256,21 @@ directive not properly surrounded with whitespace, etc. It's highly recommended.
234256
Merging translations into another branch
235257
----------------------------------------
236258

237-
This is useful when you want to replicate a translation from the CPython branch currently being translated to another
238-
older branch. E.g. 3.12 is currently being translated, but 3.11 has that same string and could make use of the
239-
translation contributed.
259+
This is useful when you want to replicate a translation from the CPython branch
260+
currently being translated to another older branch. E.g. |py_new| is currently being
261+
translated, but |py_last| has that same string and could make use of the contributed
262+
translations.
240263

241264
.. code-block:: shell
242265
243266
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
244-
TARGET_BRANCH=3.11
267+
TARGET_BRANCH=|py_last|
245268
pomerge --from-files *.po **/*.po
246269
git checkout ${TARGET_BRANCH}
247270
pomerge --to-files *.po **/*.po
248271
249-
After the above command, the translation from the current branch were applied to the previous branch "3.11". Now, let's
250-
make sure lines are wrapped:
272+
After the above command, the translation from the current branch were applied to
273+
the previous branch |py_last|. Now, one can verify lines are wrapped:
251274

252275
.. code-block:: shell
253276

docs/conf.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,14 @@
2323

2424
html_theme = 'furo'
2525
html_static_path = ['_static']
26+
27+
# ----------------------------------------------------------------------------
28+
29+
# Python versions
30+
newest = '3.13'
31+
previous = '3.12'
32+
33+
rst_prolog = f"""
34+
.. |py_new| replace:: {newest}
35+
.. |py_last| replace:: {previous}
36+
"""

0 commit comments

Comments
 (0)