From e7e2d2c2412f884ea2a396c848a3fb850526ed55 Mon Sep 17 00:00:00 2001 From: Comma Device Date: Sun, 16 Aug 2026 15:35:58 +0800 Subject: [PATCH] ui: make menu item titles/descriptions live-translate (lambda tr) so language switch applies immediately --- .../ui/sunnypilot/layouts/settings/cruise.py | 20 ++++++++-------- .../ui/sunnypilot/layouts/settings/models.py | 4 ++-- .../steering_sub_layouts/torque_settings.py | 2 +- .../sunnypilot/layouts/settings/sunnylink.py | 24 +++++++++---------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/openpilot/selfdrive/ui/sunnypilot/layouts/settings/cruise.py b/openpilot/selfdrive/ui/sunnypilot/layouts/settings/cruise.py index f34c90d68..d6c12c8ae 100644 --- a/openpilot/selfdrive/ui/sunnypilot/layouts/settings/cruise.py +++ b/openpilot/selfdrive/ui/sunnypilot/layouts/settings/cruise.py @@ -43,34 +43,34 @@ class CruiseLayout(Widget): def _initialize_items(self): self.icbm_toggle = toggle_item_sp( - title=tr("Intelligent Cruise Button Management (ICBM) (Alpha)"), + title=lambda: tr("Intelligent Cruise Button Management (ICBM) (Alpha)"), description="", param="IntelligentCruiseButtonManagement") self.scc_v_toggle = toggle_item_sp( - title=tr("Smart Cruise Control - Vision"), - description=tr("Use vision path predictions to estimate the appropriate speed to drive through turns ahead."), + title=lambda: tr("Smart Cruise Control - Vision"), + description=lambda: tr("Use vision path predictions to estimate the appropriate speed to drive through turns ahead."), param="SmartCruiseControlVision") self.scc_m_toggle = toggle_item_sp( - title=tr("Smart Cruise Control - Map"), - description=tr("Use map data to estimate the appropriate speed to drive through turns ahead."), + title=lambda: tr("Smart Cruise Control - Map"), + description=lambda: tr("Use map data to estimate the appropriate speed to drive through turns ahead."), param="SmartCruiseControlMap") self.custom_acc_toggle = toggle_item_sp( - title=tr("Custom ACC Speed Increments"), + title=lambda: tr("Custom ACC Speed Increments"), description="", param="CustomAccIncrementsEnabled", callback=self._on_custom_acc_toggle) self.custom_acc_short_increment = option_item_sp( - title=tr("Short Press Increment"), + title=lambda: tr("Short Press Increment"), param="CustomAccShortPressIncrement", min_value=1, max_value=10, value_change_step=1, inline=True) self.custom_acc_long_increment = option_item_sp( - title=tr("Long Press Increment"), + title=lambda: tr("Long Press Increment"), param="CustomAccLongPressIncrement", value_map={1: 1, 2: 5, 3: 10}, min_value=1, max_value=3, value_change_step=1, @@ -83,8 +83,8 @@ class CruiseLayout(Widget): ) self.dec_toggle = toggle_item_sp( - title=tr("Enable Dynamic Experimental Control"), - description=tr("Enable toggle to allow the model to determine when to use sunnypilot ACC or sunnypilot End to End Longitudinal."), + title=lambda: tr("Enable Dynamic Experimental Control"), + description=lambda: tr("Enable toggle to allow the model to determine when to use sunnypilot ACC or sunnypilot End to End Longitudinal."), param="DynamicExperimentalControl") items = [ diff --git a/openpilot/selfdrive/ui/sunnypilot/layouts/settings/models.py b/openpilot/selfdrive/ui/sunnypilot/layouts/settings/models.py index a7f0b9a04..22b4f3a86 100644 --- a/openpilot/selfdrive/ui/sunnypilot/layouts/settings/models.py +++ b/openpilot/selfdrive/ui/sunnypilot/layouts/settings/models.py @@ -50,7 +50,7 @@ class ModelsLayout(Widget): def _initialize_items(self): self.current_model_item = ListItemSP( - title=tr("Current Model"), + title=lambda: tr("Current Model"), description="", action_item=NoElideButtonAction(tr("SELECT")), callback=self._handle_current_model_clicked @@ -68,7 +68,7 @@ class ModelsLayout(Widget): gui_app.push_widget(alert_dialog(tr("Fetching Latest Models"))))) self.clear_cache_item = ListItemSP( - title=tr("Clear Model Cache"), + title=lambda: tr("Clear Model Cache"), description="", action_item=NoElideButtonAction(tr("CLEAR")), callback=self._clear_cache diff --git a/openpilot/selfdrive/ui/sunnypilot/layouts/settings/steering_sub_layouts/torque_settings.py b/openpilot/selfdrive/ui/sunnypilot/layouts/settings/steering_sub_layouts/torque_settings.py index 6dae8308c..c10868a68 100644 --- a/openpilot/selfdrive/ui/sunnypilot/layouts/settings/steering_sub_layouts/torque_settings.py +++ b/openpilot/selfdrive/ui/sunnypilot/layouts/settings/steering_sub_layouts/torque_settings.py @@ -48,7 +48,7 @@ class TorqueSettingsLayout(Widget): "Thanks to @twilsonco for the implementation."), ) self._torque_control_versions = ListItemSP( - title=tr("Torque Control Tune Version"), + title=lambda: tr("Torque Control Tune Version"), description="Select the version of Torque Control Tune to use.", action_item=NoElideButtonAction(tr("SELECT")), callback=self._show_torque_version_dialog, diff --git a/openpilot/selfdrive/ui/sunnypilot/layouts/settings/sunnylink.py b/openpilot/selfdrive/ui/sunnypilot/layouts/settings/sunnylink.py index 5e75e797c..92648d752 100644 --- a/openpilot/selfdrive/ui/sunnypilot/layouts/settings/sunnylink.py +++ b/openpilot/selfdrive/ui/sunnypilot/layouts/settings/sunnylink.py @@ -151,8 +151,8 @@ class SunnylinkLayout(Widget): def _initialize_items(self): self._sunnylink_toggle = toggle_item_sp( - title=tr("Enable sunnylink"), - description=tr("This is the master switch, it will allow you to cutoff any sunnylink requests should you want to do that."), + title=lambda: tr("Enable sunnylink"), + description=lambda: tr("This is the master switch, it will allow you to cutoff any sunnylink requests should you want to do that."), param="SunnylinkEnabled", callback=self._sunnylink_toggle_callback ) @@ -161,29 +161,29 @@ class SunnylinkLayout(Widget): self._sunnylink_description.set_visible(False) self._sponsor_btn = button_item_sp( - title=tr("Sponsor Status"), - button_text=tr("SPONSOR"), - description=tr( + title=lambda: tr("Sponsor Status"), + button_text=lambda: tr("SPONSOR"), + description=lambda: tr( "Become a sponsor of sunnypilot to get early access to sunnylink features when they become available."), callback=lambda: self._handle_pair_btn(False) ) self._pair_btn = button_item_sp( - title=tr("Pair GitHub Account"), - button_text=tr("Not Paired"), - description=tr( + title=lambda: tr("Pair GitHub Account"), + button_text=lambda: tr("Not Paired"), + description=lambda: tr( "Pair your GitHub account to grant your device sponsor benefits, including API access on sunnylink."), callback=lambda: self._handle_pair_btn(True) ) self._sunnylink_uploader_toggle = toggle_item_sp( - title=tr("Enable sunnylink uploader (infrastructure test)"), - description=tr("Enable sunnylink uploader to allow sunnypilot to upload your driving data to sunnypilot servers. ") + + title=lambda: tr("Enable sunnylink uploader (infrastructure test)"), + description=lambda: tr("Enable sunnylink uploader to allow sunnypilot to upload your driving data to sunnypilot servers. ") + tr("(Only for highest tiers, and does NOT bring ANY benefit to you yet. We are just testing data volume.)"), param="EnableSunnylinkUploader" ) self._sunnylink_backup_restore_buttons = dual_button_item( description="", - left_text=tr("Backup Settings"), - right_text=tr("Restore Settings"), + left_text=lambda: tr("Backup Settings"), + right_text=lambda: tr("Restore Settings"), left_callback=self._handle_backup_btn, right_callback=self._handle_restore_btn )