Homogenize language option during handling (#1446)

* Adding a more elaborate fix

* Added recovery function to selecting language too

* Tweaked return value of display_language() to return the Language() object.
This commit is contained in:
Anton Hvornum 2022-08-30 19:34:25 +02:00 committed by GitHub
parent ee64276f0e
commit f6e695871c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 2 deletions

View File

@ -36,10 +36,21 @@ from ..user_interaction import add_number_of_parrallel_downloads
from ..models.users import User
from ..user_interaction.partitioning_conf import current_partition_layout
from ..output import FormattedOutput
from ..translationhandler import Language
if TYPE_CHECKING:
_: Any
def display_language(global_menu, x):
if type(x) == Language:
return x
elif type(x) == str:
translation_handler = global_menu._translation_handler
for language in translation_handler._get_translations():
if language.lang == x:
return language
else:
raise ValueError(f"Language entry needs to Language() object or string of full language like 'English'.")
class GlobalMenu(GeneralMenu):
def __init__(self,data_store):
@ -51,8 +62,8 @@ class GlobalMenu(GeneralMenu):
self._menu_options['archinstall-language'] = \
Selector(
_('Archinstall language'),
lambda x: self._select_archinstall_language(x),
display_func=lambda x: x.display_name,
lambda x: self._select_archinstall_language(display_language(self, x)),
display_func=lambda x: display_language(self, x).display_name,
default=self.translation_handler.get_language('en'))
self._menu_options['keyboard-layout'] = \
Selector(