diff --git a/dragonpilot/system/ui/lib/multilang.py b/dragonpilot/system/ui/lib/multilang.py index 1f9c4c41..638ce09b 100644 --- a/dragonpilot/system/ui/lib/multilang.py +++ b/dragonpilot/system/ui/lib/multilang.py @@ -1,4 +1,6 @@ import gettext +import os +import subprocess from openpilot.system.ui.lib.multilang import ( multilang as base_multilang, TRANSLATIONS_DIR, @@ -28,10 +30,35 @@ class DpMultilang: current_lang = base_multilang.language if current_lang != self._loaded_language: self._loaded_language = current_lang + mo_path = TRANSLATIONS_DIR.joinpath(f'dragonpilot_{current_lang}.mo') + po_path = TRANSLATIONS_DIR.joinpath(f'dragonpilot_{current_lang}.po') try: - with TRANSLATIONS_DIR.joinpath(f'dragonpilot_{current_lang}.mo').open('rb') as fh: + with mo_path.open('rb') as fh: self._dragon_translation = gettext.GNUTranslations(fh) except FileNotFoundError: + # Auto-compile .po to .mo if source exists + if po_path.exists(): + try: + # Try msgfmt first (faster, available on device) + result = subprocess.run(['msgfmt', str(po_path), '-o', str(mo_path)], capture_output=True) + if result.returncode == 0 and mo_path.exists(): + with mo_path.open('rb') as fh: + self._dragon_translation = gettext.GNUTranslations(fh) + return + except FileNotFoundError: + pass + # Fallback: try polib + try: + import polib + po = polib.pofile(str(po_path)) + po.save_as_mofile(str(mo_path)) + with mo_path.open('rb') as fh: + self._dragon_translation = gettext.GNUTranslations(fh) + return + except ImportError: + pass + except Exception: + pass self._dragon_translation = gettext.NullTranslations() def tr(self, text: str) -> str: diff --git a/selfdrive/ui/translations/dragonpilot_zh-CHS.po b/selfdrive/ui/translations/dragonpilot_zh-CHS.po index 1e65ba9f..e6c3ff1a 100644 --- a/selfdrive/ui/translations/dragonpilot_zh-CHS.po +++ b/selfdrive/ui/translations/dragonpilot_zh-CHS.po @@ -169,7 +169,7 @@ msgstr "道路边缘检测 (RED)" #: dragonpilot/settings/min-feat.lat.road-edge-detection.py msgid "Block lane change assist when the system detects the road edge.
NOTE: This will show 'Car Detected in Blindspot' warning." -msgstr "当系统检测到道路边缘时阻止变道辅助。
注意:将显示"检测到盲区车辆"警告。" +msgstr "当系统检测到道路边缘时阻止变道辅助。
注意:将显示\"检测到盲区车辆\"警告。" #: dragonpilot/settings/min-feat.lon.acm.py msgid "Enable Adaptive Coasting Mode (ACM)" @@ -193,7 +193,7 @@ msgstr "自适应驾驶风格模式 (APM)" #: dragonpilot/settings/min-feat.lon.apm.py msgid "Automatically switches personality to \"Aggressive\" below 30 km/h and restores your selected personality above 40 km/h." -msgstr "车速低于 30 km/h 时自动切换为"激进"风格,高于 40 km/h 时恢复你选择的风格。" +msgstr "车速低于 30 km/h 时自动切换为\"激进\"风格,高于 40 km/h 时恢复你选择的风格。" #: dragonpilot/settings/min-feat.lon.ext-radar.py msgid "Use External Radar"