2018-11-16 11:43:55 +00:00
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
|
|
|
;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com>
|
2019-04-17 09:07:21 +00:00
|
|
|
;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
|
2018-11-16 11:43:55 +00:00
|
|
|
;;;
|
|
|
|
;;; This file is part of GNU Guix.
|
|
|
|
;;;
|
|
|
|
;;; GNU Guix 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 3 of the License, or (at
|
|
|
|
;;; your option) any later version.
|
|
|
|
;;;
|
|
|
|
;;; GNU Guix 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 GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
(define-module (gnu installer newt locale)
|
|
|
|
#:use-module (gnu installer locale)
|
|
|
|
#:use-module (gnu installer steps)
|
|
|
|
#:use-module (gnu installer newt page)
|
|
|
|
#:use-module (guix i18n)
|
|
|
|
#:use-module (newt)
|
|
|
|
#:use-module (srfi srfi-1)
|
|
|
|
#:use-module (srfi srfi-26)
|
|
|
|
#:use-module (srfi srfi-34)
|
|
|
|
#:use-module (srfi srfi-35)
|
|
|
|
#:use-module (ice-9 match)
|
|
|
|
#:export (run-locale-page))
|
|
|
|
|
|
|
|
(define (run-language-page languages language->text)
|
2019-04-17 08:34:02 +00:00
|
|
|
(define result
|
2018-11-16 11:43:55 +00:00
|
|
|
(run-listbox-selection-page
|
2019-04-17 08:34:02 +00:00
|
|
|
#:title (G_ "Locale language")
|
2019-04-07 10:11:55 +00:00
|
|
|
#:info-text (G_ "Choose the language to use for the \
|
|
|
|
installation process and for the installed system.")
|
2018-12-05 10:27:31 +00:00
|
|
|
#:info-textbox-width 70
|
2018-11-16 11:43:55 +00:00
|
|
|
#:listbox-items languages
|
|
|
|
#:listbox-item->text language->text
|
2018-12-05 10:27:31 +00:00
|
|
|
#:sort-listbox-items? #f
|
2018-12-05 10:50:17 +00:00
|
|
|
#:button-text (G_ "Exit")
|
2018-11-16 11:43:55 +00:00
|
|
|
#:button-callback-procedure
|
|
|
|
(lambda _
|
installer: Use named prompt to abort or break installer steps.
* gnu/installer/steps.scm (run-installer-steps): Set up
'installer-step prompt.
* gnu/installer/newt/ethernet.scm (run-ethernet-page)
* gnu/installer/newt/final.scm (run-config-display-page,
run-install-failed-page)
* gnu/installer/newt/keymap.scm (run-layout-page, run-variant-page)
* gnu/installer/newt/locale.scm (run-language-page,
run-territory-page, run-codeset-page, run-modifier-page,
run-locale-page)
* gnu/installer/newt/network.scm (run-technology-page,
wait-service-online)
* gnu/installer/newt/page.scm (run-listbox-selection-page,
run-checkbox-tree-page)
* gnu/installer/newt/partition.scm (button-exit-action)
* gnu/installer/newt/services.scm (run-desktop-environments-cbt-page,
run-networking-cbt-page, run-other-services-cbt-page,
run-network-management-page)
* gnu/installer/newt/timezone.scm (run-timezone-page)
* gnu/installer/newt/user.scm (run-user-page)
* gnu/installer/newt/welcome.scm (run-menu-page)
* gnu/installer/newt/wifi.scm (run-wifi-page): Use the 'installer-step
prompt to abort.
Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
2022-01-15 13:50:07 +00:00
|
|
|
(abort-to-prompt 'installer-step 'abort))))
|
2019-04-17 08:34:02 +00:00
|
|
|
|
|
|
|
;; Immediately install the chosen language so that the territory page that
|
|
|
|
;; comes after (optionally) is displayed in the chosen language.
|
|
|
|
(setenv "LANGUAGE" result)
|
|
|
|
|
|
|
|
result)
|
2018-11-16 11:43:55 +00:00
|
|
|
|
|
|
|
(define (run-territory-page territories territory->text)
|
2018-12-05 10:27:31 +00:00
|
|
|
(let ((title (G_ "Locale location")))
|
2018-11-16 11:43:55 +00:00
|
|
|
(run-listbox-selection-page
|
|
|
|
#:title title
|
2019-04-07 10:11:55 +00:00
|
|
|
#:info-text (G_ "Choose a territory for this language.")
|
2018-11-16 11:43:55 +00:00
|
|
|
#:listbox-items territories
|
|
|
|
#:listbox-item->text territory->text
|
|
|
|
#:button-text (G_ "Back")
|
|
|
|
#:button-callback-procedure
|
|
|
|
(lambda _
|
installer: Use named prompt to abort or break installer steps.
* gnu/installer/steps.scm (run-installer-steps): Set up
'installer-step prompt.
* gnu/installer/newt/ethernet.scm (run-ethernet-page)
* gnu/installer/newt/final.scm (run-config-display-page,
run-install-failed-page)
* gnu/installer/newt/keymap.scm (run-layout-page, run-variant-page)
* gnu/installer/newt/locale.scm (run-language-page,
run-territory-page, run-codeset-page, run-modifier-page,
run-locale-page)
* gnu/installer/newt/network.scm (run-technology-page,
wait-service-online)
* gnu/installer/newt/page.scm (run-listbox-selection-page,
run-checkbox-tree-page)
* gnu/installer/newt/partition.scm (button-exit-action)
* gnu/installer/newt/services.scm (run-desktop-environments-cbt-page,
run-networking-cbt-page, run-other-services-cbt-page,
run-network-management-page)
* gnu/installer/newt/timezone.scm (run-timezone-page)
* gnu/installer/newt/user.scm (run-user-page)
* gnu/installer/newt/welcome.scm (run-menu-page)
* gnu/installer/newt/wifi.scm (run-wifi-page): Use the 'installer-step
prompt to abort.
Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
2022-01-15 13:50:07 +00:00
|
|
|
(abort-to-prompt 'installer-step 'abort)))))
|
2018-11-16 11:43:55 +00:00
|
|
|
|
|
|
|
(define (run-codeset-page codesets)
|
2018-12-05 10:27:31 +00:00
|
|
|
(let ((title (G_ "Locale codeset")))
|
2018-11-16 11:43:55 +00:00
|
|
|
(run-listbox-selection-page
|
|
|
|
#:title title
|
2019-04-07 10:11:55 +00:00
|
|
|
#:info-text (G_ "Choose the locale encoding.")
|
2018-11-16 11:43:55 +00:00
|
|
|
#:listbox-items codesets
|
|
|
|
#:listbox-item->text identity
|
|
|
|
#:listbox-default-item "UTF-8"
|
|
|
|
#:button-text (G_ "Back")
|
|
|
|
#:button-callback-procedure
|
|
|
|
(lambda _
|
installer: Use named prompt to abort or break installer steps.
* gnu/installer/steps.scm (run-installer-steps): Set up
'installer-step prompt.
* gnu/installer/newt/ethernet.scm (run-ethernet-page)
* gnu/installer/newt/final.scm (run-config-display-page,
run-install-failed-page)
* gnu/installer/newt/keymap.scm (run-layout-page, run-variant-page)
* gnu/installer/newt/locale.scm (run-language-page,
run-territory-page, run-codeset-page, run-modifier-page,
run-locale-page)
* gnu/installer/newt/network.scm (run-technology-page,
wait-service-online)
* gnu/installer/newt/page.scm (run-listbox-selection-page,
run-checkbox-tree-page)
* gnu/installer/newt/partition.scm (button-exit-action)
* gnu/installer/newt/services.scm (run-desktop-environments-cbt-page,
run-networking-cbt-page, run-other-services-cbt-page,
run-network-management-page)
* gnu/installer/newt/timezone.scm (run-timezone-page)
* gnu/installer/newt/user.scm (run-user-page)
* gnu/installer/newt/welcome.scm (run-menu-page)
* gnu/installer/newt/wifi.scm (run-wifi-page): Use the 'installer-step
prompt to abort.
Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
2022-01-15 13:50:07 +00:00
|
|
|
(abort-to-prompt 'installer-step 'abort)))))
|
2018-11-16 11:43:55 +00:00
|
|
|
|
|
|
|
(define (run-modifier-page modifiers modifier->text)
|
2018-12-05 10:27:31 +00:00
|
|
|
(let ((title (G_ "Locale modifier")))
|
2018-11-16 11:43:55 +00:00
|
|
|
(run-listbox-selection-page
|
|
|
|
#:title title
|
2018-12-05 10:27:31 +00:00
|
|
|
#:info-text (G_ "Choose your locale's modifier. The most frequent \
|
|
|
|
modifier is euro. It indicates that you want to use Euro as the currency \
|
|
|
|
symbol.")
|
2018-11-16 11:43:55 +00:00
|
|
|
#:listbox-items modifiers
|
|
|
|
#:listbox-item->text modifier->text
|
|
|
|
#:button-text (G_ "Back")
|
|
|
|
#:button-callback-procedure
|
|
|
|
(lambda _
|
installer: Use named prompt to abort or break installer steps.
* gnu/installer/steps.scm (run-installer-steps): Set up
'installer-step prompt.
* gnu/installer/newt/ethernet.scm (run-ethernet-page)
* gnu/installer/newt/final.scm (run-config-display-page,
run-install-failed-page)
* gnu/installer/newt/keymap.scm (run-layout-page, run-variant-page)
* gnu/installer/newt/locale.scm (run-language-page,
run-territory-page, run-codeset-page, run-modifier-page,
run-locale-page)
* gnu/installer/newt/network.scm (run-technology-page,
wait-service-online)
* gnu/installer/newt/page.scm (run-listbox-selection-page,
run-checkbox-tree-page)
* gnu/installer/newt/partition.scm (button-exit-action)
* gnu/installer/newt/services.scm (run-desktop-environments-cbt-page,
run-networking-cbt-page, run-other-services-cbt-page,
run-network-management-page)
* gnu/installer/newt/timezone.scm (run-timezone-page)
* gnu/installer/newt/user.scm (run-user-page)
* gnu/installer/newt/welcome.scm (run-menu-page)
* gnu/installer/newt/wifi.scm (run-wifi-page): Use the 'installer-step
prompt to abort.
Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
2022-01-15 13:50:07 +00:00
|
|
|
(abort-to-prompt 'installer-step 'abort)))))
|
2018-11-16 11:43:55 +00:00
|
|
|
|
|
|
|
(define* (run-locale-page #:key
|
|
|
|
supported-locales
|
|
|
|
iso639-languages
|
|
|
|
iso3166-territories)
|
2018-12-05 10:27:31 +00:00
|
|
|
"Run a page asking the user to select a locale language and possibly
|
|
|
|
territory, codeset and modifier. Use SUPPORTED-LOCALES as the list of glibc
|
|
|
|
available locales. ISO639-LANGUAGES is an association list associating a
|
|
|
|
locale code to a locale name. ISO3166-TERRITORIES is an association list
|
2020-09-20 19:05:23 +00:00
|
|
|
associating a territory code with a territory name. The formatted locale, under
|
2018-12-05 10:27:31 +00:00
|
|
|
glibc format is returned."
|
2018-11-16 11:43:55 +00:00
|
|
|
|
|
|
|
(define (break-on-locale-found locales)
|
installer: Use named prompt to abort or break installer steps.
* gnu/installer/steps.scm (run-installer-steps): Set up
'installer-step prompt.
* gnu/installer/newt/ethernet.scm (run-ethernet-page)
* gnu/installer/newt/final.scm (run-config-display-page,
run-install-failed-page)
* gnu/installer/newt/keymap.scm (run-layout-page, run-variant-page)
* gnu/installer/newt/locale.scm (run-language-page,
run-territory-page, run-codeset-page, run-modifier-page,
run-locale-page)
* gnu/installer/newt/network.scm (run-technology-page,
wait-service-online)
* gnu/installer/newt/page.scm (run-listbox-selection-page,
run-checkbox-tree-page)
* gnu/installer/newt/partition.scm (button-exit-action)
* gnu/installer/newt/services.scm (run-desktop-environments-cbt-page,
run-networking-cbt-page, run-other-services-cbt-page,
run-network-management-page)
* gnu/installer/newt/timezone.scm (run-timezone-page)
* gnu/installer/newt/user.scm (run-user-page)
* gnu/installer/newt/welcome.scm (run-menu-page)
* gnu/installer/newt/wifi.scm (run-wifi-page): Use the 'installer-step
prompt to abort.
Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
2022-01-15 13:50:07 +00:00
|
|
|
"Break to the installer step if LOCALES contains exactly one
|
2018-11-16 11:43:55 +00:00
|
|
|
element."
|
|
|
|
(and (= (length locales) 1)
|
installer: Use named prompt to abort or break installer steps.
* gnu/installer/steps.scm (run-installer-steps): Set up
'installer-step prompt.
* gnu/installer/newt/ethernet.scm (run-ethernet-page)
* gnu/installer/newt/final.scm (run-config-display-page,
run-install-failed-page)
* gnu/installer/newt/keymap.scm (run-layout-page, run-variant-page)
* gnu/installer/newt/locale.scm (run-language-page,
run-territory-page, run-codeset-page, run-modifier-page,
run-locale-page)
* gnu/installer/newt/network.scm (run-technology-page,
wait-service-online)
* gnu/installer/newt/page.scm (run-listbox-selection-page,
run-checkbox-tree-page)
* gnu/installer/newt/partition.scm (button-exit-action)
* gnu/installer/newt/services.scm (run-desktop-environments-cbt-page,
run-networking-cbt-page, run-other-services-cbt-page,
run-network-management-page)
* gnu/installer/newt/timezone.scm (run-timezone-page)
* gnu/installer/newt/user.scm (run-user-page)
* gnu/installer/newt/welcome.scm (run-menu-page)
* gnu/installer/newt/wifi.scm (run-wifi-page): Use the 'installer-step
prompt to abort.
Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
2022-01-15 13:50:07 +00:00
|
|
|
(abort-to-prompt 'installer-step 'break)))
|
2018-11-16 11:43:55 +00:00
|
|
|
|
|
|
|
(define (filter-locales locales result)
|
|
|
|
"Filter the list of locale records LOCALES using the RESULT returned by
|
|
|
|
the installer-steps defined below."
|
|
|
|
(filter
|
|
|
|
(lambda (locale)
|
|
|
|
(and-map identity
|
|
|
|
`(,(string=? (locale-language locale)
|
|
|
|
(result-step result 'language))
|
|
|
|
,@(if (result-step-done? result 'territory)
|
|
|
|
(list (equal? (locale-territory locale)
|
|
|
|
(result-step result 'territory)))
|
|
|
|
'())
|
|
|
|
,@(if (result-step-done? result 'codeset)
|
|
|
|
(list (equal? (locale-codeset locale)
|
|
|
|
(result-step result 'codeset)))
|
|
|
|
'())
|
|
|
|
,@(if (result-step-done? result 'modifier)
|
|
|
|
(list (equal? (locale-modifier locale)
|
|
|
|
(result-step result 'modifier)))
|
|
|
|
'()))))
|
|
|
|
locales))
|
|
|
|
|
|
|
|
(define (result->locale-string locales result)
|
|
|
|
"Supposing that LOCALES contains exactly one locale record, turn it into a
|
|
|
|
glibc locale string and return it."
|
|
|
|
(match (filter-locales locales result)
|
|
|
|
((locale)
|
|
|
|
(locale->locale-string locale))))
|
|
|
|
|
2018-12-05 10:29:54 +00:00
|
|
|
(define (sort-languages languages)
|
|
|
|
"Extract some languages from LANGUAGES list and place them ahead."
|
|
|
|
(let* ((first-languages '("en"))
|
|
|
|
(other-languages (lset-difference equal?
|
|
|
|
languages
|
|
|
|
first-languages)))
|
|
|
|
`(,@first-languages ,@other-languages)))
|
|
|
|
|
2018-11-16 11:43:55 +00:00
|
|
|
(define locale-steps
|
|
|
|
(list
|
|
|
|
(installer-step
|
|
|
|
(id 'language)
|
|
|
|
(compute
|
|
|
|
(lambda _
|
|
|
|
(run-language-page
|
2018-12-05 10:29:54 +00:00
|
|
|
(sort-languages
|
|
|
|
(delete-duplicates (map locale-language supported-locales)))
|
2019-04-17 09:07:21 +00:00
|
|
|
(lambda (language)
|
|
|
|
(let ((english (language-code->language-name iso639-languages
|
|
|
|
language)))
|
|
|
|
(setenv "LANGUAGE" language)
|
|
|
|
(let ((native (gettext english "iso_639-3")))
|
|
|
|
(unsetenv "LANGUAGE")
|
|
|
|
native)))))))
|
2018-11-16 11:43:55 +00:00
|
|
|
(installer-step
|
|
|
|
(id 'territory)
|
|
|
|
(compute
|
2018-12-05 05:36:22 +00:00
|
|
|
(lambda (result _)
|
2018-11-16 11:43:55 +00:00
|
|
|
(let ((locales (filter-locales supported-locales result)))
|
|
|
|
;; Stop the process if the language returned by the previous step
|
|
|
|
;; is matching one and only one supported locale.
|
|
|
|
(break-on-locale-found locales)
|
|
|
|
|
|
|
|
;; Otherwise, ask the user to select a territory among those
|
|
|
|
;; supported by the previously selected language.
|
|
|
|
(run-territory-page
|
|
|
|
(delete-duplicates (map locale-territory locales))
|
2019-04-17 09:07:21 +00:00
|
|
|
(lambda (territory)
|
|
|
|
(if territory
|
|
|
|
(let ((english (territory-code->territory-name
|
|
|
|
iso3166-territories territory)))
|
|
|
|
(gettext english "iso_3166-1"))
|
2018-11-16 11:43:55 +00:00
|
|
|
(G_ "No location"))))))))
|
|
|
|
(installer-step
|
|
|
|
(id 'codeset)
|
|
|
|
(compute
|
2018-12-05 05:36:22 +00:00
|
|
|
(lambda (result _)
|
2018-11-16 11:43:55 +00:00
|
|
|
(let ((locales (filter-locales supported-locales result)))
|
|
|
|
;; Same as above but we now have a language and a territory to
|
|
|
|
;; narrow down the search of a locale.
|
|
|
|
(break-on-locale-found locales)
|
|
|
|
|
2019-04-07 10:11:55 +00:00
|
|
|
;; Otherwise, choose a codeset.
|
|
|
|
(let ((codesets (delete-duplicates (map locale-codeset locales))))
|
|
|
|
(if (member "UTF-8" codesets)
|
|
|
|
"UTF-8" ;don't even ask
|
|
|
|
(run-codeset-page codesets)))))))
|
2018-11-16 11:43:55 +00:00
|
|
|
(installer-step
|
|
|
|
(id 'modifier)
|
|
|
|
(compute
|
2018-12-05 05:36:22 +00:00
|
|
|
(lambda (result _)
|
2018-11-16 11:43:55 +00:00
|
|
|
(let ((locales (filter-locales supported-locales result)))
|
|
|
|
;; Same thing with a language, a territory and a codeset this time.
|
|
|
|
(break-on-locale-found locales)
|
|
|
|
|
|
|
|
;; Otherwise, ask for a modifier.
|
|
|
|
(run-modifier-page
|
|
|
|
(delete-duplicates (map locale-modifier locales))
|
|
|
|
(lambda (modifier)
|
|
|
|
(or modifier (G_ "No modifier"))))))))))
|
|
|
|
|
|
|
|
;; If run-installer-steps returns locally, it means that the user had to go
|
|
|
|
;; through all steps (language, territory, codeset and modifier) to select a
|
installer: Use named prompt to abort or break installer steps.
* gnu/installer/steps.scm (run-installer-steps): Set up
'installer-step prompt.
* gnu/installer/newt/ethernet.scm (run-ethernet-page)
* gnu/installer/newt/final.scm (run-config-display-page,
run-install-failed-page)
* gnu/installer/newt/keymap.scm (run-layout-page, run-variant-page)
* gnu/installer/newt/locale.scm (run-language-page,
run-territory-page, run-codeset-page, run-modifier-page,
run-locale-page)
* gnu/installer/newt/network.scm (run-technology-page,
wait-service-online)
* gnu/installer/newt/page.scm (run-listbox-selection-page,
run-checkbox-tree-page)
* gnu/installer/newt/partition.scm (button-exit-action)
* gnu/installer/newt/services.scm (run-desktop-environments-cbt-page,
run-networking-cbt-page, run-other-services-cbt-page,
run-network-management-page)
* gnu/installer/newt/timezone.scm (run-timezone-page)
* gnu/installer/newt/user.scm (run-user-page)
* gnu/installer/newt/welcome.scm (run-menu-page)
* gnu/installer/newt/wifi.scm (run-wifi-page): Use the 'installer-step
prompt to abort.
Signed-off-by: Mathieu Othacehe <othacehe@gnu.org>
2022-01-15 13:50:07 +00:00
|
|
|
;; locale. In that case, like if we exited by breaking to the installer
|
|
|
|
;; step, turn the result into a glibc locale string and return it.
|
2018-11-16 11:43:55 +00:00
|
|
|
(result->locale-string
|
|
|
|
supported-locales
|
|
|
|
(run-installer-steps #:steps locale-steps)))
|