mirror of
https://github.com/apache/superset.git
synced 2026-05-22 00:05:15 +00:00
A fresh test run on French exposed a real bug in _apply_translation: when the model returns a JSON list for a plural entry (e.g. ["form0", "form1"], which is a valid representation since plural forms are ordered), the previous code took the else branch and broadcast str(list) — Python list-repr like ['form0', 'form1'] — to every plural form. Both msgstr[0] and msgstr[1] ended up containing the same literal Python list-repr string, breaking gettext lookups for that entry. Spanish dodged it by chance (the model returned dicts that time); the failure mode is reproducible on French. Changes: - Extract _apply_plural_translation helper. Handles dict, list, scalar, and non-JSON-string responses. List path distributes forms by index and repeats the last form if the model returned fewer forms than the language requires (better than leaving slots blank, which falls back to displaying the raw English msgid). - The split also drops _apply_translation's cyclomatic complexity back below the C901 threshold. - Adds 4 regression tests covering: list response, list response round-tripped through parse_response, list shorter than required forms (last-form-repeats), and empty list (falls back to raw-string broadcast). Verified end-to-end on French: the previously-broken plural entry "Added 1 new column to the virtual dataset" / "Added %s new columns to the virtual dataset" now writes msgstr[0] and msgstr[1] correctly on a fresh run. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>