From 810c9bd2fa8393b139246a3635b01840e13b0688 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sun, 10 Aug 2025 14:59:50 +0200 Subject: [PATCH] Manage localisation issues from CI --- .github/workflows/Locales.yml | 12 ++++++++---- tools/check_po.py | 29 ++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/.github/workflows/Locales.yml b/.github/workflows/Locales.yml index 42fa903b..722586f6 100644 --- a/.github/workflows/Locales.yml +++ b/.github/workflows/Locales.yml @@ -9,10 +9,14 @@ jobs: - uses: actions/checkout@v4 - name: Install dependencies - run: sudo apt-get update && sudo apt-get install gettext qt6-base-dev qt6-tools-dev qt6-l10n-tools qtchooser python3-polib + run: | + sudo apt-get update && sudo apt-get install gettext + pip install polib PyGithub - name: Check that .po files are up to date run: | - qtchooser -install qt6 $(which qmake6) - export QT_SELECT=qt6 - tools/check_po.py + if [[ "${{github.ref}}" == 'refs/heads/master' ]] ; then + tools/check_po.py --manage-issues --github-repository "${{ github.repository }}" --github-token "${{ github.token }}" + else + tools/check_po.py + fi diff --git a/tools/check_po.py b/tools/check_po.py index 118243d9..c311b751 100755 --- a/tools/check_po.py +++ b/tools/check_po.py @@ -1,6 +1,5 @@ #!/usr/bin/env python -import sys import polib import argparse import os @@ -35,6 +34,9 @@ def flag(lang: str): res += chr(ord(i) + ord('🇦') - ord('A')) return res +ISSUE_LABEL="localisation" +ISSUE_TITLE="[{lang}] Missing translations" + if __name__ == "__main__": root = os.path.dirname(os.path.dirname(__file__)) locale_dir = os.path.join(root, "locale") @@ -45,6 +47,9 @@ if __name__ == "__main__": description='Check that all strings are translated in a .po file') parser.add_argument('lang', type=str, nargs="*") + parser.add_argument('--github-repository') + parser.add_argument('--github-token') + parser.add_argument('--manage-issues', action="store_true") args = parser.parse_args() @@ -53,6 +58,11 @@ if __name__ == "__main__": if os.path.isdir(os.path.join(locale_dir, d)): args.lang.append(d) + if args.manage_issues: + from github import Github, Auth + gh = Github(auth=Auth.Token(args.github_token)) + repo = gh.get_repo(args.github_repository) + with tempfile.TemporaryDirectory() as tmpdir: client_pot = os.path.join(tmpdir, "client.pot") dashboard_pot = os.path.join(tmpdir, "dashboard.pot") @@ -103,3 +113,20 @@ if __name__ == "__main__": if missing > 0: print(f"::warning file={po}::{flag(lang)} {missing} translations missing") + + if args.manage_issues: + issues = [i for i in repo.get_issues(state="all", labels = [ISSUE_LABEL]) if i.title == ISSUE_TITLE.format(lang=lang)] + if not issues: + issue = repo.create_issue( + title=ISSUE_TITLE.format(lang=lang), + labels = [ISSUE_LABEL] + ) + else: + for issue in issues: + if issue.state != "open": + issue.edit(state = "open") + else: + if args.manage_issues: + issues = [i for i in repo.get_issues(state="open", labels = [ISSUE_LABEL]) if i.title == ISSUE_TITLE.format(lang=lang)] + for issue in issues: + issue.edit(state = "closed")