From f6e695871cdf55dd5277a955ff63a1ee1fd14348 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Tue, 30 Aug 2022 19:34:25 +0200 Subject: 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. --- archinstall/lib/menu/global_menu.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'archinstall/lib/menu') diff --git a/archinstall/lib/menu/global_menu.py b/archinstall/lib/menu/global_menu.py index f631c086..fc7c90bc 100644 --- a/archinstall/lib/menu/global_menu.py +++ b/archinstall/lib/menu/global_menu.py @@ -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( -- cgit v1.2.3-54-g00ecf