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

Co-authored-by: Peter Feerick <5500713+pfeerick@users.noreply.github.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Abhishek Praveenkumar Muttath
2026-08-12 07:23:18 +10:00
committed by GitHub
co-authored by Peter Feerick Claude Sonnet 5
parent 81db17e5a7
commit c8499366a2
2 changed files with 44 additions and 23 deletions
-1
View File
@@ -83,7 +83,6 @@
#define TR_MAIN_MENU_MODEL_SETTINGS "Editar Modelo" #define TR_MAIN_MENU_MODEL_SETTINGS "Editar Modelo"
#define TR_MAIN_MENU_RADIO_SETTINGS "Editar Rádio" #define TR_MAIN_MENU_RADIO_SETTINGS "Editar Rádio"
#define TR_MAIN_MENU_SCREEN_SETTINGS "Editar Tela" #define TR_MAIN_MENU_SCREEN_SETTINGS "Editar Tela"
#define TR_MAIN_MENU_RESET_TELEMETRY "Reset Telem."
#define TR_MAIN_MENU_STATISTICS "Estatist." #define TR_MAIN_MENU_STATISTICS "Estatist."
#define TR_MAIN_MENU_ABOUT_EDGETX "Sobre EdgeTX" #define TR_MAIN_MENU_ABOUT_EDGETX "Sobre EdgeTX"
#define TR_MAIN_VIEW_X "Screen " #define TR_MAIN_VIEW_X "Screen "
+31 -9
View File
@@ -61,6 +61,7 @@ class TranslationChecker:
current_language = None current_language = None
in_translation_block = False in_translation_block = False
conditional_depth = 0 conditional_depth = 0
past_translation_block = False
for i, line in enumerate(lines): for i, line in enumerate(lines):
line = line.strip() line = line.strip()
@@ -93,6 +94,19 @@ class TranslationChecker:
# This is the end of the translation block # This is the end of the translation block
in_translation_block = False in_translation_block = False
current_language = None current_language = None
past_translation_block = True
continue
# Past the language chain, a #define TR_BL_x is a fallback default
# (e.g. "#if !defined(COLORLCD) && !defined(TR_BL_X)") that fills the
# key in for every language that didn't already define it explicitly.
if past_translation_block:
define_match = re.match(r'#define\s+(TR_BL_\w+)', line)
if define_match:
key = define_match.group(1)
self.bootloader_keys.add(key)
for lang in self.bootloader_translations:
self.bootloader_translations[lang].add(key)
continue continue
# Skip non-translation lines # Skip non-translation lines
@@ -139,13 +153,10 @@ class TranslationChecker:
"""Check individual language translation files.""" """Check individual language translation files."""
languages_found = [] languages_found = []
# Look for .h files that are language files (excluding special files) # Language headers live under i18n/; translations_dir itself only has shared headers.
exclude_files = {"bl_translations.h", "untranslated.h"} i18n_dir = translations_dir / "i18n"
for h_file in translations_dir.glob("*.h"):
if h_file.name in exclude_files:
continue
for h_file in i18n_dir.glob("*.h"):
# Skip files that are clearly not language files # Skip files that are clearly not language files
if h_file.name.startswith("tts_"): if h_file.name.startswith("tts_"):
continue continue
@@ -190,11 +201,13 @@ class TranslationChecker:
"extra": len(results["bootloader"]["extra_keys"][lang]) "extra": len(results["bootloader"]["extra_keys"][lang])
} }
# Analyze language file translations # Diff against EN rather than the union: unlike bl_translations.h, i18n/*.h
# has no fallback macros, so a key EN lacks is genuinely extra elsewhere.
language_reference = self.language_translations.get("EN", self.language_keys)
for lang in language_languages: for lang in language_languages:
lang_keys = self.language_translations[lang] lang_keys = self.language_translations[lang]
results["language_files"]["missing_keys"][lang] = self.language_keys - lang_keys results["language_files"]["missing_keys"][lang] = language_reference - lang_keys
results["language_files"]["extra_keys"][lang] = lang_keys - self.language_keys results["language_files"]["extra_keys"][lang] = lang_keys - language_reference
results["language_files"]["summary"][lang] = { results["language_files"]["summary"][lang] = {
"total": len(lang_keys), "total": len(lang_keys),
"missing": len(results["language_files"]["missing_keys"][lang]), "missing": len(results["language_files"]["missing_keys"][lang]),
@@ -320,6 +333,15 @@ Examples:
args = parser.parse_args() args = parser.parse_args()
# The report uses Unicode status glyphs (checkmarks, crosses, bullets).
# Consoles that default to a non-UTF-8 encoding (e.g. Windows cp1252) would
# otherwise raise UnicodeEncodeError and crash the tool. Force UTF-8 output
# where the stream supports reconfiguration.
try:
sys.stdout.reconfigure(encoding="utf-8")
except (AttributeError, ValueError):
pass
checker = TranslationChecker() checker = TranslationChecker()
# Find translations directory # Find translations directory