Skip to content

Commit cdbdf85

Browse files
authored
Merge pull request #398 from flpm/change-update-translations
docs: change update translation sessions in nox
2 parents 41866f9 + a19d40c commit cdbdf85

File tree

2 files changed

+95
-65
lines changed

2 files changed

+95
-65
lines changed

TRANSLATING.md

+8-12
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ You can find a list of the two-letter Sphinx language option [here](https://www.
7272

7373
The translation files contain the original English text and a space for you to enter the translated text. Before starting to translate, you need to make sure the translation files are up to date with the latest changes to the guide.
7474

75-
You can do this by running the following command:
75+
You can do this by running the following command, replacing LANG by the language code you plan to work on (e.g., `es` for Spanish):
7676

7777
```shell
78-
$ nox -s update-translations
78+
$ nox -s update-language -- LANG
7979
```
8080

8181
This command will create the translation files if they don't exist yet, or update them with the latest changes if they already exist.
@@ -220,10 +220,10 @@ When working on a translation, you **should not** modify the original English te
220220

221221
## Building the Translated Documentation
222222

223-
Once you finished translating or when you want to check the translation in context, you can build the guide locally on your computer, using the following command:
223+
Once you finished translating or when you want to check the translation in context, you can build the guide locally on your computer, using the following command, replacing LANG by the proper language code (e.g., `es` for Spanish)
224224

225225
```shell
226-
nox -s build-translations
226+
nox -s build-language -- LANG
227227
```
228228

229229
This command will build all the translated versions of the guide defined in the `LANGUAGES` list in `noxfile.py`. These translations will be stored in the `_build/html`, in folders named after the language code (e.g., `es`, `fr`, etc.).
@@ -251,7 +251,7 @@ You can follow these steps:
251251
1. Build the translations of the guide with same parameters that will be used during the release:
252252

253253
```shell
254-
nox -s build-translations-test
254+
nox -s build-all-languages-test
255255
```
256256

257257
2. Make sure there are no warnings or errors in the output. If there are, you will need to fix them before submitting the PR.
@@ -297,7 +297,7 @@ When you run the `sphinx-intl stat` command, you will see a list of `.po` files
297297

298298
### What happens when a string has changed in the original English text?
299299

300-
If a string has changed in the original English version, it will be marked as `fuzzy` in the translation file the next time it is updated (`nox -s update-translations`). Contributors working on the translation can then review the fuzzy entries and make the necessary changes to ensure it is accurate, before removing the `fuzzy` tag.
300+
If a string has changed in the original English version, it will be marked as `fuzzy` in the translation file the next time it is updated (`update-language`, `update-all-languages`, or `update-all-release-languages`). Contributors working on the translation can then review the fuzzy entries and make the necessary changes to ensure it is accurate, before removing the `fuzzy` tag.
301301

302302
### How do I handle links in the translated text?
303303

@@ -340,10 +340,6 @@ TODO: There are many approaches here, some projects release a translation as soo
340340

341341
### How can I get help with my translation?
342342

343-
If you have any questions or need help with your translation, you can create an issue in the repository.
343+
If you have any questions or need help with your translation, you can create an [issue](https://github.com/pyOpenSci/python-package-guide/issues) in the [Packaging Guide repository](https://github.com/pyOpenSci/python-package-guide)
344344

345-
TODO: Maybe [Discourse](https://pyopensci.discourse.group/) could be used as a way for contributors to ask for help with translations or the translation workflow?
346-
347-
```
348-
349-
```
345+
You can also ask in the PyOpenSci Discord server ([click here](https://discord.gg/CvSMp4zcqX) to join), you will find a general channel for questions related to our workflow, processes, and tools (translation-general) and channels for each of the languages we are working on (spanish-translation, japanese-translation, etc).

noxfile.py

+87-53
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def docs(session):
5555
session.install("-e", ".")
5656
session.run(SPHINX_BUILD, *BUILD_PARAMETERS, SOURCE_DIR, OUTPUT_DIR, *session.posargs)
5757
# When building the guide, also build the translations in RELEASE_LANGUAGES
58-
session.notify("build-translations", ['release-build'])
58+
session.notify("build-release-languages", session.posargs)
5959

6060

6161
@nox.session(name="docs-test")
@@ -69,7 +69,7 @@ def docs_test(session):
6969
session.run(SPHINX_BUILD, *BUILD_PARAMETERS, *TEST_PARAMETERS, SOURCE_DIR, OUTPUT_DIR, *session.posargs)
7070
# When building the guide with additional parameters, also build the translations in RELEASE_LANGUAGES
7171
# with those same parameters.
72-
session.notify("build-translations", ['release-build', *TEST_PARAMETERS])
72+
session.notify("build-release-languages", [*TEST_PARAMETERS, *session.posargs])
7373

7474

7575
@nox.session(name="docs-live")
@@ -142,76 +142,110 @@ def clean_dir(session):
142142
pathlib.Path(content).unlink()
143143

144144

145-
@nox.session(name="update-translations")
146-
def update_translations(session):
145+
@nox.session(name="update-release-languages")
146+
def update_release_languages(session):
147147
"""
148-
Update the translation files (./locales/*/.po) for all languages translations.
148+
Update the translation files (./locales/*/.po) for languages in RELEASE_LANGUAGES.
149149
150-
Note: this step is important because it makes sure that the translation files are
151-
up to date with the latest changes in the guide.
150+
Note: this step is called in the CI to keep release translations up to date with
151+
the latest changes in the guide.
152152
"""
153-
session.install("-e", ".")
154-
session.install("sphinx-intl")
155-
session.log("Updating templates (.pot)")
156-
session.run(SPHINX_BUILD, *TRANSLATION_TEMPLATE_PARAMETERS, SOURCE_DIR, TRANSLATION_TEMPLATE_DIR, *session.posargs)
157-
for lang in LANGUAGES:
158-
session.log(f"Updating .po files for [{lang}] translation")
159-
session.run("sphinx-intl", "update", "-p", TRANSLATION_TEMPLATE_DIR, "-l", lang)
153+
if RELEASE_LANGUAGES:
154+
session.install("-e", ".")
155+
session.install("sphinx-intl")
156+
session.log("Updating templates (.pot)")
157+
session.run(SPHINX_BUILD, *TRANSLATION_TEMPLATE_PARAMETERS, SOURCE_DIR, TRANSLATION_TEMPLATE_DIR, *session.posargs)
158+
for lang in RELEASE_LANGUAGES:
159+
session.log(f"Updating .po files for [{lang}] translation")
160+
session.run("sphinx-intl", "update", "-p", TRANSLATION_TEMPLATE_DIR, "-l", lang)
161+
else:
162+
session.warn("No release languages defined in RELEASE_LANGUAGES")
160163

161164

162-
@nox.session(name="build-languages")
163-
def build_languages(session):
165+
@nox.session(name="update-language")
166+
def update_language(session):
164167
"""
165-
Build the translations of the guide for the specified language.
168+
Update the translation files (./locales/*/.po) for a specific language translation.
166169
167-
Note: This sessions expects a list of languages to build in the first position of the session arguments.
168-
It does not need to be called directly, it is started by build_translations session.
170+
Note: this step is used by language coordinators to keep their translation files up to date
171+
with the latest changes in the guide, before the translation is released.
169172
"""
170-
if not session.posargs:
171-
session.error("Please provide the list of languages to build the translation for")
172-
languages_to_build = session.posargs.pop(0)
173+
if session.posargs and (lang := session.posargs.pop(0)):
174+
if lang in LANGUAGES:
175+
session.install("-e", ".")
176+
session.install("sphinx-intl")
177+
session.log("Updating templates (.pot)")
178+
session.run(SPHINX_BUILD, *TRANSLATION_TEMPLATE_PARAMETERS, SOURCE_DIR, TRANSLATION_TEMPLATE_DIR, *session.posargs)
179+
session.log(f"Updating .po files for [{lang}] translation")
180+
session.run("sphinx-intl", "update", "-p", TRANSLATION_TEMPLATE_DIR, "-l", lang)
181+
else:
182+
f"[{lang}] locale is not available. Try using:\n\n "
183+
"nox -s docs-live-lang -- LANG\n\n "
184+
f"where LANG is one of: {LANGUAGES}"
185+
else:
186+
session.error(
187+
"Please provide a language using:\n\n "
188+
"nox -s update-language -- LANG\n\n "
189+
f" where LANG is one of: {LANGUAGES}"
190+
)
191+
192+
@nox.session(name="build-language")
193+
def build_language(session):
194+
"""
195+
Build the guide for a specific language translation
196+
197+
For example: nox -s build-language -- es.
198+
"""
199+
if session.posargs and (lang := session.posargs.pop(0)):
200+
if lang in LANGUAGES:
201+
session.install("-e", ".")
202+
session.log(f"Building [{lang}] guide")
203+
session.run(SPHINX_BUILD, *BUILD_PARAMETERS, "-D", f"language={lang}", ".", OUTPUT_DIR / lang, *session.posargs)
204+
else:
205+
session.error(f"Language {lang} is not in LANGUAGES list.")
206+
else:
207+
session.error(
208+
"Please provide a language using:\n\n "
209+
"nox -s build-language -- LANG\n\n "
210+
f" where LANG is one of: {LANGUAGES}"
211+
)
212+
173213

214+
@nox.session(name="build-release-languages")
215+
def build_release_languages(session):
216+
"""
217+
Build the translations of the guide for the languages in RELEASE_LANGUAGES.
218+
"""
219+
if not RELEASE_LANGUAGES:
220+
session.warn("No release languages defined in RELEASE_LANGUAGES")
221+
return
174222
session.install("-e", ".")
175-
for lang in languages_to_build:
176-
if lang not in LANGUAGES:
177-
session.warn(f"Language [{lang}] is not available for translation")
178-
continue
223+
for lang in RELEASE_LANGUAGES:
179224
session.log(f"Building [{lang}] guide")
180225
session.run(SPHINX_BUILD, *BUILD_PARAMETERS, "-D", f"language={lang}", ".", OUTPUT_DIR / lang, *session.posargs)
226+
session.log(f"Translations built for {RELEASE_LANGUAGES}")
181227

182-
183-
@nox.session(name="build-translations")
184-
def build_translations(session):
228+
@nox.session(name="build-all-languages")
229+
def build_all_languages(session):
185230
"""
186-
Build translations of the guide.
187-
188-
Note: this session can be called directly to build all available translations (defined in LANGUAGES).
189-
It is also called by the docs and docs-test sessions with 'release-build' as the first positional
190-
argument, to build only the translations defined in RELEASE_LANGUAGES.
231+
Build the translations of the guide for the languages in LANGUAGES.
191232
"""
192-
release_build = False
193-
if session.posargs and session.posargs[0] == 'release-build':
194-
session.posargs.pop(0)
195-
release_build = True
196-
# if running from the docs or docs-test sessions, build only release languages
197-
BUILD_LANGUAGES = RELEASE_LANGUAGES if release_build else LANGUAGES
198-
# only build languages that have a locale folder
199-
BUILD_LANGUAGES = [lang for lang in BUILD_LANGUAGES if (TRANSLATION_LOCALES_DIR / lang).exists()]
200-
session.log(f"Declared languages: {LANGUAGES}")
201-
session.log(f"Release languages: {RELEASE_LANGUAGES}")
202-
session.log(f"Building languages{' for release' if release_build else ''}: {BUILD_LANGUAGES}")
203-
if not BUILD_LANGUAGES:
204-
session.warn("No translations to build")
205-
else:
206-
session.notify("build-languages", [BUILD_LANGUAGES, *session.posargs])
233+
if not LANGUAGES:
234+
session.warn("No languages defined in LANGUAGES")
235+
return
236+
session.install("-e", ".")
237+
for lang in LANGUAGES:
238+
session.log(f"Building [{lang}] guide")
239+
session.run(SPHINX_BUILD, *BUILD_PARAMETERS, "-D", f"language={lang}", ".", OUTPUT_DIR / lang, *session.posargs)
240+
session.log(f"Translations built for {LANGUAGES}")
207241

208242

209-
@nox.session(name="build-translations-test")
210-
def build_translations_test(session):
243+
@nox.session(name="build-all-languages-test")
244+
def build_all_languages_test(session):
211245
"""
212-
Build all translations of the guide with testing parameters.
246+
Build all translations of the guide with the testing parameters.
213247
214248
This is a convenience session to test the build of all translations with the testing parameters
215249
in the same way docs-test does for the English version.
216250
"""
217-
session.notify("build-translations", [*TEST_PARAMETERS])
251+
session.notify("build-all-languages", [*TEST_PARAMETERS])

0 commit comments

Comments
 (0)