From c660b50557409bda5203c1514bc33e15c8734d54 Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Wed, 25 Nov 2026 18:53:05 -0800 Subject: [PATCH 1/2] ci(i18n): add translation and POT validation workflow Add SHA-pinned GitHub Actions workflow validating plugin .po and .pot files: - msgfmt -c -v -o /dev/null syntax and format-string checks - Devanagari-danda-safe msgcheck==4.2.0 linting (hi/mr/ne/sa) - Placeholder and HTML tag parity audit matching Cacti/cacti#8970 - POT source-string lint (plural periods, HTML balance, php-format prose) Uses incremental --base comparison so pre-existing upstream baseline issues do not break unrelated PRs, and runs a validator self-test on workflow edits. Signed-off-by: Thomas Vincent --- .github/workflows/i18n-validation.yml | 633 ++++++++++++++++++++++++++ 1 file changed, 633 insertions(+) create mode 100644 .github/workflows/i18n-validation.yml diff --git a/.github/workflows/i18n-validation.yml b/.github/workflows/i18n-validation.yml new file mode 100644 index 00000000..70702994 --- /dev/null +++ b/.github/workflows/i18n-validation.yml @@ -0,0 +1,633 @@ +# +-------------------------------------------------------------------------+ +# | Copyright (C) 2004-2026 The Cacti Group | +# | | +# | 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. | +# +-------------------------------------------------------------------------+ + +name: i18n Validation + +on: + push: + branches: + - develop + paths: + - 'locales/po/*.po' + - 'locales/po/*.pot' + - '.github/workflows/i18n-validation.yml' + pull_request: + paths: + - 'locales/po/*.po' + - 'locales/po/*.pot' + - '.github/workflows/i18n-validation.yml' + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + validate-i18n: + name: Validate Translations and POT Template + runs-on: ubuntu-24.04 + timeout-minutes: 15 + + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Set up Python 3.12 + uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 + with: + python-version: '3.12' + + - name: Install dependencies + run: | + set -euo pipefail + sudo apt-get update -qq + sudo apt-get install -y --no-install-recommends gettext + python3 -m pip install --only-binary=:all: msgcheck==4.2.0 polib==1.2.0 + + - name: Identify target translation and template files + id: changed + env: + EVENT_NAME: ${{ github.event_name }} + PR_BASE_SHA: ${{ github.event.pull_request.base.sha }} + PUSH_BEFORE: ${{ github.event.before }} + run: | + set -euo pipefail + if [ "$EVENT_NAME" = "pull_request" ]; then + BASE="$PR_BASE_SHA" + else + BASE="$PUSH_BEFORE" + fi + + HAS_BASE="false" + if [ -n "$BASE" ] && git cat-file -e "${BASE}^{commit}" 2>/dev/null; then + HAS_BASE="true" + echo "base=$BASE" >> "$GITHUB_OUTPUT" + git diff --name-only --diff-filter=d "$BASE" HEAD > /tmp/changed_all.txt + else + git show --name-only --diff-filter=d --format="" HEAD > /tmp/changed_all.txt + fi + + WORKFLOW_CHANGED="false" + if grep -Fxq ".github/workflows/i18n-validation.yml" /tmp/changed_all.txt; then + WORKFLOW_CHANGED="true" + fi + echo "workflow_changed=$WORKFLOW_CHANGED" >> "$GITHUB_OUTPUT" + + if [ "$WORKFLOW_CHANGED" = "true" ]; then + git ls-files 'locales/po/*.po' > /tmp/target_po.txt + git ls-files 'locales/po/*.pot' > /tmp/target_pot.txt + elif [ "$HAS_BASE" = "true" ]; then + git diff --name-only --diff-filter=d "$BASE" HEAD -- 'locales/po/*.po' > /tmp/target_po.txt + git diff --name-only --diff-filter=d "$BASE" HEAD -- 'locales/po/*.pot' > /tmp/target_pot.txt + else + git show --name-only --diff-filter=d --format="" HEAD -- 'locales/po/*.po' > /tmp/target_po.txt + git show --name-only --diff-filter=d --format="" HEAD -- 'locales/po/*.pot' > /tmp/target_pot.txt + fi + + PO_COUNT=$(grep -c '.' /tmp/target_po.txt || true) + POT_COUNT=$(grep -c '.' /tmp/target_pot.txt || true) + echo "po_count=$PO_COUNT" >> "$GITHUB_OUTPUT" + echo "pot_count=$POT_COUNT" >> "$GITHUB_OUTPUT" + echo "Workflow changed: $WORKFLOW_CHANGED | Target .po: $PO_COUNT | Target .pot: $POT_COUNT" + cat /tmp/target_po.txt + cat /tmp/target_pot.txt + + - name: Write i18n validation script + run: | + cat <<'PYEOF' > /tmp/cacti_i18n_check.py + #!/usr/bin/env python3 + """Self-contained i18n validator for Cacti plugin .po and .pot catalogs.""" + + import argparse + from collections import Counter + from pathlib import Path + import re + import subprocess + import sys + import tempfile + + import polib + + DEVANAGARI_RE = re.compile(r'^(?:hi|mr|ne|sa)(?:[-_].*)?\.po$', re.IGNORECASE) + DANDA_TRAILING_RE = re.compile(r'\u0964(\s*)$') + HTML_TAG_RE = re.compile(r'<[^>]+>') + HTML_OPEN_CLOSE_RE = re.compile(r'<(/?)([a-z][a-z0-9]*)\b[^>]*?(/?)>', re.IGNORECASE) + + # Real non-void HTML element names (excludes Cacti tokens and void tags). + HTML_PAIRED_TAGS = { + 'a', 'abbr', 'b', 'blockquote', 'body', 'button', 'caption', 'code', + 'dd', 'del', 'details', 'dfn', 'div', 'dl', 'dt', 'em', 'fieldset', + 'figcaption', 'figure', 'font', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', + 'h6', 'head', 'header', 'html', 'i', 'ins', 'kbd', 'label', 'legend', + 'li', 'main', 'mark', 'nav', 'noscript', 'ol', 'optgroup', 'option', + 'p', 'pre', 'q', 's', 'samp', 'script', 'section', 'select', 'small', + 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', + 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'title', 'tr', 'tt', + 'u', 'ul', 'var', + } + + # Match printf-style placeholders matching Cacti/cacti#8970. + _CONVERSION = r'[bcdeEfFgGosuxX]' + _PLACEHOLDER_PARTS = re.compile( + r'%(?!%)' + r'(?:([0-9]+)\$)?' + r"[#0\-+']*" + r'(?:[0-9]+|\*)?' + r'(?:\.(?:[0-9]+|\*))?' + r'(?:hh|h|ll|l|L|z|j|t)?' + r'(' + _CONVERSION + r')' + ) + + # Literal '%' prose accidentally tagged php-format by xgettext (e.g. "'%'", "% for"). + LITERAL_PCT_PROSE_RE = re.compile(r"(? list[str]: + return [line.strip() for line in Path(path).read_text(encoding='utf-8').splitlines() if line.strip()] + + + def git_show_bytes(base: str, rel_path: str) -> bytes | None: + res = subprocess.run(['git', 'show', f'{base}:{rel_path}'], capture_output=True, check=False) + return res.stdout if res.returncode == 0 else None + + + def _normalize_msgfmt_errors(stderr: str) -> Counter[str]: + errs: Counter[str] = Counter() + for line in stderr.splitlines(): + s = line.strip() + if not s or 'translated message' in s or re.match(r'^msgfmt: found \d+ fatal error', s): + continue + # Strip file:line: prefix so unrelated line shifts do not mask baseline identity. + norm = re.sub(r'^[^:]+:\d+:\s*', '', s) + errs[norm] += 1 + return errs + + + def _run_msgfmt_file(path: str) -> tuple[int, str]: + res = subprocess.run(['msgfmt', '-c', '-v', '-o', '/dev/null', path], capture_output=True, text=True, check=False) + return res.returncode, res.stderr + + + def cmd_msgfmt(files: list[str], base: str | None) -> int: + failures = 0 + for rel in files: + rc, stderr = _run_msgfmt_file(rel) + if rc == 0: + print(f'OK [msgfmt] {rel}: {stderr.strip()}') + continue + cur_errs = _normalize_msgfmt_errors(stderr) + if base: + base_bytes = git_show_bytes(base, rel) + if base_bytes is not None: + with tempfile.TemporaryDirectory() as td: + bp = Path(td) / 'base.po' + bp.write_bytes(base_bytes) + brc, berr = _run_msgfmt_file(str(bp)) + if brc != 0: + new_errs = cur_errs - _normalize_msgfmt_errors(berr) + if not new_errs: + print(f'::warning file={rel}::Pre-existing msgfmt baseline issue(s) unchanged from base') + continue + print(f'ERROR [msgfmt] {rel}:\n{stderr.strip()}') + failures += 1 + return 1 if failures else 0 + + + def _normalize_danda_for_msgcheck(po_bytes: bytes, filename: str, dst: Path) -> None: + dst.write_bytes(po_bytes) + if not DEVANAGARI_RE.match(Path(filename).name): + return + po = polib.pofile(str(dst)) + changed = False + for entry in po: + if entry.obsolete: + continue + if entry.msgid and entry.msgid.rstrip().endswith('.'): + if entry.msgstr and DANDA_TRAILING_RE.search(entry.msgstr): + entry.msgstr = DANDA_TRAILING_RE.sub(r'.\1', entry.msgstr) + changed = True + if entry.msgid_plural and entry.msgstr_plural: + for idx, val in list(entry.msgstr_plural.items()): + ref = entry.msgid_plural if idx > 0 else entry.msgid + if ref and ref.rstrip().endswith('.') and val and DANDA_TRAILING_RE.search(val): + entry.msgstr_plural[idx] = DANDA_TRAILING_RE.sub(r'.\1', val) + changed = True + if changed: + po.save(str(dst)) + + + def _run_msgcheck_bytes(po_bytes: bytes, filename: str) -> Counter[str]: + with tempfile.TemporaryDirectory() as td: + tmp_po = Path(td) / Path(filename).name + _normalize_danda_for_msgcheck(po_bytes, filename, tmp_po) + res = subprocess.run(['msgcheck', '--no-lines', str(tmp_po)], capture_output=True, text=True, check=False) + if res.returncode == 0: + return Counter() + out = (res.stdout + '\n' + res.stderr).splitlines() + findings: Counter[str] = Counter() + for line in out: + s = line.strip() + if not s: + continue + norm = s.replace(str(tmp_po), filename) + findings[norm] += 1 + return findings or Counter({f'msgcheck exited with status {res.returncode}': 1}) + + + def cmd_msgcheck(files: list[str], base: str | None) -> int: + failures = 0 + for rel in files: + cur = _run_msgcheck_bytes(Path(rel).read_bytes(), rel) + if not cur: + print(f'OK [msgcheck] {rel}') + continue + if base: + base_bytes = git_show_bytes(base, rel) + if base_bytes is not None: + prev = _run_msgcheck_bytes(base_bytes, rel) + cur = cur - prev + if not cur: + print(f'::warning file={rel}::Pre-existing msgcheck baseline finding(s) unchanged from base') + continue + print(f'ERROR [msgcheck] {rel}:') + for msg, cnt in sorted(cur.items()): + print(f' ({cnt}x) {msg}') + failures += 1 + return 1 if failures else 0 + + + def _parse_placeholders(text: str) -> list[tuple[int | None, str, str]]: + cleaned = text.replace('%%', '') + parsed: list[tuple[int | None, str, str]] = [] + for m in _PLACEHOLDER_PARTS.finditer(cleaned): + pos = int(m.group(1)) if m.group(1) is not None else None + parsed.append((pos, m.group(2), m.group(0))) + return parsed + + + def _expected_arg_types(src: list[tuple[int | None, str, str]]) -> dict[int, str]: + types: dict[int, str] = {} + seq = 1 + for pos, conv, _ in src: + if pos is None: + idx = seq + seq += 1 + else: + idx = pos + types[idx] = conv + return types + + + def audit_pair(msgid: str, msgstr: str, loc: str) -> int: + errors = 0 + + # 1. HTML tag count parity + tags_id = HTML_TAG_RE.findall(msgid) + tags_str = HTML_TAG_RE.findall(msgstr) + if len(tags_id) != len(tags_str): + print( + f'ERROR [{loc}] HTML tag count mismatch: ' + f'msgid has {len(tags_id)}, msgstr has {len(tags_str)}' + f'\n msgid: {msgid[:80]}' + f'\n msgstr: {msgstr[:80]}' + ) + errors += 1 + + # 2. Printf-style placeholder parity and style consistency (Cacti/cacti#8970) + src = _parse_placeholders(msgid) + tgt = _parse_placeholders(msgstr) + + if tgt and not src: + print( + f'ERROR [{loc}] msgstr has format specifier(s) but msgid has none' + f'\n msgid: {msgid[:80]}' + f'\n msgstr: {msgstr[:80]}' + ) + return errors + 1 + + if src and not tgt: + print( + f'ERROR [{loc}] msgstr is missing format specifier(s): ' + f'msgid has {len(src)}, msgstr has 0' + f'\n msgid: {msgid[:80]}' + f'\n msgstr: {msgstr[:80]}' + ) + return errors + 1 + + if not src: + return errors + + src_types = _expected_arg_types(src) + positional_count = sum(1 for pos, _, _ in tgt if pos is not None) + + if 0 < positional_count < len(tgt): + print( + f'ERROR [{loc}] Mixed positional and non-positional placeholders in msgstr' + f'\n msgid: {msgid[:80]}' + f'\n msgstr: {msgstr[:80]}' + ) + return errors + 1 + + if positional_count == len(tgt): + max_idx = max(src_types) + out_of_range = [raw for pos, _, raw in tgt if pos is None or pos < 1 or pos not in src_types] + if out_of_range: + print( + f'ERROR [{loc}] Out-of-range positional placeholder(s) ' + f'{", ".join(out_of_range)} (expected 1..{max_idx})' + f'\n msgid: {msgid[:80]}' + f'\n msgstr: {msgstr[:80]}' + ) + errors += 1 + + type_mismatches = [ + f'{raw} (expected %{pos}${src_types[pos]})' + for pos, conv, raw in tgt + if pos is not None and pos in src_types and conv != src_types[pos] + ] + if type_mismatches: + print( + f'ERROR [{loc}] Positional placeholder type mismatch: {", ".join(type_mismatches)}' + f'\n msgid: {msgid[:80]}' + f'\n msgstr: {msgstr[:80]}' + ) + errors += 1 + + referenced = {pos for pos, _, _ in tgt if pos is not None} + missing = sorted(set(src_types) - referenced) + if missing: + missing_desc = ', '.join(f'%{idx}${src_types[idx]}' for idx in missing) + print( + f'ERROR [{loc}] Missing positional placeholder(s): {missing_desc}' + f'\n msgid: {msgid[:80]}' + f'\n msgstr: {msgstr[:80]}' + ) + errors += 1 + return errors + + if len(tgt) != len(src): + print( + f'ERROR [{loc}] Placeholder count mismatch: ' + f'msgid has {len(src)}, msgstr has {len(tgt)}' + f'\n msgid: {msgid[:80]}' + f'\n msgstr: {msgstr[:80]}' + ) + return errors + 1 + + src_convs = [conv for _, conv, _ in src] + tgt_convs = [conv for _, conv, _ in tgt] + if tgt_convs != src_convs: + print( + f'ERROR [{loc}] Placeholder type/order mismatch: ' + f'msgid has [{", ".join("%" + c for c in src_convs)}], ' + f'msgstr has [{", ".join("%" + c for c in tgt_convs)}]' + f'\n msgid: {msgid[:80]}' + f'\n msgstr: {msgstr[:80]}' + ) + errors += 1 + + return errors + + + def _entry_key(entry: polib.POEntry) -> tuple: + return (entry.msgctxt, entry.msgid, entry.msgid_plural) + + + def _entry_value(entry: polib.POEntry) -> tuple: + return (entry.msgstr, tuple(sorted(entry.msgstr_plural.items()))) + + + def _load_base_po_map(rel_path: str, base: str) -> dict[tuple, tuple] | None: + raw = git_show_bytes(base, rel_path) + if raw is None: + return None + with tempfile.TemporaryDirectory() as td: + p = Path(td) / 'base.po' + p.write_bytes(raw) + try: + po = polib.pofile(str(p)) + except (OSError, ValueError, UnicodeDecodeError): + return None + return {_entry_key(e): _entry_value(e) for e in po if not e.obsolete} + + + def cmd_audit_po(files: list[str], base: str | None) -> int: + total_errors = 0 + for rel in files: + po = polib.pofile(rel) + previous = _load_base_po_map(rel, base) if base else None + file_errors = 0 + for entry in po: + if entry.obsolete: + continue + if previous is not None and previous.get(_entry_key(entry)) == _entry_value(entry): + continue + loc = f'{rel}:{entry.linenum}' + if entry.msgstr: + file_errors += audit_pair(entry.msgid, entry.msgstr, loc) + if entry.msgid_plural and entry.msgstr_plural: + for idx, plural_str in sorted(entry.msgstr_plural.items()): + if not plural_str: + continue + source = entry.msgid_plural if idx > 0 else entry.msgid + file_errors += audit_pair(source, plural_str, f'{loc}[{idx}]') + total_errors += file_errors + if total_errors: + print(f'\n{total_errors} placeholder/HTML audit error(s) found.') + return 1 + print(f'OK [audit-po] {len(files)} file(s) passed.') + return 0 + + + def _has_unbalanced_html(text: str) -> list[str]: + stack: list[str] = [] + for m in HTML_OPEN_CLOSE_RE.finditer(text): + closing, tag, self_close = (m.group(1) == '/'), m.group(2).lower(), (m.group(3) == '/') + if self_close or tag not in HTML_PAIRED_TAGS: + continue + if not closing: + stack.append(tag) + elif stack and stack[-1] == tag: + stack.pop() + else: + return [f'unexpected '] + return [f'unclosed <{t}>' for t in stack] + + + def lint_pot_entry(entry: polib.POEntry) -> list[str]: + issues: list[str] = [] + if entry.msgid_plural: + if entry.msgid.rstrip().endswith('.') != entry.msgid_plural.rstrip().endswith('.'): + issues.append('mismatched trailing period between msgid and msgid_plural') + for field_name, text in (('msgid', entry.msgid), ('msgid_plural', entry.msgid_plural)): + if not text: + continue + html_errs = _has_unbalanced_html(text) + if html_errs: + issues.append(f'unbalanced HTML in {field_name}: {", ".join(html_errs)}') + if 'php-format' in entry.flags and 'no-php-format' not in entry.flags: + if LITERAL_PCT_PROSE_RE.search(entry.msgid or '') or LITERAL_PCT_PROSE_RE.search(entry.msgid_plural or ''): + issues.append('literal % prose marked php-format without no-php-format') + return issues + + + def cmd_lint_pot(files: list[str], base: str | None) -> int: + total_errors = 0 + for rel in files: + pot = polib.pofile(rel) + base_sigs: set[tuple] | None = None + if base: + raw = git_show_bytes(base, rel) + if raw is not None: + with tempfile.TemporaryDirectory() as td: + p = Path(td) / 'base.pot' + p.write_bytes(raw) + try: + bpot = polib.pofile(str(p)) + base_sigs = { + (e.msgctxt, e.msgid, e.msgid_plural, tuple(sorted(e.flags))) + for e in bpot if not e.obsolete + } + except (OSError, ValueError, UnicodeDecodeError): + base_sigs = None + baseline_warnings = 0 + for entry in pot: + if entry.obsolete or not entry.msgid: + continue + issues = lint_pot_entry(entry) + if not issues: + continue + sig = (entry.msgctxt, entry.msgid, entry.msgid_plural, tuple(sorted(entry.flags))) + if base_sigs is not None and sig in base_sigs: + baseline_warnings += 1 + continue + for iss in issues: + print(f'ERROR [{rel}:{entry.linenum}] {iss}\n msgid: {entry.msgid[:90]}') + total_errors += 1 + if baseline_warnings: + print(f'::warning file={rel}::{baseline_warnings} pre-existing POT lint issue(s) unchanged from base') + if total_errors: + print(f'\n{total_errors} POT lint error(s) found.') + return 1 + print(f'OK [lint-pot] {len(files)} file(s) passed.') + return 0 + + + def cmd_self_test() -> int: + # 1. Placeholder & HTML parity (Cacti/cacti#8970) + assert audit_pair('%s of %d', '%s de %d', 't') == 0 + assert audit_pair('%s has %d items', '%2$d Elemente in %1$s', 't') == 0 + assert audit_pair('Literal %%s and %s', 'Literal %%s och %s', 't') == 0 + assert audit_pair('Half of hosts', '50 % des hôtes', 't') == 0 + assert audit_pair('%s of %d', '%1$s de %d', 't') >= 1 + assert audit_pair('%s of %d', '%0$s de %1$d', 't') >= 1 + assert audit_pair('%s of %d', '%d de %s', 't') >= 1 + assert audit_pair('Hi', 'Hi', 't') >= 1 + + # 2. Devanagari-danda-safe msgcheck + hi_po = ( + 'msgid ""\nmsgstr ""\n' + '"Content-Type: text/plain; charset=UTF-8\\n"\n' + '"Language: hi-IN\\n"\n\n' + 'msgid "Save changes."\n' + 'msgstr "परिवर्तन सहेजें।"\n' + ).encode('utf-8') + assert not _run_msgcheck_bytes(hi_po, 'locales/po/hi-IN.po'), 'Devanagari danda should pass msgcheck' + + # 3. msgfmt syntax catch + bad_fmt = ( + 'msgid ""\nmsgstr ""\n' + '"Content-Type: text/plain; charset=UTF-8\\n"\n\n' + '#, php-format\nmsgid "Hello %s"\nmsgstr "Hello %d"\n' + ).encode('utf-8') + with tempfile.TemporaryDirectory() as td: + p = Path(td) / 'bad.po' + p.write_bytes(bad_fmt) + rc, _ = _run_msgfmt_file(str(p)) + assert rc != 0, 'msgfmt must reject format specifier mismatch' + + # 4. POT source-string lint + e_period = polib.POEntry(msgid='Delete item.', msgid_plural='Delete items') + assert any('trailing period' in x for x in lint_pot_entry(e_period)) + e_html = polib.POEntry(msgid='Hello world') + assert any('unbalanced HTML' in x for x in lint_pot_entry(e_html)) + e_cacti_ph = polib.POEntry(msgid='Device: ()
') + assert not lint_pot_entry(e_cacti_ph), 'Cacti tokens must not trip HTML balance check' + e_pct = polib.POEntry(msgid="SQL wildcard is '%' sign.", flags=['php-format']) + assert any('php-format' in x for x in lint_pot_entry(e_pct)) + e_pct_ok = polib.POEntry(msgid="SQL wildcard is '%' sign.", flags=['no-php-format']) + assert not lint_pot_entry(e_pct_ok) + + print('OK [self-test] All validator checks passed.') + return 0 + + + def main() -> int: + ap = argparse.ArgumentParser() + sub = ap.add_subparsers(dest='cmd', required=True) + sub.add_parser('self-test') + for name in ('msgfmt', 'msgcheck', 'audit-po', 'lint-pot'): + sp = sub.add_parser(name) + sp.add_argument('--base', default='') + sp.add_argument('--files-from', required=True) + args = ap.parse_args() + if args.cmd == 'self-test': + return cmd_self_test() + files = read_file_list(args.files_from) + if not files: + print(f'SKIP [{args.cmd}] No target files.') + return 0 + base = args.base or None + if args.cmd == 'msgfmt': + return cmd_msgfmt(files, base) + if args.cmd == 'msgcheck': + return cmd_msgcheck(files, base) + if args.cmd == 'audit-po': + return cmd_audit_po(files, base) + if args.cmd == 'lint-pot': + return cmd_lint_pot(files, base) + return 1 + + + if __name__ == '__main__': + sys.exit(main()) + PYEOF + + - name: Run validator self-test + if: steps.changed.outputs.workflow_changed == 'true' + run: python3 /tmp/cacti_i18n_check.py self-test + + - name: Run msgfmt syntax and format-string check + if: steps.changed.outputs.po_count != '0' + env: + BASE: ${{ steps.changed.outputs.base }} + run: python3 /tmp/cacti_i18n_check.py msgfmt --base "$BASE" --files-from /tmp/target_po.txt + + - name: Run Devanagari-safe msgcheck linter + if: steps.changed.outputs.po_count != '0' + env: + BASE: ${{ steps.changed.outputs.base }} + run: python3 /tmp/cacti_i18n_check.py msgcheck --base "$BASE" --files-from /tmp/target_po.txt + + - name: Run HTML and placeholder parity audit + if: steps.changed.outputs.po_count != '0' + env: + BASE: ${{ steps.changed.outputs.base }} + run: python3 /tmp/cacti_i18n_check.py audit-po --base "$BASE" --files-from /tmp/target_po.txt + + - name: Run POT source-string lint + if: steps.changed.outputs.pot_count != '0' + env: + BASE: ${{ steps.changed.outputs.base }} + run: python3 /tmp/cacti_i18n_check.py lint-pot --base "$BASE" --files-from /tmp/target_pot.txt From 7d61384213a472f1ecb1648a341da6486738889f Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Thu, 26 Nov 2026 01:22:31 -0800 Subject: [PATCH 2/2] ci(i18n): call the shared Cacti i18n validation workflow Replace the copied validation steps with a call to the reusable workflow in Cacti/cacti, which runs msgfmt, msgcheck and the .po and .pot audits from the shared scripts in tests/tools. The triggers and the job name stay the same. Depends on Cacti/cacti#8977, which adds the reusable workflow. Signed-off-by: Thomas Vincent --- .github/workflows/i18n-validation.yml | 600 +------------------------- 1 file changed, 2 insertions(+), 598 deletions(-) diff --git a/.github/workflows/i18n-validation.yml b/.github/workflows/i18n-validation.yml index 70702994..29ce6197 100644 --- a/.github/workflows/i18n-validation.yml +++ b/.github/workflows/i18n-validation.yml @@ -33,601 +33,5 @@ concurrency: jobs: validate-i18n: name: Validate Translations and POT Template - runs-on: ubuntu-24.04 - timeout-minutes: 15 - - steps: - - name: Checkout - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - fetch-depth: 0 - persist-credentials: false - - - name: Set up Python 3.12 - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 - with: - python-version: '3.12' - - - name: Install dependencies - run: | - set -euo pipefail - sudo apt-get update -qq - sudo apt-get install -y --no-install-recommends gettext - python3 -m pip install --only-binary=:all: msgcheck==4.2.0 polib==1.2.0 - - - name: Identify target translation and template files - id: changed - env: - EVENT_NAME: ${{ github.event_name }} - PR_BASE_SHA: ${{ github.event.pull_request.base.sha }} - PUSH_BEFORE: ${{ github.event.before }} - run: | - set -euo pipefail - if [ "$EVENT_NAME" = "pull_request" ]; then - BASE="$PR_BASE_SHA" - else - BASE="$PUSH_BEFORE" - fi - - HAS_BASE="false" - if [ -n "$BASE" ] && git cat-file -e "${BASE}^{commit}" 2>/dev/null; then - HAS_BASE="true" - echo "base=$BASE" >> "$GITHUB_OUTPUT" - git diff --name-only --diff-filter=d "$BASE" HEAD > /tmp/changed_all.txt - else - git show --name-only --diff-filter=d --format="" HEAD > /tmp/changed_all.txt - fi - - WORKFLOW_CHANGED="false" - if grep -Fxq ".github/workflows/i18n-validation.yml" /tmp/changed_all.txt; then - WORKFLOW_CHANGED="true" - fi - echo "workflow_changed=$WORKFLOW_CHANGED" >> "$GITHUB_OUTPUT" - - if [ "$WORKFLOW_CHANGED" = "true" ]; then - git ls-files 'locales/po/*.po' > /tmp/target_po.txt - git ls-files 'locales/po/*.pot' > /tmp/target_pot.txt - elif [ "$HAS_BASE" = "true" ]; then - git diff --name-only --diff-filter=d "$BASE" HEAD -- 'locales/po/*.po' > /tmp/target_po.txt - git diff --name-only --diff-filter=d "$BASE" HEAD -- 'locales/po/*.pot' > /tmp/target_pot.txt - else - git show --name-only --diff-filter=d --format="" HEAD -- 'locales/po/*.po' > /tmp/target_po.txt - git show --name-only --diff-filter=d --format="" HEAD -- 'locales/po/*.pot' > /tmp/target_pot.txt - fi - - PO_COUNT=$(grep -c '.' /tmp/target_po.txt || true) - POT_COUNT=$(grep -c '.' /tmp/target_pot.txt || true) - echo "po_count=$PO_COUNT" >> "$GITHUB_OUTPUT" - echo "pot_count=$POT_COUNT" >> "$GITHUB_OUTPUT" - echo "Workflow changed: $WORKFLOW_CHANGED | Target .po: $PO_COUNT | Target .pot: $POT_COUNT" - cat /tmp/target_po.txt - cat /tmp/target_pot.txt - - - name: Write i18n validation script - run: | - cat <<'PYEOF' > /tmp/cacti_i18n_check.py - #!/usr/bin/env python3 - """Self-contained i18n validator for Cacti plugin .po and .pot catalogs.""" - - import argparse - from collections import Counter - from pathlib import Path - import re - import subprocess - import sys - import tempfile - - import polib - - DEVANAGARI_RE = re.compile(r'^(?:hi|mr|ne|sa)(?:[-_].*)?\.po$', re.IGNORECASE) - DANDA_TRAILING_RE = re.compile(r'\u0964(\s*)$') - HTML_TAG_RE = re.compile(r'<[^>]+>') - HTML_OPEN_CLOSE_RE = re.compile(r'<(/?)([a-z][a-z0-9]*)\b[^>]*?(/?)>', re.IGNORECASE) - - # Real non-void HTML element names (excludes Cacti tokens and void tags). - HTML_PAIRED_TAGS = { - 'a', 'abbr', 'b', 'blockquote', 'body', 'button', 'caption', 'code', - 'dd', 'del', 'details', 'dfn', 'div', 'dl', 'dt', 'em', 'fieldset', - 'figcaption', 'figure', 'font', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', - 'h6', 'head', 'header', 'html', 'i', 'ins', 'kbd', 'label', 'legend', - 'li', 'main', 'mark', 'nav', 'noscript', 'ol', 'optgroup', 'option', - 'p', 'pre', 'q', 's', 'samp', 'script', 'section', 'select', 'small', - 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', - 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'title', 'tr', 'tt', - 'u', 'ul', 'var', - } - - # Match printf-style placeholders matching Cacti/cacti#8970. - _CONVERSION = r'[bcdeEfFgGosuxX]' - _PLACEHOLDER_PARTS = re.compile( - r'%(?!%)' - r'(?:([0-9]+)\$)?' - r"[#0\-+']*" - r'(?:[0-9]+|\*)?' - r'(?:\.(?:[0-9]+|\*))?' - r'(?:hh|h|ll|l|L|z|j|t)?' - r'(' + _CONVERSION + r')' - ) - - # Literal '%' prose accidentally tagged php-format by xgettext (e.g. "'%'", "% for"). - LITERAL_PCT_PROSE_RE = re.compile(r"(? list[str]: - return [line.strip() for line in Path(path).read_text(encoding='utf-8').splitlines() if line.strip()] - - - def git_show_bytes(base: str, rel_path: str) -> bytes | None: - res = subprocess.run(['git', 'show', f'{base}:{rel_path}'], capture_output=True, check=False) - return res.stdout if res.returncode == 0 else None - - - def _normalize_msgfmt_errors(stderr: str) -> Counter[str]: - errs: Counter[str] = Counter() - for line in stderr.splitlines(): - s = line.strip() - if not s or 'translated message' in s or re.match(r'^msgfmt: found \d+ fatal error', s): - continue - # Strip file:line: prefix so unrelated line shifts do not mask baseline identity. - norm = re.sub(r'^[^:]+:\d+:\s*', '', s) - errs[norm] += 1 - return errs - - - def _run_msgfmt_file(path: str) -> tuple[int, str]: - res = subprocess.run(['msgfmt', '-c', '-v', '-o', '/dev/null', path], capture_output=True, text=True, check=False) - return res.returncode, res.stderr - - - def cmd_msgfmt(files: list[str], base: str | None) -> int: - failures = 0 - for rel in files: - rc, stderr = _run_msgfmt_file(rel) - if rc == 0: - print(f'OK [msgfmt] {rel}: {stderr.strip()}') - continue - cur_errs = _normalize_msgfmt_errors(stderr) - if base: - base_bytes = git_show_bytes(base, rel) - if base_bytes is not None: - with tempfile.TemporaryDirectory() as td: - bp = Path(td) / 'base.po' - bp.write_bytes(base_bytes) - brc, berr = _run_msgfmt_file(str(bp)) - if brc != 0: - new_errs = cur_errs - _normalize_msgfmt_errors(berr) - if not new_errs: - print(f'::warning file={rel}::Pre-existing msgfmt baseline issue(s) unchanged from base') - continue - print(f'ERROR [msgfmt] {rel}:\n{stderr.strip()}') - failures += 1 - return 1 if failures else 0 - - - def _normalize_danda_for_msgcheck(po_bytes: bytes, filename: str, dst: Path) -> None: - dst.write_bytes(po_bytes) - if not DEVANAGARI_RE.match(Path(filename).name): - return - po = polib.pofile(str(dst)) - changed = False - for entry in po: - if entry.obsolete: - continue - if entry.msgid and entry.msgid.rstrip().endswith('.'): - if entry.msgstr and DANDA_TRAILING_RE.search(entry.msgstr): - entry.msgstr = DANDA_TRAILING_RE.sub(r'.\1', entry.msgstr) - changed = True - if entry.msgid_plural and entry.msgstr_plural: - for idx, val in list(entry.msgstr_plural.items()): - ref = entry.msgid_plural if idx > 0 else entry.msgid - if ref and ref.rstrip().endswith('.') and val and DANDA_TRAILING_RE.search(val): - entry.msgstr_plural[idx] = DANDA_TRAILING_RE.sub(r'.\1', val) - changed = True - if changed: - po.save(str(dst)) - - - def _run_msgcheck_bytes(po_bytes: bytes, filename: str) -> Counter[str]: - with tempfile.TemporaryDirectory() as td: - tmp_po = Path(td) / Path(filename).name - _normalize_danda_for_msgcheck(po_bytes, filename, tmp_po) - res = subprocess.run(['msgcheck', '--no-lines', str(tmp_po)], capture_output=True, text=True, check=False) - if res.returncode == 0: - return Counter() - out = (res.stdout + '\n' + res.stderr).splitlines() - findings: Counter[str] = Counter() - for line in out: - s = line.strip() - if not s: - continue - norm = s.replace(str(tmp_po), filename) - findings[norm] += 1 - return findings or Counter({f'msgcheck exited with status {res.returncode}': 1}) - - - def cmd_msgcheck(files: list[str], base: str | None) -> int: - failures = 0 - for rel in files: - cur = _run_msgcheck_bytes(Path(rel).read_bytes(), rel) - if not cur: - print(f'OK [msgcheck] {rel}') - continue - if base: - base_bytes = git_show_bytes(base, rel) - if base_bytes is not None: - prev = _run_msgcheck_bytes(base_bytes, rel) - cur = cur - prev - if not cur: - print(f'::warning file={rel}::Pre-existing msgcheck baseline finding(s) unchanged from base') - continue - print(f'ERROR [msgcheck] {rel}:') - for msg, cnt in sorted(cur.items()): - print(f' ({cnt}x) {msg}') - failures += 1 - return 1 if failures else 0 - - - def _parse_placeholders(text: str) -> list[tuple[int | None, str, str]]: - cleaned = text.replace('%%', '') - parsed: list[tuple[int | None, str, str]] = [] - for m in _PLACEHOLDER_PARTS.finditer(cleaned): - pos = int(m.group(1)) if m.group(1) is not None else None - parsed.append((pos, m.group(2), m.group(0))) - return parsed - - - def _expected_arg_types(src: list[tuple[int | None, str, str]]) -> dict[int, str]: - types: dict[int, str] = {} - seq = 1 - for pos, conv, _ in src: - if pos is None: - idx = seq - seq += 1 - else: - idx = pos - types[idx] = conv - return types - - - def audit_pair(msgid: str, msgstr: str, loc: str) -> int: - errors = 0 - - # 1. HTML tag count parity - tags_id = HTML_TAG_RE.findall(msgid) - tags_str = HTML_TAG_RE.findall(msgstr) - if len(tags_id) != len(tags_str): - print( - f'ERROR [{loc}] HTML tag count mismatch: ' - f'msgid has {len(tags_id)}, msgstr has {len(tags_str)}' - f'\n msgid: {msgid[:80]}' - f'\n msgstr: {msgstr[:80]}' - ) - errors += 1 - - # 2. Printf-style placeholder parity and style consistency (Cacti/cacti#8970) - src = _parse_placeholders(msgid) - tgt = _parse_placeholders(msgstr) - - if tgt and not src: - print( - f'ERROR [{loc}] msgstr has format specifier(s) but msgid has none' - f'\n msgid: {msgid[:80]}' - f'\n msgstr: {msgstr[:80]}' - ) - return errors + 1 - - if src and not tgt: - print( - f'ERROR [{loc}] msgstr is missing format specifier(s): ' - f'msgid has {len(src)}, msgstr has 0' - f'\n msgid: {msgid[:80]}' - f'\n msgstr: {msgstr[:80]}' - ) - return errors + 1 - - if not src: - return errors - - src_types = _expected_arg_types(src) - positional_count = sum(1 for pos, _, _ in tgt if pos is not None) - - if 0 < positional_count < len(tgt): - print( - f'ERROR [{loc}] Mixed positional and non-positional placeholders in msgstr' - f'\n msgid: {msgid[:80]}' - f'\n msgstr: {msgstr[:80]}' - ) - return errors + 1 - - if positional_count == len(tgt): - max_idx = max(src_types) - out_of_range = [raw for pos, _, raw in tgt if pos is None or pos < 1 or pos not in src_types] - if out_of_range: - print( - f'ERROR [{loc}] Out-of-range positional placeholder(s) ' - f'{", ".join(out_of_range)} (expected 1..{max_idx})' - f'\n msgid: {msgid[:80]}' - f'\n msgstr: {msgstr[:80]}' - ) - errors += 1 - - type_mismatches = [ - f'{raw} (expected %{pos}${src_types[pos]})' - for pos, conv, raw in tgt - if pos is not None and pos in src_types and conv != src_types[pos] - ] - if type_mismatches: - print( - f'ERROR [{loc}] Positional placeholder type mismatch: {", ".join(type_mismatches)}' - f'\n msgid: {msgid[:80]}' - f'\n msgstr: {msgstr[:80]}' - ) - errors += 1 - - referenced = {pos for pos, _, _ in tgt if pos is not None} - missing = sorted(set(src_types) - referenced) - if missing: - missing_desc = ', '.join(f'%{idx}${src_types[idx]}' for idx in missing) - print( - f'ERROR [{loc}] Missing positional placeholder(s): {missing_desc}' - f'\n msgid: {msgid[:80]}' - f'\n msgstr: {msgstr[:80]}' - ) - errors += 1 - return errors - - if len(tgt) != len(src): - print( - f'ERROR [{loc}] Placeholder count mismatch: ' - f'msgid has {len(src)}, msgstr has {len(tgt)}' - f'\n msgid: {msgid[:80]}' - f'\n msgstr: {msgstr[:80]}' - ) - return errors + 1 - - src_convs = [conv for _, conv, _ in src] - tgt_convs = [conv for _, conv, _ in tgt] - if tgt_convs != src_convs: - print( - f'ERROR [{loc}] Placeholder type/order mismatch: ' - f'msgid has [{", ".join("%" + c for c in src_convs)}], ' - f'msgstr has [{", ".join("%" + c for c in tgt_convs)}]' - f'\n msgid: {msgid[:80]}' - f'\n msgstr: {msgstr[:80]}' - ) - errors += 1 - - return errors - - - def _entry_key(entry: polib.POEntry) -> tuple: - return (entry.msgctxt, entry.msgid, entry.msgid_plural) - - - def _entry_value(entry: polib.POEntry) -> tuple: - return (entry.msgstr, tuple(sorted(entry.msgstr_plural.items()))) - - - def _load_base_po_map(rel_path: str, base: str) -> dict[tuple, tuple] | None: - raw = git_show_bytes(base, rel_path) - if raw is None: - return None - with tempfile.TemporaryDirectory() as td: - p = Path(td) / 'base.po' - p.write_bytes(raw) - try: - po = polib.pofile(str(p)) - except (OSError, ValueError, UnicodeDecodeError): - return None - return {_entry_key(e): _entry_value(e) for e in po if not e.obsolete} - - - def cmd_audit_po(files: list[str], base: str | None) -> int: - total_errors = 0 - for rel in files: - po = polib.pofile(rel) - previous = _load_base_po_map(rel, base) if base else None - file_errors = 0 - for entry in po: - if entry.obsolete: - continue - if previous is not None and previous.get(_entry_key(entry)) == _entry_value(entry): - continue - loc = f'{rel}:{entry.linenum}' - if entry.msgstr: - file_errors += audit_pair(entry.msgid, entry.msgstr, loc) - if entry.msgid_plural and entry.msgstr_plural: - for idx, plural_str in sorted(entry.msgstr_plural.items()): - if not plural_str: - continue - source = entry.msgid_plural if idx > 0 else entry.msgid - file_errors += audit_pair(source, plural_str, f'{loc}[{idx}]') - total_errors += file_errors - if total_errors: - print(f'\n{total_errors} placeholder/HTML audit error(s) found.') - return 1 - print(f'OK [audit-po] {len(files)} file(s) passed.') - return 0 - - - def _has_unbalanced_html(text: str) -> list[str]: - stack: list[str] = [] - for m in HTML_OPEN_CLOSE_RE.finditer(text): - closing, tag, self_close = (m.group(1) == '/'), m.group(2).lower(), (m.group(3) == '/') - if self_close or tag not in HTML_PAIRED_TAGS: - continue - if not closing: - stack.append(tag) - elif stack and stack[-1] == tag: - stack.pop() - else: - return [f'unexpected '] - return [f'unclosed <{t}>' for t in stack] - - - def lint_pot_entry(entry: polib.POEntry) -> list[str]: - issues: list[str] = [] - if entry.msgid_plural: - if entry.msgid.rstrip().endswith('.') != entry.msgid_plural.rstrip().endswith('.'): - issues.append('mismatched trailing period between msgid and msgid_plural') - for field_name, text in (('msgid', entry.msgid), ('msgid_plural', entry.msgid_plural)): - if not text: - continue - html_errs = _has_unbalanced_html(text) - if html_errs: - issues.append(f'unbalanced HTML in {field_name}: {", ".join(html_errs)}') - if 'php-format' in entry.flags and 'no-php-format' not in entry.flags: - if LITERAL_PCT_PROSE_RE.search(entry.msgid or '') or LITERAL_PCT_PROSE_RE.search(entry.msgid_plural or ''): - issues.append('literal % prose marked php-format without no-php-format') - return issues - - - def cmd_lint_pot(files: list[str], base: str | None) -> int: - total_errors = 0 - for rel in files: - pot = polib.pofile(rel) - base_sigs: set[tuple] | None = None - if base: - raw = git_show_bytes(base, rel) - if raw is not None: - with tempfile.TemporaryDirectory() as td: - p = Path(td) / 'base.pot' - p.write_bytes(raw) - try: - bpot = polib.pofile(str(p)) - base_sigs = { - (e.msgctxt, e.msgid, e.msgid_plural, tuple(sorted(e.flags))) - for e in bpot if not e.obsolete - } - except (OSError, ValueError, UnicodeDecodeError): - base_sigs = None - baseline_warnings = 0 - for entry in pot: - if entry.obsolete or not entry.msgid: - continue - issues = lint_pot_entry(entry) - if not issues: - continue - sig = (entry.msgctxt, entry.msgid, entry.msgid_plural, tuple(sorted(entry.flags))) - if base_sigs is not None and sig in base_sigs: - baseline_warnings += 1 - continue - for iss in issues: - print(f'ERROR [{rel}:{entry.linenum}] {iss}\n msgid: {entry.msgid[:90]}') - total_errors += 1 - if baseline_warnings: - print(f'::warning file={rel}::{baseline_warnings} pre-existing POT lint issue(s) unchanged from base') - if total_errors: - print(f'\n{total_errors} POT lint error(s) found.') - return 1 - print(f'OK [lint-pot] {len(files)} file(s) passed.') - return 0 - - - def cmd_self_test() -> int: - # 1. Placeholder & HTML parity (Cacti/cacti#8970) - assert audit_pair('%s of %d', '%s de %d', 't') == 0 - assert audit_pair('%s has %d items', '%2$d Elemente in %1$s', 't') == 0 - assert audit_pair('Literal %%s and %s', 'Literal %%s och %s', 't') == 0 - assert audit_pair('Half of hosts', '50 % des hôtes', 't') == 0 - assert audit_pair('%s of %d', '%1$s de %d', 't') >= 1 - assert audit_pair('%s of %d', '%0$s de %1$d', 't') >= 1 - assert audit_pair('%s of %d', '%d de %s', 't') >= 1 - assert audit_pair('Hi', 'Hi', 't') >= 1 - - # 2. Devanagari-danda-safe msgcheck - hi_po = ( - 'msgid ""\nmsgstr ""\n' - '"Content-Type: text/plain; charset=UTF-8\\n"\n' - '"Language: hi-IN\\n"\n\n' - 'msgid "Save changes."\n' - 'msgstr "परिवर्तन सहेजें।"\n' - ).encode('utf-8') - assert not _run_msgcheck_bytes(hi_po, 'locales/po/hi-IN.po'), 'Devanagari danda should pass msgcheck' - - # 3. msgfmt syntax catch - bad_fmt = ( - 'msgid ""\nmsgstr ""\n' - '"Content-Type: text/plain; charset=UTF-8\\n"\n\n' - '#, php-format\nmsgid "Hello %s"\nmsgstr "Hello %d"\n' - ).encode('utf-8') - with tempfile.TemporaryDirectory() as td: - p = Path(td) / 'bad.po' - p.write_bytes(bad_fmt) - rc, _ = _run_msgfmt_file(str(p)) - assert rc != 0, 'msgfmt must reject format specifier mismatch' - - # 4. POT source-string lint - e_period = polib.POEntry(msgid='Delete item.', msgid_plural='Delete items') - assert any('trailing period' in x for x in lint_pot_entry(e_period)) - e_html = polib.POEntry(msgid='Hello world') - assert any('unbalanced HTML' in x for x in lint_pot_entry(e_html)) - e_cacti_ph = polib.POEntry(msgid='Device: ()
') - assert not lint_pot_entry(e_cacti_ph), 'Cacti tokens must not trip HTML balance check' - e_pct = polib.POEntry(msgid="SQL wildcard is '%' sign.", flags=['php-format']) - assert any('php-format' in x for x in lint_pot_entry(e_pct)) - e_pct_ok = polib.POEntry(msgid="SQL wildcard is '%' sign.", flags=['no-php-format']) - assert not lint_pot_entry(e_pct_ok) - - print('OK [self-test] All validator checks passed.') - return 0 - - - def main() -> int: - ap = argparse.ArgumentParser() - sub = ap.add_subparsers(dest='cmd', required=True) - sub.add_parser('self-test') - for name in ('msgfmt', 'msgcheck', 'audit-po', 'lint-pot'): - sp = sub.add_parser(name) - sp.add_argument('--base', default='') - sp.add_argument('--files-from', required=True) - args = ap.parse_args() - if args.cmd == 'self-test': - return cmd_self_test() - files = read_file_list(args.files_from) - if not files: - print(f'SKIP [{args.cmd}] No target files.') - return 0 - base = args.base or None - if args.cmd == 'msgfmt': - return cmd_msgfmt(files, base) - if args.cmd == 'msgcheck': - return cmd_msgcheck(files, base) - if args.cmd == 'audit-po': - return cmd_audit_po(files, base) - if args.cmd == 'lint-pot': - return cmd_lint_pot(files, base) - return 1 - - - if __name__ == '__main__': - sys.exit(main()) - PYEOF - - - name: Run validator self-test - if: steps.changed.outputs.workflow_changed == 'true' - run: python3 /tmp/cacti_i18n_check.py self-test - - - name: Run msgfmt syntax and format-string check - if: steps.changed.outputs.po_count != '0' - env: - BASE: ${{ steps.changed.outputs.base }} - run: python3 /tmp/cacti_i18n_check.py msgfmt --base "$BASE" --files-from /tmp/target_po.txt - - - name: Run Devanagari-safe msgcheck linter - if: steps.changed.outputs.po_count != '0' - env: - BASE: ${{ steps.changed.outputs.base }} - run: python3 /tmp/cacti_i18n_check.py msgcheck --base "$BASE" --files-from /tmp/target_po.txt - - - name: Run HTML and placeholder parity audit - if: steps.changed.outputs.po_count != '0' - env: - BASE: ${{ steps.changed.outputs.base }} - run: python3 /tmp/cacti_i18n_check.py audit-po --base "$BASE" --files-from /tmp/target_po.txt - - - name: Run POT source-string lint - if: steps.changed.outputs.pot_count != '0' - env: - BASE: ${{ steps.changed.outputs.base }} - run: python3 /tmp/cacti_i18n_check.py lint-pot --base "$BASE" --files-from /tmp/target_pot.txt + # The steps and scripts live in Cacti/cacti so every plugin runs the same checks. + uses: Cacti/cacti/.github/workflows/reusable-i18n-validation.yml@develop