From f38d03ca624b348fab8b15f9f7660187ad1d2513 Mon Sep 17 00:00:00 2001 From: ann0see <20726856+ann0see@users.noreply.github.com> Date: Sat, 10 Jan 2026 21:53:24 +0100 Subject: [PATCH] Add annotation tests for translations Make script executable Add PR commenting logic Add pygithub dependency Fix import Remove GitHub requirements Refactor test suite Fix some errors Add styling Add severity Be closer to qtlinguist semantics --- .github/workflows/translation-check.yml | 3 + tools/check-translations.py | 238 ++++++++++++++++++++++++ 2 files changed, 241 insertions(+) create mode 100755 tools/check-translations.py diff --git a/.github/workflows/translation-check.yml b/.github/workflows/translation-check.yml index 60d8a2d40d..e3e9ccc494 100644 --- a/.github/workflows/translation-check.yml +++ b/.github/workflows/translation-check.yml @@ -10,6 +10,7 @@ on: push: paths: - 'src/translation/wininstaller/**' + - 'src/translation/*.ts' - 'tools/check-wininstaller-translations.sh' - '.github/workflows/translation-check.yml' @@ -24,5 +25,7 @@ jobs: uses: actions/checkout@v6 - name: "Check Windows installer translations" run: ./tools/check-wininstaller-translations.sh + - name: "Check application translations" + run: pip install PyGithub && ./tools/check-translations.py #- name: "Check for duplicate hotkeys (will not fail)" # run: sudo apt install libxml-simple-perl && cd src/translation/ && perl ./tools/checkkeys.pl diff --git a/tools/check-translations.py b/tools/check-translations.py new file mode 100755 index 0000000000..7d60a99fa6 --- /dev/null +++ b/tools/check-translations.py @@ -0,0 +1,238 @@ +#!/usr/bin/env python3 +# +############################################################################## +# Copyright (c) 2026 +# +# Author(s): +# ChatGPT +# ann0see +# The Jamulus Development Team +# +############################################################################## +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +# +############################################################################## + +""" +Qt TS translation checker. + +This tool validates Qt `.ts` translation files according to Qt Linguist +semantics. +Warnings are reported with best-effort line numbers. In strict mode, the +presence of any warning results in a non-zero exit code to allow CI failure. +""" + +import argparse +import re +import sys +import xml.etree.ElementTree as ET +from collections import defaultdict +from dataclasses import dataclass +from enum import IntEnum +from pathlib import Path + +# Regex helpers +PLACEHOLDER_RE = re.compile(r"%\d+") +HTML_TAG_RE = re.compile(r"<[^>]+>") + +# ANSI escape codes +BOLD = "\033[1m" +CYAN = "\033[36m" +YELLOW = "\033[33m" +RED = "\033[31m" +RESET = "\033[0m" + +# Severity Enum +class Severity(IntEnum): + WARNING = 1 + SEVERE = 2 + +# Data structures +@dataclass(frozen=True) +class MessageContext: + ts_file: Path + line: int + lang: str + source: str + translation: str + tr_type: str + excerpt: str + +@dataclass(frozen=True) +class WarningItem: + ts_file: Path + line: int + message: str + severity: Severity + +# Helpers +def approximate_message_lines(text: str): + """Yield approximate line numbers for elements.""" + lines = text.splitlines() + cursor = 0 + for _ in range(text.count(" 0 or (args.strict and total_warning > 0): + return 1 + + return 0 + +if __name__ == "__main__": + sys.exit(main())