fix(tools): update check_translations to i18n structure, utf-8 terminal encoding - #7636
Conversation
I have no problem with 4476f55 - the script was primarily intended to be run inside the build container, but if it can be run native on windows without obtuse errors with a minor tweak like that - fantastic! |
The translation report prints Unicode status glyphs (checkmarks, crosses and bullets). On consoles whose default encoding is not UTF-8 (notably Windows cp1252) printing these raised UnicodeEncodeError and aborted the run before the report finished. Reconfigure stdout to UTF-8 when the stream supports it so the tool runs consistently across platforms and CI environments.
check_translations.py (added in EdgeTX#6396) globbed *.h directly under radio/src/translations/ to find per-language files. PR EdgeTX#6502 later restructured that directory: real language headers (en.h, de.h, ...) moved into a new i18n/ subdirectory, and new shared/derived headers (translation_def.h, string_list.h, sim_string_list.h, translations.h) were added at the top level. The checker was never updated to match. As a result, the "Language File Translations" report found zero real languages, and instead misdetected translation_def.h - which defines ~120 array-selector macros like TR_MULTI_PROTOCOLS, not per-language strings - as a bogus language named TRANSLATION_DEF. Scan translations_dir/i18n instead, where the real per-language files now live. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The bootloader file has a one-off fallback macro (see bl_translations.h:430-432) outside any per-language block, so no single key-set comparison (union or reference) is sound for it - that's why the earlier EN-reference attempt at this in dbe55a9 was reverted for the bootloader section. The i18n/*.h language headers have no such fallback: each language is a flat, independent set of #define TR_x macros, and EN is where keys originate. Diffing each language against EN (instead of the union of all languages, which can never produce "extra" keys) correctly surfaces real drift, e.g. pt.h still defines the long-removed TR_MAIN_MENU_RESET_TELEMETRY - unused anywhere in radio/src and absent from every other language - which now reports as an Extra key for PT instead of a false Missing key for the other 18 languages. Bootloader section is unchanged (still union-based). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
bl_translations.h has a fallback pattern for TR_BL_OR_PLUGIN_USB_CABLE: a #define outside the per-language #if/elif/.../else chain, guarded by "#if !defined(...) && !defined(TR_BL_X)", that fills the key in for any language that didn't explicitly override it. The checker previously only understood #define statements inside the per-language chain, so it reported this key as "Extra" for DE (the only language with an explicit override) even though every other language gets it too, via the fallback. Once the per-language chain closes, treat any further #define TR_BL_x as a fallback default and add it to every already-seen language's key set. This is pattern-based rather than hardcoded to the one key that exists today, so it holds if another such fallback is added later. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…pt.h This key was removed from en.h (and every other language) back in EdgeTX#5685, but survived unchanged in pt.h through the EdgeTX#6502 directory restructuring and wasn't caught by the later EdgeTX#7590 string cleanup pass - likely because check_translations.py's extra-key detection was broken (see the preceding commits in this branch) at the time, so a tool-assisted review wouldn't have flagged it. It isn't referenced anywhere in radio/src outside the translation headers, so it's dead weight only in pt.h. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
4476f55 to
e27ff8a
Compare
|
Rebased and reworked this branch (force-pushed):
|
Fixes #7637
Summary of changes:
union of all keys, so extra keys are now correctly detected.
sys.stdout.reconfigure(encoding="utf-8")at startup to preventUnicodeEncodeErroron Windows cp1252 consoles.