fix zipapp with multilang (#36511)

* fix

* fix

* fix

* more
pull/36512/head
Maxime Desroches 3 weeks ago committed by GitHub
parent 73ed45f9d7
commit 8a77534d02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      release/pack.py
  2. 4
      selfdrive/ui/tests/test_translations.py
  3. 2
      selfdrive/ui/update_translations.py
  4. 5
      system/ui/lib/application.py
  5. 11
      system/ui/lib/multilang.py

@ -12,7 +12,7 @@ from openpilot.common.basedir import BASEDIR
DIRS = ['cereal', 'openpilot'] DIRS = ['cereal', 'openpilot']
EXTS = ['.png', '.py', '.ttf', '.capnp'] EXTS = ['.png', '.py', '.ttf', '.capnp', '.json', '.fnt', '.mo']
INTERPRETER = '/usr/bin/env python3' INTERPRETER = '/usr/bin/env python3'

@ -8,7 +8,7 @@ import requests
from parameterized import parameterized_class from parameterized import parameterized_class
from openpilot.system.ui.lib.multilang import TRANSLATIONS_DIR, LANGUAGES_FILE from openpilot.system.ui.lib.multilang import TRANSLATIONS_DIR, LANGUAGES_FILE
with open(LANGUAGES_FILE) as f: with open(str(LANGUAGES_FILE)) as f:
translation_files = json.load(f) translation_files = json.load(f)
UNFINISHED_TRANSLATION_TAG = "<translation type=\"unfinished\"" # non-empty translations can be marked unfinished UNFINISHED_TRANSLATION_TAG = "<translation type=\"unfinished\"" # non-empty translations can be marked unfinished
@ -29,7 +29,7 @@ class TestTranslations:
return f.read() return f.read()
def test_missing_translation_files(self): def test_missing_translation_files(self):
assert os.path.exists(os.path.join(TRANSLATIONS_DIR, f"{self.file}.ts")), \ assert os.path.exists(os.path.join(str(TRANSLATIONS_DIR), f"{self.file}.ts")), \
f"{self.name} has no XML translation file, run selfdrive/ui/update_translations.py" f"{self.name} has no XML translation file, run selfdrive/ui/update_translations.py"
@pytest.mark.skip("Only test unfinished translations before going to release") @pytest.mark.skip("Only test unfinished translations before going to release")

@ -4,7 +4,7 @@ import os
from openpilot.common.basedir import BASEDIR from openpilot.common.basedir import BASEDIR
from openpilot.system.ui.lib.multilang import SYSTEM_UI_DIR, UI_DIR, TRANSLATIONS_DIR, multilang from openpilot.system.ui.lib.multilang import SYSTEM_UI_DIR, UI_DIR, TRANSLATIONS_DIR, multilang
POT_FILE = os.path.join(TRANSLATIONS_DIR, "app.pot") POT_FILE = os.path.join(str(TRANSLATIONS_DIR), "app.pot")
def update_translations(): def update_translations():

@ -391,8 +391,9 @@ class GuiApplication:
def _load_fonts(self): def _load_fonts(self):
for font_weight_file in FontWeight: for font_weight_file in FontWeight:
with as_file(FONT_DIR.joinpath(font_weight_file)) as fspath: with as_file(FONT_DIR) as fspath:
font = rl.load_font(fspath.as_posix()) fnt_path = fspath / font_weight_file
font = rl.load_font(fnt_path.as_posix())
rl.set_texture_filter(font.texture, rl.TextureFilter.TEXTURE_FILTER_BILINEAR) rl.set_texture_filter(font.texture, rl.TextureFilter.TEXTURE_FILTER_BILINEAR)
self._fonts[font_weight_file] = font self._fonts[font_weight_file] = font
rl.gui_set_font(self._fonts[FontWeight.NORMAL]) rl.gui_set_font(self._fonts[FontWeight.NORMAL])

@ -1,3 +1,4 @@
from importlib.resources import files
import os import os
import json import json
import gettext import gettext
@ -10,9 +11,9 @@ except ImportError:
Params = None Params = None
SYSTEM_UI_DIR = os.path.join(BASEDIR, "system", "ui") SYSTEM_UI_DIR = os.path.join(BASEDIR, "system", "ui")
UI_DIR = os.path.join(BASEDIR, "selfdrive", "ui") UI_DIR = files("openpilot.selfdrive.ui")
TRANSLATIONS_DIR = os.path.join(UI_DIR, "translations") TRANSLATIONS_DIR = UI_DIR.joinpath("translations")
LANGUAGES_FILE = os.path.join(TRANSLATIONS_DIR, "languages.json") LANGUAGES_FILE = TRANSLATIONS_DIR.joinpath("languages.json")
UNIFONT_LANGUAGES = [ UNIFONT_LANGUAGES = [
"ar", "ar",
@ -43,7 +44,7 @@ class Multilang:
def setup(self): def setup(self):
try: try:
with open(os.path.join(TRANSLATIONS_DIR, f'app_{self._language}.mo'), 'rb') as fh: with TRANSLATIONS_DIR.joinpath(f'app_{self._language}.mo').open('rb') as fh:
translation = gettext.GNUTranslations(fh) translation = gettext.GNUTranslations(fh)
translation.install() translation.install()
self._translation = translation self._translation = translation
@ -66,7 +67,7 @@ class Multilang:
return self._translation.ngettext(singular, plural, n) return self._translation.ngettext(singular, plural, n)
def _load_languages(self): def _load_languages(self):
with open(LANGUAGES_FILE, encoding='utf-8') as f: with LANGUAGES_FILE.open(encoding='utf-8') as f:
self.languages = json.load(f) self.languages = json.load(f)
self.codes = {v: k for k, v in self.languages.items()} self.codes = {v: k for k, v in self.languages.items()}

Loading…
Cancel
Save