Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 5 additions & 19 deletions archinstall/lib/translationhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def json(self) -> str:

class TranslationHandler:
def __init__(self) -> None:
self._locales_dir = Path(__file__).parent.parent / 'locales'
self._base_pot = 'base.pot'
self._languages = 'languages.json'
self._active_language: Language | None = None
Expand Down Expand Up @@ -136,7 +137,7 @@ def _get_translations(self) -> list[Language]:

try:
# get a translation for a specific language
translation = gettext.translation('base', localedir=self._get_locales_dir(), languages=(abbr, lang))
translation = gettext.translation('base', localedir=self._locales_dir, languages=(abbr, lang))
except FileNotFoundError as err:
raise FileNotFoundError(f"Could not locate language file for '{lang}': {err}")

Expand All @@ -158,10 +159,7 @@ def _load_language_mappings(self) -> list[dict[str, str]]:
"""
Load the mapping table of all known languages
"""
locales_dir = self._get_locales_dir()
languages = Path.joinpath(locales_dir, self._languages)

with open(languages) as fp:
with (self._locales_dir / self._languages).open() as fp:
return json.load(fp)

def _get_catalog_size(self, translation: gettext.NullTranslations) -> int:
Expand All @@ -178,8 +176,7 @@ def _get_total_active_messages(self) -> int:
"""
Get total messages that could be translated
"""
locales = self._get_locales_dir()
with open(f'{locales}/{self._base_pot}') as fp:
with (self._locales_dir / self._base_pot).open() as fp:
lines = fp.readlines()
msgid_lines = [line for line in lines if 'msgid' in line]

Expand Down Expand Up @@ -237,23 +234,12 @@ def apply_console_font(self) -> None:
self._set_font(self.active_font)
debug(f'Console font set from language mapping: {self.active_font}')

def _get_locales_dir(self) -> Path:
"""
Get the locales directory path
"""
cur_path = Path(__file__).parent.parent
locales_dir = Path.joinpath(cur_path, 'locales')
return locales_dir

def _provided_translations(self) -> list[str]:
"""
Get a list of all known languages
"""
locales_dir = self._get_locales_dir()
filenames = os.listdir(locales_dir)

translation_files = []
for filename in filenames:
for filename in os.listdir(self._locales_dir):
if len(filename) == 2 or filename in ['pt_BR', 'zh-CN', 'zh-TW']:
translation_files.append(filename)

Expand Down