|
|
@ -9,6 +9,7 @@ import xml.etree.ElementTree as ET |
|
|
|
from selfdrive.ui.update_translations import TRANSLATIONS_DIR, LANGUAGES_FILE, update_translations |
|
|
|
from selfdrive.ui.update_translations import TRANSLATIONS_DIR, LANGUAGES_FILE, update_translations |
|
|
|
|
|
|
|
|
|
|
|
TMP_TRANSLATIONS_DIR = os.path.join(TRANSLATIONS_DIR, "tmp") |
|
|
|
TMP_TRANSLATIONS_DIR = os.path.join(TRANSLATIONS_DIR, "tmp") |
|
|
|
|
|
|
|
LOCATION_TAG = "<location " |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestTranslations(unittest.TestCase): |
|
|
|
class TestTranslations(unittest.TestCase): |
|
|
@ -27,9 +28,11 @@ class TestTranslations(unittest.TestCase): |
|
|
|
@staticmethod |
|
|
|
@staticmethod |
|
|
|
def _read_translation_file(path, file): |
|
|
|
def _read_translation_file(path, file): |
|
|
|
tr_file = os.path.join(path, f"{file}.ts") |
|
|
|
tr_file = os.path.join(path, f"{file}.ts") |
|
|
|
with open(tr_file, "rb") as f: |
|
|
|
with open(tr_file, "r") as f: |
|
|
|
# fix relative path depth |
|
|
|
# ignore locations when checking if translations are updated |
|
|
|
return f.read().replace(b"filename=\"../../", b"filename=\"../") |
|
|
|
lines = [line for line in f.read().splitlines() if |
|
|
|
|
|
|
|
not line.strip().startswith(LOCATION_TAG)] |
|
|
|
|
|
|
|
return "\n".join(lines) |
|
|
|
|
|
|
|
|
|
|
|
def test_missing_translation_files(self): |
|
|
|
def test_missing_translation_files(self): |
|
|
|
for name, file in self.translation_files.items(): |
|
|
|
for name, file in self.translation_files.items(): |
|
|
@ -56,14 +59,14 @@ class TestTranslations(unittest.TestCase): |
|
|
|
for name, file in self.translation_files.items(): |
|
|
|
for name, file in self.translation_files.items(): |
|
|
|
with self.subTest(name=name, file=file): |
|
|
|
with self.subTest(name=name, file=file): |
|
|
|
cur_translations = self._read_translation_file(TRANSLATIONS_DIR, file) |
|
|
|
cur_translations = self._read_translation_file(TRANSLATIONS_DIR, file) |
|
|
|
self.assertTrue(b"<translation type=\"unfinished\">" not in cur_translations, |
|
|
|
self.assertTrue("<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") |
|
|
|
f"{file} ({name}) translation file has unfinished translations. Finish translations or mark them as completed in Qt Linguist") |
|
|
|
|
|
|
|
|
|
|
|
def test_vanished_translations(self): |
|
|
|
def test_vanished_translations(self): |
|
|
|
for name, file in self.translation_files.items(): |
|
|
|
for name, file in self.translation_files.items(): |
|
|
|
with self.subTest(name=name, file=file): |
|
|
|
with self.subTest(name=name, file=file): |
|
|
|
cur_translations = self._read_translation_file(TRANSLATIONS_DIR, file) |
|
|
|
cur_translations = self._read_translation_file(TRANSLATIONS_DIR, file) |
|
|
|
self.assertTrue(b"<translation type=\"vanished\">" not in cur_translations, |
|
|
|
self.assertTrue("<translation type=\"vanished\">" not in cur_translations, |
|
|
|
f"{file} ({name}) translation file has obsolete translations. Run selfdrive/ui/update_translations.py --vanish to remove them") |
|
|
|
f"{file} ({name}) translation file has obsolete translations. Run selfdrive/ui/update_translations.py --vanish to remove them") |
|
|
|
|
|
|
|
|
|
|
|
def test_plural_translations(self): |
|
|
|
def test_plural_translations(self): |
|
|
|