multilanguage: compile QM in scons (#25217)

* All in scons

* delete all this

* delete the qm files

* No need to check QM files in test_translations.py anymore

* readme

* add lupdate to third party

* fix

* one line

* update files_common

* readme imp

* add j flag

* add to path

* duplicate scons!

* update readme

* fix path

fix path

fix path

* no path
pull/25228/head
Shane Smiskol 3 years ago committed by GitHub
parent c875f540a8
commit c528decd17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      .gitignore
  2. 5
      release/files_common
  3. 7
      selfdrive/ui/SConscript
  4. 23
      selfdrive/ui/tests/test_translations.py
  5. 12
      selfdrive/ui/translations/README.md
  6. BIN
      selfdrive/ui/translations/main_ja.qm
  7. BIN
      selfdrive/ui/translations/main_ko.qm
  8. BIN
      selfdrive/ui/translations/main_zh-CHS.qm
  9. BIN
      selfdrive/ui/translations/main_zh-CHT.qm
  10. 3
      selfdrive/ui/update_translations.py
  11. BIN
      third_party/qt5/larch64/bin/lrelease
  12. BIN
      third_party/qt5/larch64/bin/lupdate

1
.gitignore vendored

@ -32,6 +32,7 @@ a.out
*.class
*.pyxbldc
*.vcd
*.qm
config.json
clcache
compile_commands.json

@ -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

@ -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)

@ -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}.{file_ext}")):
if not os.path.exists(os.path.join(TRANSLATIONS_DIR, f"{file}.ts")):
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)
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}) {file_ext.upper()} translation file out of date. Run selfdrive/ui/update_translations.py to update the translation files")
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"<translation type=\"unfinished\">" not in cur_translations,
f"{file} ({name}) translation file has unfinished translations. Finish translations or mark them as completed in Qt Linguist")

@ -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:

@ -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",

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save