translations tests: ignore line numbers (#25675)

* no line numbers

* remove locations

* test

* ignore line numbers

* revert

revert

* fix that

* use relative

* non bytes, global

* clean up
pull/25687/head
Shane Smiskol 3 years ago committed by GitHub
parent d222461a3e
commit 719d5f7856
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      selfdrive/ui/tests/test_translations.py
  2. 4
      selfdrive/ui/translations/main_en.ts
  3. 506
      selfdrive/ui/translations/main_ja.ts
  4. 506
      selfdrive/ui/translations/main_ko.ts
  5. 506
      selfdrive/ui/translations/main_pt-BR.ts
  6. 506
      selfdrive/ui/translations/main_zh-CHS.ts
  7. 506
      selfdrive/ui/translations/main_zh-CHT.ts
  8. 2
      selfdrive/ui/update_translations.py

@ -9,6 +9,7 @@ import xml.etree.ElementTree as ET
from selfdrive.ui.update_translations import TRANSLATIONS_DIR, LANGUAGES_FILE, update_translations
TMP_TRANSLATIONS_DIR = os.path.join(TRANSLATIONS_DIR, "tmp")
LOCATION_TAG = "<location "
class TestTranslations(unittest.TestCase):
@ -27,9 +28,11 @@ class TestTranslations(unittest.TestCase):
@staticmethod
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=\"../")
with open(tr_file, "r") as f:
# ignore locations when checking if translations are updated
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):
for name, file in self.translation_files.items():
@ -56,14 +59,14 @@ class TestTranslations(unittest.TestCase):
for name, file in self.translation_files.items():
with self.subTest(name=name, file=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")
def test_vanished_translations(self):
for name, file in self.translation_files.items():
with self.subTest(name=name, file=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")
def test_plural_translations(self):

@ -4,6 +4,7 @@
<context>
<name>InputDialog</name>
<message numerus="yes">
<location filename="../qt/widgets/input.cc" line="+168"/>
<source>Need at least %n character(s)!</source>
<translation>
<numerusform>Need at least %n character!</numerusform>
@ -14,6 +15,7 @@
<context>
<name>QObject</name>
<message numerus="yes">
<location filename="../qt/util.cc" line="+82"/>
<source>%n minute(s) ago</source>
<translation>
<numerusform>%n minute ago</numerusform>
@ -21,6 +23,7 @@
</translation>
</message>
<message numerus="yes">
<location line="+3"/>
<source>%n hour(s) ago</source>
<translation>
<numerusform>%n hour ago</numerusform>
@ -28,6 +31,7 @@
</translation>
</message>
<message numerus="yes">
<location line="+3"/>
<source>%n day(s) ago</source>
<translation>
<numerusform>%n day ago</numerusform>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -19,7 +19,7 @@ def update_translations(vanish=False, plural_only=None, translations_dir=TRANSLA
for file in translation_files.values():
tr_file = os.path.join(translations_dir, f"{file}.ts")
args = f"lupdate -recursive {UI_DIR} -ts {tr_file}"
args = f"lupdate -locations relative -recursive {UI_DIR} -ts {tr_file}"
if vanish:
args += " -no-obsolete"
if file in plural_only:

Loading…
Cancel
Save