Add Chinese (traditional) translations (#25064)

* Add Chinese translations

* wrap these

* add to languages.json

* fix tests

* use tmp dir for tests (doesn't change translation files in git repo)

* defaultdict not used

* update main_zh.ts (test outdated QM file)

* test outdated QM file (prev commit tests missing)

* update qm file

* add sidebar translations

* no need for function
pull/25071/head
Shane Smiskol 3 years ago committed by GitHub
parent 836e2a4d98
commit bd2ea15897
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      selfdrive/ui/qt/sidebar.h
  2. 44
      selfdrive/ui/tests/test_translations.py
  3. 3
      selfdrive/ui/translations/languages.json
  4. BIN
      selfdrive/ui/translations/main_zh.qm
  5. 1212
      selfdrive/ui/translations/main_zh.ts
  6. 4
      selfdrive/ui/update_translations.py

@ -34,13 +34,13 @@ protected:
QPixmap home_img, settings_img;
const QMap<cereal::DeviceState::NetworkType, QString> network_type = {
{cereal::DeviceState::NetworkType::NONE, "--"},
{cereal::DeviceState::NetworkType::WIFI, "Wi-Fi"},
{cereal::DeviceState::NetworkType::ETHERNET, "ETH"},
{cereal::DeviceState::NetworkType::CELL2_G, "2G"},
{cereal::DeviceState::NetworkType::CELL3_G, "3G"},
{cereal::DeviceState::NetworkType::CELL4_G, "LTE"},
{cereal::DeviceState::NetworkType::CELL5_G, "5G"}
{cereal::DeviceState::NetworkType::NONE, tr("--")},
{cereal::DeviceState::NetworkType::WIFI, tr("Wi-Fi")},
{cereal::DeviceState::NetworkType::ETHERNET, tr("ETH")},
{cereal::DeviceState::NetworkType::CELL2_G, tr("2G")},
{cereal::DeviceState::NetworkType::CELL3_G, tr("3G")},
{cereal::DeviceState::NetworkType::CELL4_G, tr("LTE")},
{cereal::DeviceState::NetworkType::CELL5_G, tr("5G")}
};
const QRect settings_btn = QRect(50, 35, 200, 117);

@ -1,10 +1,13 @@
#!/usr/bin/env python3
import json
import os
import shutil
import unittest
from selfdrive.ui.update_translations import TRANSLATIONS_DIR, LANGUAGES_FILE, update_translations
TMP_TRANSLATIONS_DIR = os.path.join(TRANSLATIONS_DIR, "tmp")
class TestTranslations(unittest.TestCase):
@classmethod
@ -12,11 +15,25 @@ class TestTranslations(unittest.TestCase):
with open(LANGUAGES_FILE, "r") as f:
cls.translation_files = json.load(f)
# Set up temp directory
shutil.copytree(TRANSLATIONS_DIR, TMP_TRANSLATIONS_DIR, dirs_exist_ok=True)
@classmethod
def tearDownClass(cls):
shutil.rmtree(TMP_TRANSLATIONS_DIR, ignore_errors=True)
@staticmethod
def _read_translation_file(path, file, file_ext):
tr_file = os.path.join(path, f"{file}.{file_ext}")
with open(tr_file, "rb") as f:
# fix relative path depth
return f.read().replace(b"filename=\"../../", b"filename=\"../")
def test_missing_translation_files(self):
for name, file in self.translation_files.items():
with self.subTest(name=name, file=file):
if not len(file):
self.skipTest(f"{name} translation has no file")
self.skipTest(f"{name} translation has no defined file")
self.assertTrue(os.path.exists(os.path.join(TRANSLATIONS_DIR, f"{file}.ts")),
f"{name} has no XML translation file, run selfdrive/ui/update_translations.py")
@ -24,26 +41,25 @@ class TestTranslations(unittest.TestCase):
f"{name} has no compiled QM translation file, run selfdrive/ui/update_translations.py --release")
def test_translations_updated(self):
suffix = "_test"
update_translations(suffix=suffix)
update_translations(release=True, translations_dir=TMP_TRANSLATIONS_DIR)
for name, file in self.translation_files.items():
with self.subTest(name=name, file=file):
cur_tr_file = os.path.join(TRANSLATIONS_DIR, f"{file}.ts")
new_tr_file = os.path.join(TRANSLATIONS_DIR, f"{file}{suffix}.ts")
if not len(file):
self.skipTest(f"{name} translation has no file")
elif not os.path.exists(cur_tr_file):
self.skipTest(f"{name} missing translation file") # caught by test_missing_translation_files
self.skipTest(f"{name} translation has no defined file")
for file_ext in ["ts", "qm"]:
with self.subTest(file_ext=file_ext):
# caught by test_missing_translation_files
if not os.path.exists(os.path.join(TRANSLATIONS_DIR, f"{file}.{file_ext}")):
self.skipTest(f"{name} missing translation file")
with open(cur_tr_file, "r") as f:
cur_translations = f.read()
with open(new_tr_file, "r") as f:
new_translations = f.read()
cur_translations = self._read_translation_file(TRANSLATIONS_DIR, file, file_ext)
new_translations = self._read_translation_file(TMP_TRANSLATIONS_DIR, file, file_ext)
self.assertEqual(cur_translations, new_translations,
f"{name} translation file out of date. Run selfdrive/ui/update_translations.py to update the translation files")
f"{file} ({name}) {file_ext.upper()} translation file out of date. Run selfdrive/ui/update_translations.py --release to update the translation files")
if __name__ == "__main__":

@ -1,3 +1,4 @@
{
"English": ""
"English": "",
"中文(简体)": "main_zh"
}

File diff suppressed because it is too large Load Diff

@ -10,7 +10,7 @@ TRANSLATIONS_DIR = os.path.join(UI_DIR, "translations")
LANGUAGES_FILE = os.path.join(TRANSLATIONS_DIR, "languages.json")
def update_translations(release=False, suffix=""):
def update_translations(release=False, translations_dir=TRANSLATIONS_DIR):
with open(LANGUAGES_FILE, "r") as f:
translation_files = json.load(f)
@ -19,7 +19,7 @@ def update_translations(release=False, suffix=""):
print(f"{name} has no translation file, skipping...")
continue
tr_file = os.path.join(TRANSLATIONS_DIR, f"{file}{suffix}.ts")
tr_file = os.path.join(translations_dir, f"{file}.ts")
ret = os.system(f"lupdate -recursive {UI_DIR} -ts {tr_file}")
assert ret == 0

Loading…
Cancel
Save