1
- ============================================
2
- Commands for maintaining language repository
3
- ============================================
1
+ ==============================================
2
+ Commands for maintaining a language repository
3
+ ==============================================
4
4
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.
7
7
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.
10
10
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.
13
15
14
16
15
17
Clone CPython repository
16
18
------------------------
17
19
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.
20
22
21
23
From inside your language repository, run:
22
24
23
25
.. code-block :: shell
24
26
25
- BRANCH=3.12
27
+ BRANCH=| py_new |
26
28
git clone --depth 1 https://github.com/python/cpython --branch $BRANCH
27
29
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.
29
32
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.
33
36
34
37
35
38
Install requirements
36
39
--------------------
37
40
38
- Creating virtual environment
39
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
41
+ Creating a virtual environment
42
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
40
43
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:
43
47
44
48
.. code-block :: shell
45
49
@@ -49,14 +53,15 @@ this venv to make sure commands are run from it:
49
53
Install Python packages
50
54
^^^^^^^^^^^^^^^^^^^^^^^
51
55
52
- Update pip and then install the Python requirements :
56
+ Update pip and then install the required packages :
53
57
54
58
.. code-block :: shell
55
59
56
60
python -m pip install --upgrade pip
57
61
python -m pip install sphinx-intl> =2.1.0 pomerge powrap sphinx-lint
58
62
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.
60
65
61
66
Transifex CLI tool
62
67
^^^^^^^^^^^^^^^^^^
@@ -69,37 +74,42 @@ Install the Transifex CLI client, required to interact with Transifex:
69
74
curl -s -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh
70
75
cd ../..
71
76
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.
76
81
77
82
Updating the translations
78
83
-------------------------
79
84
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.
82
87
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 ::
87
96
88
97
Generating pot files
89
98
^^^^^^^^^^^^^^^^^^^^
90
99
91
- Let's use Sphinx's gettext builder for generating pot files:
100
+ Sphinx's gettext builder can be used for generating pot files:
92
101
93
102
.. code-block :: shell
94
103
95
104
make -C cpython/Doc/ ALLSPHINXOPTS=' -E -b gettext -D gettext_compact=0 -d build/.doctrees . locales/pot' build
96
105
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.
98
108
99
- Generating .tx/config file
100
- ^^^^^^^^^^^^^^^^^^^^^^^^^^
109
+ Generating a .tx/config file
110
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
101
111
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:
103
113
104
114
.. code-block :: shell
105
115
@@ -110,11 +120,13 @@ Having the pot files, make use of sphinx-intl to generate the .tx/config:
110
120
--transifex-project-name=python-newest \
111
121
--locale-dir . --pot-dir pot
112
122
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 >`.
115
126
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:
118
130
119
131
.. code-block :: shell
120
132
@@ -127,18 +139,18 @@ translations from Transifex or upload local translation changes, all this from r
127
139
sed -i .tx/config \
128
140
-e " s|^xfile_filter = ./<lang>/LC_MESSAGES/|trans.${LANGCODE} = |;"
129
141
130
- Remapping translation and Transifex resources is done .
142
+ Remapping translation and Transifex resources is complete .
131
143
132
- Pulling the translations
133
- ^^^^^^^^^^^^^^^^^^^^^^^^
144
+ Pulling translations
145
+ ^^^^^^^^^^^^^^^^^^^^
134
146
135
- Finally, let's download translations from Transifex using Transifex CLI tool:
147
+ To download translations from Transifex using Transifex CLI tool:
136
148
137
149
.. code-block :: shell
138
150
139
151
tx pull -l ${LANGCODE} -t -f
140
152
141
- Command explanations:
153
+ Argument explanations:
142
154
143
155
* ``-l ${LANGCODE} `` – specify the language code so that tx doesn't pull all languages.
144
156
* ``-t `` – specify that we want translations
@@ -147,43 +159,50 @@ Command explanations:
147
159
Wrapping the translation files
148
160
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
149
161
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:
151
164
152
165
.. code-block :: shell
153
166
154
167
powrap --quiet * .po ** /* .po
155
168
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.
157
171
158
172
159
173
Commit and push translation changes
160
174
-----------------------------------
161
175
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.
163
178
164
179
.. code-block :: shell
165
180
166
181
git diff -I' ^"POT-Creation-Date: ' --numstat * .po ** /* .po | cut -f3 | xargs -r git add
167
182
git add $( git ls-files -o --exclude-standard * .po ** /* .po) .tx/config
168
183
git diff-index --quiet HEAD || { git commit -m " Update translations" && git push; }
169
184
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).
173
189
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.
176
193
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.
179
196
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.
181
199
182
200
183
201
Build translated documentation
184
202
------------------------------
185
203
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.
187
206
188
207
To build translated documentation, run:
189
208
@@ -193,11 +212,13 @@ To build translated documentation, run:
193
212
make -C cpython/Doc venv
194
213
make -C cpython/Doc SPHINXOPTS=" --keep-going -D gettext_compact=0 -D language=${LANGCODE} " html
195
214
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.
197
217
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.
199
220
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:
201
222
202
223
* ``-C cpython/Doc `` – changes the current directory to run the make command
203
224
* ``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
208
229
209
230
210
231
Viewing the documentation in a web browser
211
- -----------------------------------------
232
+ ------------------------------------------
212
233
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:
215
236
216
237
.. code-block :: shell
217
238
218
239
python -c " import os, webbrowser; webbrowser.open('file://cpython/Doc/build/html/index.html')"
219
240
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' `` .
221
242
222
243
223
244
Linting the translation files
224
245
-----------------------------
225
246
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.
228
250
229
251
.. code-block :: shell
230
252
@@ -234,20 +256,21 @@ directive not properly surrounded with whitespace, etc. It's highly recommended.
234
256
Merging translations into another branch
235
257
----------------------------------------
236
258
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.
240
263
241
264
.. code-block :: shell
242
265
243
266
CURRENT_BRANCH=$( git rev-parse --abbrev-ref HEAD)
244
- TARGET_BRANCH=3.11
267
+ TARGET_BRANCH=| py_last |
245
268
pomerge --from-files * .po ** /* .po
246
269
git checkout ${TARGET_BRANCH}
247
270
pomerge --to-files * .po ** /* .po
248
271
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:
251
274
252
275
.. code-block :: shell
253
276
0 commit comments