diff --git a/.github/workflows/tester.yml b/.github/workflows/tester.yml index f274e88f..42a3683e 100644 --- a/.github/workflows/tester.yml +++ b/.github/workflows/tester.yml @@ -4,9 +4,14 @@ on: push: branches: - master + - release/* + # path filters are not evaluated for pushes of tags + tags: + - "*" paths: - ".github/workflows/tester.yml" - "**/*.py" + - "dicogis/ui/i18n/*" - pyproject.toml pull_request: @@ -24,6 +29,9 @@ permissions: env: GDAL_VERSION: 3.* PROJECT_FOLDER: "dicogis" + # check translations completeness (tests/test_ui_i18n.py) only on tags and + # release/* branches. head_ref is the source branch of a pull request, empty on push + DICOGIS_I18N_STRICT: ${{ (startsWith(github.ref, 'refs/tags/') || startsWith(github.ref_name, 'release/') || startsWith(github.head_ref, 'release/')) && 'true' || 'false' }} jobs: test-ubuntu: diff --git a/docs/development/translation.md b/docs/development/translation.md index ac716e4b..7926758a 100644 --- a/docs/development/translation.md +++ b/docs/development/translation.md @@ -73,11 +73,13 @@ Ubuntu installs those binaries in `/usr/lib/qt6/bin/`, which is not on the `PATH 1. Check your work: ```sh - pytest tests/test_ui_i18n.py + DICOGIS_I18N_STRICT=1 pytest tests/test_ui_i18n.py ``` That suite fails, naming the offending strings, when a `self.tr()` string has no translation in a shipped locale, or when a `.qm` is out of date with its `.ts`. + The completeness check (every `self.tr()` string translated) is skipped unless the `DICOGIS_I18N_STRICT` environment variable is true, because translations are legitimately incomplete while a feature is under development. The CI enables it only on tags and on `release/*` branches (including pull requests opened from one), so a release cannot ship an untranslated interface. The `.qm` freshness check always runs. + ### English is the source language `dicogis_en.ts` is kept as a reference of the extracted strings and is regenerated like the others, but it is **never translated, compiled nor loaded**: with no translator installed, Qt returns the source string, which is already English. `DicoGIS._install_qt_translator()` accordingly removes any installed translator and returns early for `EN`. diff --git a/tests/test_ui_i18n.py b/tests/test_ui_i18n.py index 702d319e..81bebc07 100644 --- a/tests/test_ui_i18n.py +++ b/tests/test_ui_i18n.py @@ -22,12 +22,16 @@ # standard library import ast +from os import getenv from pathlib import Path from xml.etree import ElementTree # 3rd party import pytest +# project +from dicogis.utils.str2bool import str2bool + # ############################################################################## # ########## Globals ############### @@ -39,6 +43,16 @@ # loaded at runtime, so untranslated entries there are expected TRANSLATED_LOCALES = ("fr", "es") +# Missing translations are expected while features are under development, so the +# completeness check is only enforced when explicitly enabled: the CI does it on +# tags and `release/*` branches, a contributor can do it locally with +# `DICOGIS_I18N_STRICT=1 pytest tests/test_ui_i18n.py` +I18N_STRICT_ENV_VAR = "DICOGIS_I18N_STRICT" +requires_i18n_strict = pytest.mark.skipif( + not str2bool(getenv(I18N_STRICT_ENV_VAR, "False")), + reason=f"translations completeness only checked if {I18N_STRICT_ENV_VAR} is true", +) + # ############################################################################## # ########## Functions ############# @@ -108,6 +122,7 @@ def test_translatable_sources_are_found() -> None: assert len(_translatable_sources()) > 50 +@requires_i18n_strict @pytest.mark.parametrize("locale", TRANSLATED_LOCALES) def test_every_widget_string_is_translated(locale: str) -> None: """Every `self.tr()` string must have a translation in each shipped locale.