mirror of
https://github.com/apache/superset.git
synced 2026-07-16 11:46:09 +00:00
feat(i18n): skip do-not-translate entries in backfill_po
The backfill only checked for an empty msgstr, so it filled entries a human translator had deliberately left blank — e.g. the ru catalog's "# Не переводить" (do-not-translate) markers on literal tokens. This translated strings that must stay identical to the source: icon names (`bolt` -> the ⚡ Explore control icon), d3 enum values (`step-after`/`step-before`), API field names (`error_message`), SQL keywords, code constants, and example placeholders. Add `_is_do_not_translate`, consulted when collecting untranslated entries. An entry is skipped if its msgid is in the curated `DO_NOT_TRANSLATE` set (seeded from the ru translator's markers; language-independent) or if it carries an explicit do-not-translate translator comment in any catalog. Skipped entries are reported and left untranslated (source-token fallback). Adds unit tests for the curated set, translator-comment honoring (incl. the Cyrillic marker), and the normal-entry pass-through. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -436,3 +436,29 @@ def test_resilient_translate_propagates_runtime_error(
|
||||
monkeypatch.setattr(backfill_po, "translate_batch", _boom)
|
||||
with pytest.raises(RuntimeError):
|
||||
backfill_po._resilient_translate("m", "fr", [_qitem("Alpha")], {})
|
||||
|
||||
|
||||
# --- _is_do_not_translate: never machine-fill literal tokens -------------------
|
||||
|
||||
|
||||
def test_is_do_not_translate_curated_msgid() -> None:
|
||||
"""A msgid in the curated DO_NOT_TRANSLATE set is protected (icon names,
|
||||
enum values, SQL keywords, API field names, placeholders)."""
|
||||
for msgid in ("bolt", "error_message", "step-after", "GROUP BY"):
|
||||
assert backfill_po._is_do_not_translate(polib.POEntry(msgid=msgid, msgstr=""))
|
||||
|
||||
|
||||
def test_is_do_not_translate_honors_translator_comment() -> None:
|
||||
"""An explicit do-not-translate translator comment is honored, in any
|
||||
language (e.g. the ru catalog's Cyrillic marker) and phrasing."""
|
||||
for comment in ("Не переводить", "do not translate", "DO-NOT-TRANSLATE"):
|
||||
entry = polib.POEntry(msgid="Some label", msgstr="")
|
||||
entry.tcomment = comment
|
||||
assert backfill_po._is_do_not_translate(entry)
|
||||
|
||||
|
||||
def test_is_do_not_translate_allows_normal_entry() -> None:
|
||||
"""An ordinary translatable string is not flagged."""
|
||||
entry = polib.POEntry(msgid="Save dashboard", msgstr="")
|
||||
entry.tcomment = "Machine-translated via backfill_po.py (claude-x) [no refs]"
|
||||
assert not backfill_po._is_do_not_translate(entry)
|
||||
|
||||
Reference in New Issue
Block a user