From: Michael Tremer Date: Sat, 8 May 2021 14:06:01 +0000 (+0000) Subject: welcome: Merge language selection into welcome screen X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d86c36df5d2a4b0df14a3ac5496a80793c3b29f9;p=people%2Fms%2Fbricklayer.git welcome: Merge language selection into welcome screen Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 5694d42..d1c3155 100644 --- a/Makefile.am +++ b/Makefile.am @@ -48,7 +48,6 @@ dist_pkgpython_PYTHON = \ src/python/disk.py \ src/python/errors.py \ src/python/i18n.py \ - src/python/lang.py \ src/python/logger.py \ src/python/step.py \ src/python/tui.py \ diff --git a/src/python/__init__.py b/src/python/__init__.py index d010994..59d340f 100644 --- a/src/python/__init__.py +++ b/src/python/__init__.py @@ -24,7 +24,7 @@ import sys import traceback from . import disk -from . import lang +from . import i18n from . import logger from . import step from . import tui @@ -49,7 +49,7 @@ class Bricklayer(object): # Settings self.settings = { - "language" : lang.default_language, + "language" : i18n.default_language, # Set the default swap size to 1 GiB "swap-size": 1024 ** 3, @@ -75,7 +75,6 @@ class Bricklayer(object): # An ordered list of all available steps steps = ( step.UnattendedWarning, - lang.SelectLanguage, step.Welcome, disk.SelectDisk, disk.CalculatePartitionLayout, diff --git a/src/python/i18n.py b/src/python/i18n.py index da46784..8594a49 100644 --- a/src/python/i18n.py +++ b/src/python/i18n.py @@ -20,6 +20,15 @@ import gettext +supported_languages = { + "de_DE.UTF-8" : "Deutsch", + "en_US.UTF-8" : "English (United States)", +} + +default_language = "en_US.UTF-8" + +assert default_language in supported_languages + N_ = lambda x: x def _(singular, plural=None, n=None): diff --git a/src/python/lang.py b/src/python/lang.py deleted file mode 100644 index baf38a4..0000000 --- a/src/python/lang.py +++ /dev/null @@ -1,60 +0,0 @@ -############################################################################### -# # -# Bricklayer - An Installer for IPFire # -# Copyright (C) 2021 IPFire Development Team # -# # -# This program is free software; you can redistribute it and/or # -# modify it under the terms of the GNU General Public License # -# as published by the Free Software Foundation; either version 2 # -# of the License, or (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see . # -# # -############################################################################### - -import logging -import os - -from . import step -from .i18n import _ - -# Setup logging -log = logging.getLogger("bricklayer.lang") - -supported_languages = { - "de_DE.UTF-8" : "Deutsch", - "en_US.UTF-8" : "English (United States)", -} - -default_language = "en_US.UTF-8" - -assert default_language in supported_languages - -class SelectLanguage(step.InteractiveStep): - """ - Ask the user which language to use for the installation process - """ - def initialize(self): - self.current_language = self.bricklayer.settings.get("language") - - def run(self, tui): - # Let the user select - code = tui.select( - _("Language Selection"), - _("Select the language you wish to use for the installation"), - supported_languages, default=self.current_language, buttons=(_("Select"),) - ) - - log.info("Language selected: %s" % code) - - # Store in settings - self.bricklayer.settings["language"] = code - - # Set to environment - os.environ["LANGUAGE"] = code diff --git a/src/python/step.py b/src/python/step.py index 1e6c930..e58b903 100644 --- a/src/python/step.py +++ b/src/python/step.py @@ -19,10 +19,12 @@ ############################################################################### import logging +import os import time import snack +from . import i18n from .i18n import _ # Setup logging @@ -73,15 +75,24 @@ class Welcome(InteractiveStep): """ def run(self, tui): name = self.bricklayer.os.get("NAME") - - tui.message( - title=_("Welcome"), - text=_("Welcome to the %s installation program.\n\n" - "Selecting Cancel on any of the following screens will reboot the " - "computer.") % name, - buttons=(_("Start Installation"), _("Cancel")) + current_language = self.bricklayer.settings.get("language") + + # Let the user select + lang = tui.select( + _("Willkommen, Bienvenue, Welcome!"), + _("Select the language you wish to use for the installation"), + i18n.supported_languages, default=current_language, + buttons=[_("Start Installation")], width=60, ) + log.info("Language selected: %s" % lang) + + # Store in settings + self.bricklayer.settings["language"] = lang + + # Set to environment + os.environ["LANGUAGE"] = lang + class Congratulations(InteractiveStep): """ diff --git a/src/python/tui.py b/src/python/tui.py index 83da597..80d5c3b 100644 --- a/src/python/tui.py +++ b/src/python/tui.py @@ -137,7 +137,7 @@ class Tui(object): def progress(self, *args, **kwargs): return ProgressWindow(self, *args, **kwargs) - def select(self, title, text, items, buttons=None, default=None, help=None): + def select(self, title, text, items, buttons=None, default=None, help=None, width=40): # Translate default if default: default = items.get(default, None) @@ -151,7 +151,8 @@ class Tui(object): # Show the window button, item = snack.ListboxChoiceWindow(self.screen, title, text, - [value for key, value in items], buttons=buttons, default=default, help=help) + [value for key, value in items], buttons=buttons, default=default, help=help, + width=width) # Find the selected item key, value = items[item]