Skip to content

ci: compare i18n strings via tokenizer instead of diff lines - #39

Merged
cigamit merged 1 commit into
developfrom
ci/i18n-pot-tokenizer
Oct 5, 2026
Merged

cigamit merged 1 commit into
developfrom
ci/i18n-pot-tokenizer

Conversation

@TheWitness

Copy link
Copy Markdown
Member

What

Replaces the diff-line scan in tests/bin/check-i18n-pot.php with a tokenizer-based comparison.

Why

The current script (shared across the plugin fleet) scans the unified diff line by line and compares whole normalised lines containing an i18n call. That is both too loose and too strict:

  • False positive — changing unrelated code on a line that also holds an i18n call (e.g. a width argument next to __()) demands a cacti.pot update even though the translatable string is unchanged.
  • False negative — a multi-line call whose string literal sits on its own line is missed, so changing the string slips through.

How

For the merge-base and for HEAD, tokenize every template-feeding PHP file (the same find . -maxdepth 2 -name '*.php' set build_gettext.sh scans), find the Cacti i18n helper calls, and collect the literal string arguments that actually form each pot entry — msgctxt/msgid/plural per the xgettext -k spec (__ __n:1,2 __x:1c,2 __xn:1c,2,3 __esc …). A call only contributes when those positions are constant strings, mirroring what xgettext can extract. If the extracted set differs between base and HEAD, locales/po/cacti.pot must be part of the PR.

Because it reads whole files via the tokenizer rather than diff lines, surrounding-code edits and quote-style-only changes no longer trigger it, multi-line calls are handled correctly, and method calls/declarations ($o->__(), C::__(), function __) are excluded.

Validation

Same fix as plugin_reportit#150, where it was validated against an 8-case scenario matrix (both bug classes plus the original intended behaviors) with php -l clean. This PR is the fleet-wide propagation of that fix; the script is byte-identical across repos.

Replace the diff-line scan in tests/bin/check-i18n-pot.php, which had
false-positive and false-negative cases, with a tokenizer-based
comparison. For the merge-base and for HEAD it tokenizes every
template-feeding PHP file (the find . -maxdepth 2 set build_gettext.sh
scans), finds the Cacti i18n helper calls, and collects the literal
string arguments that actually form each pot entry (msgctxt/msgid/plural
per the xgettext -k spec). A call only contributes when those positions
are constant strings, mirroring xgettext. If the extracted set differs
between base and HEAD, locales/po/cacti.pot must be part of the PR.

Reading whole files rather than diff lines means surrounding-code edits
and quote-style-only changes no longer trigger it, and multi-line calls
are handled correctly.

Same fix validated in plugin_reportit #150.
Copilot AI balanced review requested due to automatic review settings October 5, 2026 17:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request. Check if the Files changed in this pull request are included in default exclusions.

@cigamit
cigamit merged commit 37b2805 into develop Oct 5, 2026
3 checks passed
@cigamit
cigamit deleted the ci/i18n-pot-tokenizer branch October 5, 2026 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants