rev
pull/36410/head
Shane Smiskol 5 days ago
parent 1c047cd3e3
commit f64a5bd1bb
  1. 17
      selfdrive/ui/layouts/settings/device.py
  2. 2
      selfdrive/ui/translations/app_de.po
  3. 24
      selfdrive/ui/translations/languages.json
  4. 6
      selfdrive/ui/update_translations_raylib.py
  5. 8
      system/ui/lib/multilang.py
  6. 2
      system/ui/widgets/option_dialog.py

@ -12,6 +12,7 @@ from openpilot.selfdrive.ui.layouts.onboarding import TrainingGuide
from openpilot.selfdrive.ui.widgets.pairing_dialog import PairingDialog from openpilot.selfdrive.ui.widgets.pairing_dialog import PairingDialog
from openpilot.system.hardware import TICI from openpilot.system.hardware import TICI
from openpilot.system.ui.lib.application import gui_app from openpilot.system.ui.lib.application import gui_app
from openpilot.system.ui.lib.multilang import LANGUAGES_FILE, tr
from openpilot.system.ui.widgets import Widget, DialogResult from openpilot.system.ui.widgets import Widget, DialogResult
from openpilot.system.ui.widgets.confirm_dialog import ConfirmDialog, alert_dialog from openpilot.system.ui.widgets.confirm_dialog import ConfirmDialog, alert_dialog
from openpilot.system.ui.widgets.html_render import HtmlModal from openpilot.system.ui.widgets.html_render import HtmlModal
@ -21,10 +22,10 @@ from openpilot.system.ui.widgets.scroller import Scroller
# Description constants # Description constants
DESCRIPTIONS = { DESCRIPTIONS = {
'pair_device': "Pair your device with comma connect (connect.comma.ai) and claim your comma prime offer.", 'pair_device': tr("Pair your device with comma connect (connect.comma.ai) and claim your comma prime offer."),
'driver_camera': "Preview the driver facing camera to ensure that driver monitoring has good visibility. (vehicle must be off)", 'driver_camera': tr("Preview the driver facing camera to ensure that driver monitoring has good visibility. (vehicle must be off)"),
'reset_calibration': "openpilot requires the device to be mounted within 4° left or right and within 5° up or 9° down.", 'reset_calibration': tr("openpilot requires the device to be mounted within 4° left or right and within 5° up or 9° down."),
'review_guide': "Review the rules, features, and limitations of openpilot", 'review_guide': tr("Review the rules, features, and limitations of openpilot"),
} }
@ -84,14 +85,14 @@ class DeviceLayout(Widget):
def handle_language_selection(result: int): def handle_language_selection(result: int):
if result == 1 and self._select_language_dialog: if result == 1 and self._select_language_dialog:
selected_language = self._select_language_dialog.selection selected_language = self._select_language_dialog.selection
print("Selected language:", selected_language) print("Selected language:", languages[selected_language])
self._params.put("LanguageSetting", selected_language) self._params.put("LanguageSetting", languages[selected_language])
self._select_language_dialog = None self._select_language_dialog = None
try: try:
languages_file = os.path.join(BASEDIR, "selfdrive/ui/translations/languages.json") # TODO: get from multilang file
with open(languages_file, encoding='utf-8') as f: with open(LANGUAGES_FILE, encoding='utf-8') as f:
languages = json.load(f) languages = json.load(f)
self._select_language_dialog = MultiOptionDialog("Select a language", languages) self._select_language_dialog = MultiOptionDialog("Select a language", languages)

@ -20,7 +20,7 @@ msgstr ""
#: /home/batman/openpilot/selfdrive/ui/widgets/prime.py:33 #: /home/batman/openpilot/selfdrive/ui/widgets/prime.py:33
#, python-format #, python-format
msgid "Upgrade Now" msgid "Upgrade Now"
msgstr "" msgstr "Opgrader nu"
#: /home/batman/openpilot/selfdrive/ui/widgets/prime.py:38 #: /home/batman/openpilot/selfdrive/ui/widgets/prime.py:38
#, python-format #, python-format

@ -1,14 +1,14 @@
{ {
"English": "main_en", "English": "en",
"Deutsch": "main_de", "Deutsch": "de",
"Français": "main_fr", "Français": "fr",
"Português": "main_pt-BR", "Português": "pt-BR",
"Español": "main_es", "Español": "es",
"Türkçe": "main_tr", "Türkçe": "tr",
"العربية": "main_ar", "العربية": "ar",
"ไทย": "main_th", "ไทย": "th",
"中文(繁體)": "main_zh-CHT", "中文(繁體)": "zh-CHT",
"中文(简体)": "main_zh-CHS", "中文(简体)": "zh-CHS",
"한국어": "main_ko", "한국어": "ko",
"日本語": "main_ja" "日本語": "ja"
} }

@ -3,11 +3,7 @@ import argparse
import json import json
import os import os
from openpilot.common.basedir import BASEDIR from openpilot.system.ui.lib.multilang import UI_DIR, TRANSLATIONS_DIR, LANGUAGES_FILE
UI_DIR = os.path.join(BASEDIR, "selfdrive", "ui")
TRANSLATIONS_DIR = os.path.join(UI_DIR, "translations")
LANGUAGES_FILE = os.path.join(TRANSLATIONS_DIR, "languages.json")
def update_translations(): def update_translations():

@ -5,9 +5,14 @@ from openpilot.common.params import Params
from openpilot.common.basedir import BASEDIR from openpilot.common.basedir import BASEDIR
UI_DIR = os.path.join(BASEDIR, "selfdrive", "ui")
TRANSLATIONS_DIR = os.path.join(UI_DIR, "translations")
LANGUAGES_FILE = os.path.join(TRANSLATIONS_DIR, "languages.json")
class Multilang: class Multilang:
def __init__(self): def __init__(self):
self._language: str = "main_en" self._language: str = "en"
self._translations: dict[str, dict[str, str]] = {} self._translations: dict[str, dict[str, str]] = {}
self._load_languages() self._load_languages()
@ -27,6 +32,7 @@ class Multilang:
pass pass
def _get_translated_text(self, text: str) -> str: def _get_translated_text(self, text: str) -> str:
# print("Translating:", text, "to", self._language, self._translations.keys())
if self._language not in self._translations: if self._language not in self._translations:
return text return text
return self._translations[self._language].get(text, text) return self._translations[self._language].get(text, text)

@ -27,7 +27,7 @@ class MultiOptionDialog(Widget):
# Create scroller with option buttons # Create scroller with option buttons
self.option_buttons = [Button(option, click_callback=lambda opt=option: self._on_option_clicked(opt), self.option_buttons = [Button(option, click_callback=lambda opt=option: self._on_option_clicked(opt),
text_alignment=rl.GuiTextAlignment.TEXT_ALIGN_LEFT, button_style=ButtonStyle.NORMAL, text_alignment=rl.GuiTextAlignment.TEXT_ALIGN_LEFT, button_style=ButtonStyle.NORMAL,
text_padding=50, elide_right=True) for option in options] text_padding=50) for option in options]
self.scroller = Scroller(self.option_buttons, spacing=LIST_ITEM_SPACING) self.scroller = Scroller(self.option_buttons, spacing=LIST_ITEM_SPACING)
self.cancel_button = Button("Cancel", click_callback=lambda: self._set_result(DialogResult.CANCEL)) self.cancel_button = Button("Cancel", click_callback=lambda: self._set_result(DialogResult.CANCEL))

Loading…
Cancel
Save