Skip to content

fix(tools): update check_translations to i18n structure, utf-8 terminal encoding - #7636

Merged
pfeerick merged 5 commits into
EdgeTX:mainfrom
ABHISHEK22415:fix/check-translations-extra-keys-and-unicode
Aug 11, 2026
Merged

fix(tools): update check_translations to i18n structure, utf-8 terminal encoding#7636
pfeerick merged 5 commits into
EdgeTX:mainfrom
ABHISHEK22415:fix/check-translations-extra-keys-and-unicode

Conversation

@ABHISHEK22415

@ABHISHEK22415 ABHISHEK22415 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #7637

Summary of changes:

  • Compare each language against the English reference instead of the
    union of all keys, so extra keys are now correctly detected.
  • Call sys.stdout.reconfigure(encoding="utf-8") at startup to prevent
    UnicodeEncodeError on Windows cp1252 consoles.

@pfeerick

Copy link
Copy Markdown
Member

The "Extra" column always shows 0 for every language, even when a key
exists in one language but not others. For example, TR_BL_OR_PLUGIN_USB_CABLE
exists only in German (DE), but DE shows Extra: 0. Instead, that key gets
incorrectly reported as "missing" from every other language including English,
which is the reference language.

TR_BL_OR_PLUGIN_USB_CABLE is not specifically defined for EN, it is only the assembled form. So it is "missing" from EN, and every other language except for DE, as DE is the only one that explicitly provides a translated form. So the dbe55a9 portion of this is invalid IMO.

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!

ABHISHEK22415 and others added 5 commits August 11, 2026 08:45
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>
@pfeerick
pfeerick force-pushed the fix/check-translations-extra-keys-and-unicode branch from 4476f55 to e27ff8a Compare August 11, 2026 09:00
@pfeerick

pfeerick commented Aug 11, 2026

Copy link
Copy Markdown
Member

Rebased and reworked this branch (force-pushed):

  • Dropped the original "detect extra translation keys against a reference language" commit — its premise was wrong. TR_BL_OR_PLUGIN_USB_CABLE isn't actually missing from other languages; bl_translations.h:430-432 supplies it via a fallback macro outside the per-language block, which a static key diff (union or EN-reference) can't represent either way. - Generalized the bootloader parser to recognize fallback-default #defines outside the per-language chain (not hardcoded to the one key), so it no longer flags DE's TR_BL_OR_PLUGIN_USB_CABLE as "extra".
  • Added a fix for a separate, newly-discovered bug: check_translations.py still globbed radio/src/translations/*.h directly, but chore: improve translation string management #6502 moved the real per-language files into i18n/ and added shared headers (translation_def.h etc.) at the top level — so the checker found zero real languages and misreported translation_def.h's ~120 array-selector macros as a bogus language called TRANSLATION_DEF.
  • Re-added EN-reference diffing, but scoped only to the i18n/*.h language files (which have no fallback-macro complication), keeping the bootloader section union-based. This correctly surfaced a real orphaned key, TR_MAIN_MENU_RESET_TELEMETRY, defined only in pt.h and unused anywhere else — so removed.

@pfeerick pfeerick added bug/regression ↩️ A new version of EdgeTX broke something house keeping 🧹 Cleanup of code and house keeping backport/2.12 To be backported to a 2.12 release also. labels Aug 11, 2026
@pfeerick pfeerick added this to the 2.12.3 milestone Aug 11, 2026
@pfeerick pfeerick changed the title Fix/check translations extra keys and unicode fix(tools): update check_translations to i18n structure, utf-8 terminal encoding Aug 11, 2026
@pfeerick
pfeerick merged commit c849936 into EdgeTX:main Aug 11, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/2.12 To be backported to a 2.12 release also. bug/regression ↩️ A new version of EdgeTX broke something house keeping 🧹 Cleanup of code and house keeping

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tools/check_translations.py: extra-key detection always returns zero and crashes on Windows

2 participants