diff --git a/.gitignore b/.gitignore index e1ff5d5008..07626f4e28 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,7 @@ a.out *.class *.pyxbldc *.vcd +*.qm config.json clcache compile_commands.json diff --git a/release/files_common b/release/files_common index 411e4ff6dc..0980f7929d 100644 --- a/release/files_common +++ b/release/files_common @@ -303,7 +303,8 @@ selfdrive/ui/soundd/*.cc selfdrive/ui/soundd/*.h selfdrive/ui/soundd/soundd selfdrive/ui/soundd/.gitignore -selfdrive/ui/translations/* +selfdrive/ui/translations/*.ts +selfdrive/ui/translations/languages.json selfdrive/ui/qt/*.cc selfdrive/ui/qt/*.h @@ -421,6 +422,8 @@ third_party/acados/x86_64/** third_party/acados/larch64/** third_party/acados/include/** +third_party/qt5/larch64/bin/** + scripts/update_now.sh scripts/stop_updater.sh diff --git a/selfdrive/ui/SConscript b/selfdrive/ui/SConscript index 0835c16372..9e89576a54 100644 --- a/selfdrive/ui/SConscript +++ b/selfdrive/ui/SConscript @@ -63,6 +63,13 @@ if GetOption('test'): qt_env.Program('tests/test_translations', [asset_obj, 'tests/test_runner.cc', 'tests/test_translations.cc'] + qt_src, LIBS=qt_libs) +# build translation files +translation_sources = Glob("#selfdrive/ui/translations/*.ts", strings=True) +translation_targets = [src.replace(".ts", ".qm") for src in translation_sources] +lrelease = 'third_party/qt5/larch64/bin/lrelease' if arch == 'larch64' else 'lrelease' +qt_env.Command(translation_targets, translation_sources, f"{lrelease} $SOURCES") + + # setup and factory resetter if GetOption('extras'): qt_env.Program("qt/setup/reset", ["qt/setup/reset.cc"], LIBS=qt_libs) diff --git a/selfdrive/ui/tests/test_translations.py b/selfdrive/ui/tests/test_translations.py index 59751eec19..b44ab11ede 100755 --- a/selfdrive/ui/tests/test_translations.py +++ b/selfdrive/ui/tests/test_translations.py @@ -23,8 +23,8 @@ class TestTranslations(unittest.TestCase): 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}") + def _read_translation_file(path, file): + tr_file = os.path.join(path, f"{file}.ts") with open(tr_file, "rb") as f: # fix relative path depth return f.read().replace(b"filename=\"../../", b"filename=\"../") @@ -35,9 +35,8 @@ class TestTranslations(unittest.TestCase): if not len(file): self.skipTest(f"{name} translation has no defined file") - if not (os.path.exists(os.path.join(TRANSLATIONS_DIR, f"{file}.ts")) and - os.path.exists(os.path.join(TRANSLATIONS_DIR, f"{file}.qm"))): - self.fail(f"{name} is missing translation files, run selfdrive/ui/update_translations.py") + 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") def test_translations_updated(self): update_translations(translations_dir=TMP_TRANSLATIONS_DIR) @@ -47,18 +46,14 @@ class TestTranslations(unittest.TestCase): if not len(file): 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}.ts")): + self.skipTest(f"{name} missing translation file") - # 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") - - 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"{file} ({name}) {file_ext.upper()} translation file out of date. Run selfdrive/ui/update_translations.py to update the translation files") + cur_translations = self._read_translation_file(TRANSLATIONS_DIR, file) + new_translations = self._read_translation_file(TMP_TRANSLATIONS_DIR, file) + self.assertEqual(cur_translations, new_translations, + f"{file} ({name}) XML translation file out of date. Run selfdrive/ui/update_translations.py to update the translation files") @unittest.skip("Only test unfinished translations before going to release") def test_unfinished_translations(self): @@ -67,7 +62,7 @@ class TestTranslations(unittest.TestCase): if not len(file): raise self.skipTest(f"{name} translation has no defined file") - cur_translations = self._read_translation_file(TRANSLATIONS_DIR, file, "ts") + cur_translations = self._read_translation_file(TRANSLATIONS_DIR, file) self.assertTrue(b"" not in cur_translations, f"{file} ({name}) translation file has unfinished translations. Finish translations or mark them as completed in Qt Linguist") diff --git a/selfdrive/ui/translations/README.md b/selfdrive/ui/translations/README.md index 4038b1e0ce..a6f2f665eb 100644 --- a/selfdrive/ui/translations/README.md +++ b/selfdrive/ui/translations/README.md @@ -9,7 +9,7 @@ Before getting started, make sure you have set up the openpilot Ubuntu developme openpilot provides a few tools to help contributors manage their translations and to ensure quality. To get started: 1. Add your new language to [languages.json](/selfdrive/ui/translations/languages.json) with the appropriate [language code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) and the localized language name (Simplified Chinese is `中文(繁體)`). -2. Generate the translation file (`*.ts`): +2. Generate the XML translation file (`*.ts`): ```shell selfdrive/ui/update_translations.py ``` @@ -17,22 +17,22 @@ openpilot provides a few tools to help contributors manage their translations an ```shell linguist selfdrive/ui/translations/your_language_file.ts ``` -4. Save your file and generate the compiled QM file used by the Qt UI: +4. View your finished translations by compiling and starting the UI, then find it in the language selector: ```shell - selfdrive/ui/update_translations.py --release + scons -j$(nproc) selfdrive/ui && selfdrive/ui/ui ``` ### Improving an Existing Language -Follow the steps above, omitting steps 1. and 2. Any time you edit translations you'll want to make sure to compile them. +Follow step 3. above, you can review existing translations and add missing ones. Once you're done, just open a pull request to openpilot. ### Updating the UI -Any time you edit source code in the UI, you need to update and compile the translations to ensure the line numbers and contexts are up to date (last step above). +Any time you edit source code in the UI, you need to update the translations to ensure the line numbers and contexts are up to date (first step above). ### Testing -openpilot has a few unit tests to make sure all translations are up to date and that all strings are wrapped in a translation marker. +openpilot has a few unit tests to make sure all translations are up to date and that all strings are wrapped in a translation marker. They are run in CI, but you can also run them locally. Tests translation files up to date: diff --git a/selfdrive/ui/translations/main_ja.qm b/selfdrive/ui/translations/main_ja.qm deleted file mode 100644 index b70c5abe0d..0000000000 Binary files a/selfdrive/ui/translations/main_ja.qm and /dev/null differ diff --git a/selfdrive/ui/translations/main_ko.qm b/selfdrive/ui/translations/main_ko.qm deleted file mode 100644 index d59698e074..0000000000 Binary files a/selfdrive/ui/translations/main_ko.qm and /dev/null differ diff --git a/selfdrive/ui/translations/main_zh-CHS.qm b/selfdrive/ui/translations/main_zh-CHS.qm deleted file mode 100644 index eed52b2778..0000000000 Binary files a/selfdrive/ui/translations/main_zh-CHS.qm and /dev/null differ diff --git a/selfdrive/ui/translations/main_zh-CHT.qm b/selfdrive/ui/translations/main_zh-CHT.qm deleted file mode 100644 index 029332de23..0000000000 Binary files a/selfdrive/ui/translations/main_zh-CHT.qm and /dev/null differ diff --git a/selfdrive/ui/update_translations.py b/selfdrive/ui/update_translations.py index 5ccae0eb02..9731160752 100755 --- a/selfdrive/ui/update_translations.py +++ b/selfdrive/ui/update_translations.py @@ -26,9 +26,6 @@ def update_translations(vanish=False, translations_dir=TRANSLATIONS_DIR): ret = os.system(args) assert ret == 0 - ret = os.system(f"lrelease {tr_file}") - assert ret == 0 - if __name__ == "__main__": parser = argparse.ArgumentParser(description="Update translation files for UI", diff --git a/third_party/qt5/larch64/bin/lrelease b/third_party/qt5/larch64/bin/lrelease new file mode 100755 index 0000000000..5c0195d29a Binary files /dev/null and b/third_party/qt5/larch64/bin/lrelease differ diff --git a/third_party/qt5/larch64/bin/lupdate b/third_party/qt5/larch64/bin/lupdate new file mode 100755 index 0000000000..67b7ea5cb5 Binary files /dev/null and b/third_party/qt5/larch64/bin/lupdate differ