From 68280833d2f2a52189cb22bd9851710c708d89fc Mon Sep 17 00:00:00 2001
From: 1okko <15377594951@189.cn>
Date: Mon, 15 Jun 2026 21:34:42 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20dragonpilot=E7=BF=BB=E8=AF=91=E8=87=AA?=
=?UTF-8?q?=E5=8A=A8=E7=BC=96=E8=AF=91=20.po=20->=20.mo=20&=20=E4=BF=AE?=
=?UTF-8?q?=E5=A4=8DPO=E8=AF=AD=E6=B3=95=E9=94=99=E8=AF=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
dragonpilot/system/ui/lib/multilang.py | 29 ++++++++++++++++++-
.../ui/translations/dragonpilot_zh-CHS.po | 4 +--
2 files changed, 30 insertions(+), 3 deletions(-)
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"