Skip to content

fix(i18n): detect accidental python-format labels instead of listing them - #46580

Closed
antalotec wants to merge 1 commit into
apache:masterfrom
antalotec:fix/i18n-pseudo-format-flags
Closed

antalotec wants to merge 1 commit into
apache:masterfrom
antalotec:fix/i18n-pseudo-format-flags

Conversation

@antalotec

@antalotec antalotec commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

SUMMARY

Some UI labels parse as an accidentally valid %-format directive: a space flag plus a conversion character, so "% of" reads as % o (octal). Babel flags them python-format, and msgfmt --check then fatals on translations that don't keep that shape: German "% von" reads as % v, and the Chinese translations of these labels (#46129) carry no directive at all.

babel_update.sh and backfill_po.py each unflag three of these labels by name (% calculation, % of parent, % of total). Five more labels (% of, % of column, % of column total, % of grand total, % of row total) and three help texts mentioning "% of column" have the same shape and stay flagged. Two recent catalog PRs (#45931, #45674) unflagged them by hand, and every backfill run flags them again, because normalize_catalog only knows the three listed labels.

This PR moves the check into scripts/translations/unflag_pseudo_format.py and shares it between both writers. An entry is unflagged when every directive Babel's own PYTHON_FORMAT regex finds in its msgid (and msgid_plural) carries the space flag. Real placeholders (%s, %d, %(name)s) never do, and %% only appears in strings that are formatted, so a string holding either keeps the flag.

  • babel_update.sh runs the script after pybabel update and stops if it fails (|| exit 1). The script only rewrites #, lines, so canonical wrapping is untouched, and it handles msgids that pybabel folds across lines.
  • backfill_po.normalize_catalog uses the same is_pseudo_format check, so a backfill no longer re-flags these entries.
  • Applied to the template and catalogs: 238 #, lines (8 per catalog, 3 in it and none in pl, which were already fixed by hand, plus 11 in messages.pot).

Measured on master d2598e2:

before after
msgfmt --check (30 catalogs) 12 fatal 3
msgfmt --check --use-fuzzy 445 300
normalize_catalog on the fixed catalogs, then msgfmt --check 12 3

The 3 that remain are unrelated: Italian plurals whose singular form drops the %s.

Nothing users see changes: the flag is read by tooling only. The frontend JSON (po2json-cli.js) and the compiled .mo files (pybabel compile --use-fuzzy) come out byte-identical to master for all 30 catalogs.

TESTING INSTRUCTIONS

  • pytest tests/unit_tests/scripts/translations/.
    • unflag_pseudo_format_test.py covers the detection (accidental labels, real placeholders, mixed strings, plurals, %%) and the rewrite: only #, lines change, the step is idempotent, and msgfmt --check fails before and passes after.
    • babel_update_test.py runs the real script end to end: the template and catalogs come out unflagged, a real placeholder keeps its flag, and a failing unflag step makes the script exit non-zero.
    • backfill_po_test.py checks that normalize_catalog unflags the same labels, including a long msgid, and keeps real placeholders and plurals flagged.
  • msgfmt --check -o /dev/null superset/translations/zh/LC_MESSAGES/messages.po fails on master (8 fatal) and passes here.
  • Running ./scripts/translations/babel_update.sh on master and on this branch leaves only #, lines differing.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Introduces new feature or API
  • Removes existing feature or API

Developed at MYSPHERA, S.L.

@github-actions github-actions Bot added i18n Namespace | Anything related to localization i18n:spanish Translation related to Spanish language i18n:italian Translation related to Italian language i18n:french Translation related to French language i18n:chinese Translation related to Chinese language i18n:japanese Translation related to Japanese language i18n:german Translation related to German language i18n:russian Translation related to Russian language labels Nov 25, 2026
@codeant-ai-for-open-source

codeant-ai-for-open-source Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟢  Low Risk

  • The PR appears safe to merge; the affected entries are labels and help text, while real placeholders retain python-format validation.

Assessed commit: 8ceb2c25b665

@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.08%. Comparing base (d2598e2) to head (8ceb2c2).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #46580   +/-   ##
=======================================
  Coverage   86.08%   86.08%           
=======================================
  Files        3140     3140           
  Lines      219075   219083    +8     
  Branches    51919    51921    +2     
=======================================
+ Hits       188591   188601   +10     
+ Misses      27055    27054    -1     
+ Partials     3429     3428    -1     
Flag Coverage Δ
hive 33.69% <ø> (+<0.01%) ⬆️
mysql 51.47% <ø> (+0.03%) ⬆️
postgres 51.49% <ø> (+0.02%) ⬆️
presto 35.37% <ø> (+<0.01%) ⬆️
python 88.58% <ø> (+<0.01%) ⬆️
sqlite 51.18% <ø> (+0.03%) ⬆️
unit 84.13% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aminghadersohi aminghadersohi 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.

The new detection reproduces the committed catalogs, but backfill_po.py still re-adds the flag to the same entries.

Comment thread scripts/translations/babel_update.sh Resolved
Comment thread scripts/translations/babel_update.sh Resolved

@rusackas rusackas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @antalotec, detecting these beats growing the list by hand. +1 to @aminghadersohi's backfill_po.py point though, since the weekly backfill would put python-format right back on the new labels. Maybe normalize_catalog could share the same check?

GitHub shows conflicts now too, so it'll need a rebase.

…them

Labels such as "% of" parse as a valid %-format directive with a space
flag ("% o"), so Babel flags them python-format, and msgfmt then fatals
on any translation whose next letter is not a conversion character: the
German "% von" reads as "% v", and the Chinese translations of all
eight labels carry no directive at all. babel_update.sh and
backfill_po.py each unflag three of these by name, so the other five
labels and three help texts mentioning "% of column" stay flagged, and
every backfill re-flags what a catalog fixed by hand.

Move the check into scripts/translations/unflag_pseudo_format.py and
share it: an entry is unflagged when every directive Babel finds in its
msgid and msgid_plural carries the space flag. Real placeholders never
do, and %% only appears in strings that are formatted, so a string that
holds either stays flagged. babel_update.sh runs the script and stops if
it fails; backfill_po.normalize_catalog uses the same check. Apply it to
the template and the catalogs; only "#," lines change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@antalotec
antalotec force-pushed the fix/i18n-pseudo-format-flags branch from 167ac6e to 8ceb2c2 Compare November 26, 2026 10:07
@antalotec

Copy link
Copy Markdown
Contributor Author

Closing this as superseded by #46320, which landed the same fix (a shared check for babel_update.sh and backfill_po.py) and was opened first. I checked master after it: msgfmt --check is down to the same 3 unrelated Italian plural errors this PR reached, and its rule is slightly stricter than mine on % d. Thanks @aminghadersohi and @rusackas for the reviews.

@antalotec antalotec closed this Nov 27, 2026
@antalotec
antalotec deleted the fix/i18n-pseudo-format-flags branch November 27, 2026 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

i18n:arabic i18n:brazilian i18n:catalan i18n:chinese Translation related to Chinese language i18n:czech i18n:dutch i18n:finnish i18n:french Translation related to French language i18n:german Translation related to German language i18n:italian Translation related to Italian language i18n:japanese Translation related to Japanese language i18n:korean Translation related to Korean language i18n:latvian i18n:maori i18n:persian i18n:portuguese i18n:romanian i18n:russian Translation related to Russian language i18n:serbian i18n:serbian-latin i18n:slovak i18n:slovenian i18n:spanish Translation related to Spanish language i18n:tamil i18n:thai i18n:traditional-chinese i18n:turkish i18n:ukrainian i18n Namespace | Anything related to localization risk:ci-script PR modifies scripts that execute in CI (supply chain risk) size/XXL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants