ui: multilang offroad alerts (#28512)

Co-authored-by: Shane Smiskol <shane@smiskol.com>
Co-authored-by: Cameron Clough <cameronjclough@gmail.com>

old-commit-hash: 2b800cf2e7
beeps
Dean Lee 2 years ago committed by GitHub
parent 9cc4291d77
commit 1b3ba1c7ee
  1. 4
      selfdrive/controls/lib/alertmanager.py
  2. 8
      selfdrive/controls/lib/alerts_offroad.json
  3. 10
      selfdrive/controls/tests/test_alerts.py
  4. 1
      selfdrive/ui/.gitignore
  5. 6
      selfdrive/ui/qt/widgets/offroad_alerts.cc
  6. 56
      selfdrive/ui/translations/main_de.ts
  7. 56
      selfdrive/ui/translations/main_ja.ts
  8. 56
      selfdrive/ui/translations/main_ko.ts
  9. 56
      selfdrive/ui/translations/main_pt-BR.ts
  10. 56
      selfdrive/ui/translations/main_zh-CHS.ts
  11. 56
      selfdrive/ui/translations/main_zh-CHT.ts
  12. 14
      selfdrive/ui/update_translations.py

@ -16,10 +16,8 @@ with open(os.path.join(BASEDIR, "selfdrive/controls/lib/alerts_offroad.json")) a
def set_offroad_alert(alert: str, show_alert: bool, extra_text: Optional[str] = None) -> None: def set_offroad_alert(alert: str, show_alert: bool, extra_text: Optional[str] = None) -> None:
if show_alert: if show_alert:
a = OFFROAD_ALERTS[alert]
if extra_text is not None:
a = copy.copy(OFFROAD_ALERTS[alert]) a = copy.copy(OFFROAD_ALERTS[alert])
a['text'] += extra_text a['extra'] = extra_text or ''
Params().put(alert, json.dumps(a)) Params().put(alert, json.dumps(a))
else: else:
Params().remove(alert) Params().remove(alert)

@ -4,18 +4,18 @@
"severity": 1 "severity": 1
}, },
"Offroad_ConnectivityNeededPrompt": { "Offroad_ConnectivityNeededPrompt": {
"text": "Immediately connect to the internet to check for updates. If you do not connect to the internet, openpilot won't engage in ", "text": "Immediately connect to the internet to check for updates. If you do not connect to the internet, openpilot won't engage in %1",
"severity": 0, "severity": 0,
"_comment": "Append the number of days at the end of the text" "_comment": "Set extra field to number of days"
}, },
"Offroad_ConnectivityNeeded": { "Offroad_ConnectivityNeeded": {
"text": "Connect to internet to check for updates. openpilot won't automatically start until it connects to internet to check for updates.", "text": "Connect to internet to check for updates. openpilot won't automatically start until it connects to internet to check for updates.",
"severity": 1 "severity": 1
}, },
"Offroad_UpdateFailed": { "Offroad_UpdateFailed": {
"text": "Unable to download updates\n", "text": "Unable to download updates\n%1",
"severity": 1, "severity": 1,
"_comment": "Append the command and error to the text." "_comment": "Set extra field to the failed reason."
}, },
"Offroad_InvalidTime": { "Offroad_InvalidTime": {
"text": "Invalid date and time settings, system won't start. Connect to internet to set time.", "text": "Invalid date and time settings, system won't start. Connect to internet to set time.",

@ -1,4 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import copy
import json import json
import os import os
import unittest import unittest
@ -109,8 +110,9 @@ class TestAlerts(unittest.TestCase):
params = Params() params = Params()
for a in self.offroad_alerts: for a in self.offroad_alerts:
# set the alert # set the alert
alert = self.offroad_alerts[a] alert = copy.copy(self.offroad_alerts[a])
set_offroad_alert(a, True) set_offroad_alert(a, True)
alert['extra'] = ''
self.assertTrue(json.dumps(alert) == params.get(a, encoding='utf8')) self.assertTrue(json.dumps(alert) == params.get(a, encoding='utf8'))
# then delete it # then delete it
@ -125,9 +127,9 @@ class TestAlerts(unittest.TestCase):
alert = self.offroad_alerts[a] alert = self.offroad_alerts[a]
set_offroad_alert(a, True, extra_text="a"*i) set_offroad_alert(a, True, extra_text="a"*i)
expected_txt = alert['text'] + "a"*i written_alert = json.loads(params.get(a, encoding='utf8'))
written_txt = json.loads(params.get(a, encoding='utf8'))['text'] self.assertTrue("a"*i == written_alert['extra'])
self.assertTrue(expected_txt == written_txt) self.assertTrue(alert["text"] == written_alert['text'])
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()

@ -12,3 +12,4 @@ qt/setup/setup
qt/setup/reset qt/setup/reset
qt/setup/wifi qt/setup/wifi
qt/setup/updater qt/setup/updater
translations/alerts_generated.h

@ -92,7 +92,11 @@ int OffroadAlert::refresh() {
std::string bytes = params.get(key); std::string bytes = params.get(key);
if (bytes.size()) { if (bytes.size()) {
auto doc_par = QJsonDocument::fromJson(bytes.c_str()); auto doc_par = QJsonDocument::fromJson(bytes.c_str());
text = doc_par["text"].toString(); text = tr(doc_par["text"].toString().toUtf8().data());
auto extra = doc_par["extra"].toString();
if (!extra.isEmpty()) {
text = text.arg(extra);
}
} }
label->setText(text); label->setText(text);
label->setVisible(!text.isEmpty()); label->setVisible(!text.isEmpty());

@ -435,6 +435,62 @@ location set</source>
<translation>Falsches Passwort</translation> <translation>Falsches Passwort</translation>
</message> </message>
</context> </context>
<context>
<name>OffroadAlert</name>
<message>
<source>Device temperature too high. System won&apos;t start.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Immediately connect to the internet to check for updates. If you do not connect to the internet, openpilot won&apos;t engage in %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Connect to internet to check for updates. openpilot won&apos;t automatically start until it connects to internet to check for updates.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unable to download updates
%1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Invalid date and time settings, system won&apos;t start. Connect to internet to set time.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Taking camera snapshots. System won&apos;t start until finished.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>An update to your device&apos;s operating system is downloading in the background. You will be prompted to update when it&apos;s ready to install.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Device failed to register. It will not connect to or upload to comma.ai servers, and receives no support from comma.ai. If this is an official device, visit https://comma.ai/support.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>NVMe drive not mounted.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unsupported NVMe drive detected. Device may draw significantly more power and overheat due to the unsupported NVMe.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>openpilot was unable to identify your car. Your car is either unsupported or its ECUs are not recognized. Please submit a pull request to add the firmware versions to the proper vehicle. Need help? Join discord.comma.ai.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>openpilot was unable to identify your car. Check integrity of cables and ensure all connections are secure, particularly that the comma power is fully inserted in the OBD-II port of the vehicle. Need help? Join discord.comma.ai.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>openpilot detected a change in the device&apos;s mounting position. Ensure the device is fully seated in the mount and the mount is firmly secured to the windshield.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>OffroadHome</name> <name>OffroadHome</name>
<message> <message>

@ -436,6 +436,62 @@ location set</source>
<translation></translation> <translation></translation>
</message> </message>
</context> </context>
<context>
<name>OffroadAlert</name>
<message>
<source>Device temperature too high. System won&apos;t start.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Immediately connect to the internet to check for updates. If you do not connect to the internet, openpilot won&apos;t engage in %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Connect to internet to check for updates. openpilot won&apos;t automatically start until it connects to internet to check for updates.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unable to download updates
%1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Invalid date and time settings, system won&apos;t start. Connect to internet to set time.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Taking camera snapshots. System won&apos;t start until finished.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>An update to your device&apos;s operating system is downloading in the background. You will be prompted to update when it&apos;s ready to install.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Device failed to register. It will not connect to or upload to comma.ai servers, and receives no support from comma.ai. If this is an official device, visit https://comma.ai/support.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>NVMe drive not mounted.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unsupported NVMe drive detected. Device may draw significantly more power and overheat due to the unsupported NVMe.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>openpilot was unable to identify your car. Your car is either unsupported or its ECUs are not recognized. Please submit a pull request to add the firmware versions to the proper vehicle. Need help? Join discord.comma.ai.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>openpilot was unable to identify your car. Check integrity of cables and ensure all connections are secure, particularly that the comma power is fully inserted in the OBD-II port of the vehicle. Need help? Join discord.comma.ai.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>openpilot detected a change in the device&apos;s mounting position. Ensure the device is fully seated in the mount and the mount is firmly secured to the windshield.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>OffroadHome</name> <name>OffroadHome</name>
<message> <message>

@ -436,6 +436,62 @@ location set</source>
<translation> </translation> <translation> </translation>
</message> </message>
</context> </context>
<context>
<name>OffroadAlert</name>
<message>
<source>Device temperature too high. System won&apos;t start.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Immediately connect to the internet to check for updates. If you do not connect to the internet, openpilot won&apos;t engage in %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Connect to internet to check for updates. openpilot won&apos;t automatically start until it connects to internet to check for updates.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unable to download updates
%1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Invalid date and time settings, system won&apos;t start. Connect to internet to set time.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Taking camera snapshots. System won&apos;t start until finished.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>An update to your device&apos;s operating system is downloading in the background. You will be prompted to update when it&apos;s ready to install.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Device failed to register. It will not connect to or upload to comma.ai servers, and receives no support from comma.ai. If this is an official device, visit https://comma.ai/support.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>NVMe drive not mounted.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unsupported NVMe drive detected. Device may draw significantly more power and overheat due to the unsupported NVMe.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>openpilot was unable to identify your car. Your car is either unsupported or its ECUs are not recognized. Please submit a pull request to add the firmware versions to the proper vehicle. Need help? Join discord.comma.ai.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>openpilot was unable to identify your car. Check integrity of cables and ensure all connections are secure, particularly that the comma power is fully inserted in the OBD-II port of the vehicle. Need help? Join discord.comma.ai.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>openpilot detected a change in the device&apos;s mounting position. Ensure the device is fully seated in the mount and the mount is firmly secured to the windshield.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>OffroadHome</name> <name>OffroadHome</name>
<message> <message>

@ -437,6 +437,62 @@ trabalho definido</translation>
<translation>Senha incorreta</translation> <translation>Senha incorreta</translation>
</message> </message>
</context> </context>
<context>
<name>OffroadAlert</name>
<message>
<source>Device temperature too high. System won&apos;t start.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Immediately connect to the internet to check for updates. If you do not connect to the internet, openpilot won&apos;t engage in %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Connect to internet to check for updates. openpilot won&apos;t automatically start until it connects to internet to check for updates.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unable to download updates
%1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Invalid date and time settings, system won&apos;t start. Connect to internet to set time.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Taking camera snapshots. System won&apos;t start until finished.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>An update to your device&apos;s operating system is downloading in the background. You will be prompted to update when it&apos;s ready to install.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Device failed to register. It will not connect to or upload to comma.ai servers, and receives no support from comma.ai. If this is an official device, visit https://comma.ai/support.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>NVMe drive not mounted.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unsupported NVMe drive detected. Device may draw significantly more power and overheat due to the unsupported NVMe.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>openpilot was unable to identify your car. Your car is either unsupported or its ECUs are not recognized. Please submit a pull request to add the firmware versions to the proper vehicle. Need help? Join discord.comma.ai.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>openpilot was unable to identify your car. Check integrity of cables and ensure all connections are secure, particularly that the comma power is fully inserted in the OBD-II port of the vehicle. Need help? Join discord.comma.ai.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>openpilot detected a change in the device&apos;s mounting position. Ensure the device is fully seated in the mount and the mount is firmly secured to the windshield.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>OffroadHome</name> <name>OffroadHome</name>
<message> <message>

@ -434,6 +434,62 @@ location set</source>
<translation></translation> <translation></translation>
</message> </message>
</context> </context>
<context>
<name>OffroadAlert</name>
<message>
<source>Device temperature too high. System won&apos;t start.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Immediately connect to the internet to check for updates. If you do not connect to the internet, openpilot won&apos;t engage in %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Connect to internet to check for updates. openpilot won&apos;t automatically start until it connects to internet to check for updates.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unable to download updates
%1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Invalid date and time settings, system won&apos;t start. Connect to internet to set time.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Taking camera snapshots. System won&apos;t start until finished.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>An update to your device&apos;s operating system is downloading in the background. You will be prompted to update when it&apos;s ready to install.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Device failed to register. It will not connect to or upload to comma.ai servers, and receives no support from comma.ai. If this is an official device, visit https://comma.ai/support.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>NVMe drive not mounted.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unsupported NVMe drive detected. Device may draw significantly more power and overheat due to the unsupported NVMe.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>openpilot was unable to identify your car. Your car is either unsupported or its ECUs are not recognized. Please submit a pull request to add the firmware versions to the proper vehicle. Need help? Join discord.comma.ai.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>openpilot was unable to identify your car. Check integrity of cables and ensure all connections are secure, particularly that the comma power is fully inserted in the OBD-II port of the vehicle. Need help? Join discord.comma.ai.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>openpilot detected a change in the device&apos;s mounting position. Ensure the device is fully seated in the mount and the mount is firmly secured to the windshield.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>OffroadHome</name> <name>OffroadHome</name>
<message> <message>

@ -436,6 +436,62 @@ location set</source>
<translation></translation> <translation></translation>
</message> </message>
</context> </context>
<context>
<name>OffroadAlert</name>
<message>
<source>Device temperature too high. System won&apos;t start.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Immediately connect to the internet to check for updates. If you do not connect to the internet, openpilot won&apos;t engage in %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Connect to internet to check for updates. openpilot won&apos;t automatically start until it connects to internet to check for updates.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unable to download updates
%1</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Invalid date and time settings, system won&apos;t start. Connect to internet to set time.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Taking camera snapshots. System won&apos;t start until finished.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>An update to your device&apos;s operating system is downloading in the background. You will be prompted to update when it&apos;s ready to install.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Device failed to register. It will not connect to or upload to comma.ai servers, and receives no support from comma.ai. If this is an official device, visit https://comma.ai/support.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>NVMe drive not mounted.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unsupported NVMe drive detected. Device may draw significantly more power and overheat due to the unsupported NVMe.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>openpilot was unable to identify your car. Your car is either unsupported or its ECUs are not recognized. Please submit a pull request to add the firmware versions to the proper vehicle. Need help? Join discord.comma.ai.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>openpilot was unable to identify your car. Check integrity of cables and ensure all connections are secure, particularly that the comma power is fully inserted in the OBD-II port of the vehicle. Need help? Join discord.comma.ai.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>openpilot detected a change in the device&apos;s mounting position. Ensure the device is fully seated in the mount and the mount is firmly secured to the windshield.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>OffroadHome</name> <name>OffroadHome</name>
<message> <message>

@ -8,9 +8,23 @@ from common.basedir import BASEDIR
UI_DIR = os.path.join(BASEDIR, "selfdrive", "ui") UI_DIR = os.path.join(BASEDIR, "selfdrive", "ui")
TRANSLATIONS_DIR = os.path.join(UI_DIR, "translations") TRANSLATIONS_DIR = os.path.join(UI_DIR, "translations")
LANGUAGES_FILE = os.path.join(TRANSLATIONS_DIR, "languages.json") LANGUAGES_FILE = os.path.join(TRANSLATIONS_DIR, "languages.json")
TRANSLATIONS_INCLUDE_FILE = os.path.join(TRANSLATIONS_DIR, "alerts_generated.h")
def generate_translations_include():
# offroad alerts
# TODO translate events from selfdrive/controls/lib/events.py
content = "// THIS IS AN AUTOGENERATED FILE, PLEASE EDIT alerts_offroad.json\n"
with open(os.path.join(BASEDIR, "selfdrive/controls/lib/alerts_offroad.json")) as f:
for alert in json.load(f).values():
content += f'QT_TRANSLATE_NOOP("OffroadAlert", R"({alert["text"]})");\n'
with open(TRANSLATIONS_INCLUDE_FILE, "w") as f:
f.write(content)
def update_translations(vanish=False, plural_only=None, translations_dir=TRANSLATIONS_DIR): def update_translations(vanish=False, plural_only=None, translations_dir=TRANSLATIONS_DIR):
generate_translations_include()
if plural_only is None: if plural_only is None:
plural_only = [] plural_only = []

Loading…
Cancel
Save