Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib
diff options
context:
space:
mode:
Diffstat (limited to 'archinstall/lib')
-rw-r--r--archinstall/lib/menu/menu.py18
-rw-r--r--archinstall/lib/translationhandler.py42
-rw-r--r--archinstall/lib/user_interaction/general_conf.py26
3 files changed, 63 insertions, 23 deletions
diff --git a/archinstall/lib/menu/menu.py b/archinstall/lib/menu/menu.py
index 16153e2c..112bc0ae 100644
--- a/archinstall/lib/menu/menu.py
+++ b/archinstall/lib/menu/menu.py
@@ -1,7 +1,7 @@
from dataclasses import dataclass
from enum import Enum, auto
from os import system
-from typing import Dict, List, Union, Any, TYPE_CHECKING, Optional
+from typing import Dict, List, Union, Any, TYPE_CHECKING, Optional, Callable
from archinstall.lib.menu.simple_menu import TerminalMenu
@@ -52,9 +52,9 @@ class Menu(TerminalMenu):
sort :bool = True,
preset_values :Union[str, List[str]] = None,
cursor_index : Optional[int] = None,
- preview_command=None,
- preview_size=0.75,
- preview_title='Info',
+ preview_command: Optional[Callable] = None,
+ preview_size: float = 0.75,
+ preview_title: str = 'Info',
header :Union[List[str],str] = None,
raise_error_on_interrupt :bool = False,
raise_error_warning_msg :str = '',
@@ -152,6 +152,7 @@ class Menu(TerminalMenu):
self._multi = multi
self._raise_error_on_interrupt = raise_error_on_interrupt
self._raise_error_warning_msg = raise_error_warning_msg
+ self._preview_command = preview_command
menu_title = f'\n{title}\n\n'
@@ -198,7 +199,7 @@ class Menu(TerminalMenu):
# show_search_hint=True,
preselected_entries=self.preset_values,
cursor_index=self.cursor_index,
- preview_command=preview_command,
+ preview_command=lambda x: self._preview_wrapper(preview_command, x),
preview_size=preview_size,
preview_title=preview_title,
raise_error_on_interrupt=self._raise_error_on_interrupt,
@@ -235,6 +236,13 @@ class Menu(TerminalMenu):
else:
return MenuSelection(type_=MenuSelectionType.Esc)
+ def _preview_wrapper(self, preview_command: Optional[Callable], current_selection: str) -> Optional[str]:
+ if preview_command:
+ if self._default_option is not None and f'{self._default_option} {self._default_str}' == current_selection:
+ current_selection = self._default_option
+ return preview_command(current_selection)
+ return None
+
def run(self) -> MenuSelection:
ret = self._show()
diff --git a/archinstall/lib/translationhandler.py b/archinstall/lib/translationhandler.py
index 08deb3e7..ef33b8ec 100644
--- a/archinstall/lib/translationhandler.py
+++ b/archinstall/lib/translationhandler.py
@@ -17,41 +17,55 @@ if TYPE_CHECKING:
@dataclass
class Language:
abbr: str
- lang: str
+ name_en: str
translation: gettext.NullTranslations
translation_percent: int
translated_lang: Optional[str]
+ external_dep: Optional[str]
@property
def display_name(self) -> str:
- if self.translated_lang:
+ if not self.external_dep and self.translated_lang:
name = self.translated_lang
else:
- name = self.lang
+ name = self.name_en
+
return f'{name} ({self.translation_percent}%)'
def is_match(self, lang_or_translated_lang: str) -> bool:
- if self.lang == lang_or_translated_lang:
+ if self.name_en == lang_or_translated_lang:
return True
elif self.translated_lang == lang_or_translated_lang:
return True
return False
def json(self) -> str:
- return self.lang
+ return self.name_en
class TranslationHandler:
- _base_pot = 'base.pot'
- _languages = 'languages.json'
-
def __init__(self):
- # to display latin, greek, cyrillic characters
- self._set_font('LatGrkCyr-8x16')
+ self._base_pot = 'base.pot'
+ self._languages = 'languages.json'
+
+ # check if a custom font was provided, otherwise we'll
+ # use one that can display latin, greek, cyrillic characters
+ if self.is_custom_font_enabled():
+ self._set_font(self.custom_font_path().name)
+ else:
+ self._set_font('LatGrkCyr-8x16')
self._total_messages = self._get_total_active_messages()
self._translated_languages = self._get_translations()
+ @classmethod
+ def custom_font_path(cls) -> Path:
+ return Path('/usr/share/kbd/consolefonts/archinstall_font.psfu.gz')
+
+ @classmethod
+ def is_custom_font_enabled(cls) -> bool:
+ return cls.custom_font_path().exists()
+
@property
def translated_languages(self) -> List[Language]:
return self._translated_languages
@@ -70,6 +84,7 @@ class TranslationHandler:
abbr = mapping_entry['abbr']
lang = mapping_entry['lang']
translated_lang = mapping_entry.get('translated_lang', None)
+ external_dep = mapping_entry.get('external_dep', False)
try:
# get a translation for a specific language
@@ -84,7 +99,7 @@ class TranslationHandler:
# prevent cases where the .pot file is out of date and the percentage is above 100
percent = min(100, percent)
- language = Language(abbr, lang, translation, percent, translated_lang)
+ language = Language(abbr, lang, translation, percent, translated_lang, external_dep)
languages.append(language)
except FileNotFoundError as error:
raise TranslationError(f"Could not locate language file for '{lang}': {error}")
@@ -138,7 +153,7 @@ class TranslationHandler:
Get a language object by it's name, e.g. English
"""
try:
- return next(filter(lambda x: x.lang == name, self._translated_languages))
+ return next(filter(lambda x: x.name_en == name, self._translated_languages))
except Exception:
raise ValueError(f'No language with name found: {name}')
@@ -175,8 +190,7 @@ class TranslationHandler:
translation_files = []
for filename in filenames:
if len(filename) == 2 or filename == 'pt_BR':
- if filename not in ['ur', 'ta']:
- translation_files.append(filename)
+ translation_files.append(filename)
return translation_files
diff --git a/archinstall/lib/user_interaction/general_conf.py b/archinstall/lib/user_interaction/general_conf.py
index 34c80c21..6365014d 100644
--- a/archinstall/lib/user_interaction/general_conf.py
+++ b/archinstall/lib/user_interaction/general_conf.py
@@ -13,7 +13,7 @@ from ..output import log
from ..profiles import Profile, list_profiles
from ..mirrors import list_mirrors
-from ..translationhandler import Language
+from ..translationhandler import Language, TranslationHandler
from ..packages.packages import validate_package_list
from ..storage import storage
@@ -125,16 +125,34 @@ def select_archinstall_language(languages: List[Language], preset_value: Languag
# name of the language in its own language
options = {lang.display_name: lang for lang in languages}
+ def dependency_preview(current_selection: str) -> Optional[str]:
+ current_lang = options[current_selection]
+
+ if current_lang.external_dep and not TranslationHandler.is_custom_font_enabled():
+ font_file = TranslationHandler.custom_font_path()
+ text = str(_('To be able to use this translation, please install a font manually that supports the language.')) + '\n'
+ text += str(_('The font should be stored as {}')).format(font_file)
+ return text
+ return None
+
choice = Menu(
_('Archinstall language'),
list(options.keys()),
- default_option=preset_value.display_name
+ default_option=preset_value.display_name,
+ preview_command=lambda x: dependency_preview(x),
+ preview_size=0.5
).run()
match choice.type_:
- case MenuSelectionType.Esc: return preset_value
+ case MenuSelectionType.Esc:
+ return preset_value
case MenuSelectionType.Selection:
- return options[choice.value]
+ language: Language = options[choice.value]
+ # we have to make sure that the proper AUR dependency is
+ # present to be able to use this language
+ if not language.external_dep or TranslationHandler.is_custom_font_enabled():
+ return language
+ return select_archinstall_language(languages, preset_value)
def select_profile(preset) -> Optional[Profile]: