Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/tester.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion docs/development/translation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
15 changes: 15 additions & 0 deletions tests/test_ui_i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###############
Expand All @@ -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 #############
Expand Down Expand Up @@ -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.
Expand Down
Loading