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