From 2d5867a213c4d23882e463d599eb236032086250 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 17 Apr 2019 10:34:02 +0200 Subject: installer: Change language as soon as it has been chosen. Previously we'd call 'setlocale' only after the complete 'locale' step had finished. * gnu/installer/newt/locale.scm (run-language-page): Set the 'LANGUAGE' environment variable before returning. --- gnu/installer/newt/locale.scm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'gnu/installer/newt') diff --git a/gnu/installer/newt/locale.scm b/gnu/installer/newt/locale.scm index b819d06691..01bcf76025 100644 --- a/gnu/installer/newt/locale.scm +++ b/gnu/installer/newt/locale.scm @@ -30,9 +30,9 @@ (define-module (gnu installer newt locale) #:export (run-locale-page)) (define (run-language-page languages language->text) - (let ((title (G_ "Locale language"))) + (define result (run-listbox-selection-page - #:title title + #:title (G_ "Locale language") #:info-text (G_ "Choose the language to use for the \ installation process and for the installed system.") #:info-textbox-width 70 @@ -44,7 +44,13 @@ (define (run-language-page languages language->text) (lambda _ (raise (condition - (&installer-step-abort))))))) + (&installer-step-abort)))))) + + ;; Immediately install the chosen language so that the territory page that + ;; comes after (optionally) is displayed in the chosen language. + (setenv "LANGUAGE" result) + + result) (define (run-territory-page territories territory->text) (let ((title (G_ "Locale location"))) -- cgit v1.2.3 From 7837a57241775fed221c9e03700af73263e222ed Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 17 Apr 2019 11:07:21 +0200 Subject: installer: Display language and territory names natively. * gnu/installer.scm (installer-program): Add calls to 'bindtextdomain'. * gnu/installer/newt/locale.scm (run-locale-page) : Add calls to 'gettext'. --- gnu/installer.scm | 10 ++++++++++ gnu/installer/newt/locale.scm | 18 +++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) (limited to 'gnu/installer/newt') diff --git a/gnu/installer.scm b/gnu/installer.scm index 6a7a556271..5baead8137 100644 --- a/gnu/installer.scm +++ b/gnu/installer.scm @@ -343,6 +343,16 @@ (define installer-builder ;; Add some binaries used by the installers to PATH. #$set-installer-path + ;; Arrange for language and territory name translations to be + ;; available. We need them at run time, not just compile time, + ;; because some territories have several corresponding languages + ;; (e.g., "French" is always displayed as "français", but + ;; "Belgium" could be translated to Dutch, French, or German.) + (bindtextdomain "iso_639-3" ;languages + #+(file-append iso-codes "/share/locale")) + (bindtextdomain "iso_3166-1" ;territories + #+(file-append iso-codes "/share/locale")) + (let* ((current-installer newt-installer) (steps (#$steps current-installer))) ((installer-init current-installer)) diff --git a/gnu/installer/newt/locale.scm b/gnu/installer/newt/locale.scm index 01bcf76025..7108e2960b 100644 --- a/gnu/installer/newt/locale.scm +++ b/gnu/installer/newt/locale.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2018 Mathieu Othacehe +;;; Copyright © 2019 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -161,7 +162,13 @@ (define locale-steps (run-language-page (sort-languages (delete-duplicates (map locale-language supported-locales))) - (cut language-code->language-name iso639-languages <>))))) + (lambda (language) + (let ((english (language-code->language-name iso639-languages + language))) + (setenv "LANGUAGE" language) + (let ((native (gettext english "iso_639-3"))) + (unsetenv "LANGUAGE") + native))))))) (installer-step (id 'territory) (compute @@ -175,10 +182,11 @@ (define locale-steps ;; supported by the previously selected language. (run-territory-page (delete-duplicates (map locale-territory locales)) - (lambda (territory-code) - (if territory-code - (territory-code->territory-name iso3166-territories - territory-code) + (lambda (territory) + (if territory + (let ((english (territory-code->territory-name + iso3166-territories territory))) + (gettext english "iso_3166-1")) (G_ "No location")))))))) (installer-step (id 'codeset) -- cgit v1.2.3 From 7cb7be17af77caa084c1b5ebf20748dd04f208fa Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 17 Apr 2019 11:41:52 +0200 Subject: installer: Look up timezone name translations in "iso_3166-1". * gnu/installer/newt/timezone.scm (run-timezone-page): Add call to 'gettext' for timezone names. --- gnu/installer/newt/timezone.scm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'gnu/installer/newt') diff --git a/gnu/installer/newt/timezone.scm b/gnu/installer/newt/timezone.scm index 63b44af729..67bf41ff84 100644 --- a/gnu/installer/newt/timezone.scm +++ b/gnu/installer/newt/timezone.scm @@ -50,12 +50,15 @@ (define (all-but-last list) (define (run-page timezone-tree) (define (loop path) + ;; XXX: Translation of time zones isn't perfect here because the + ;; "iso_3166-1" domain contains translation for "territories" (like + ;; "Antarctic") but not for continents (like "Africa"). (let ((timezones (locate-children timezone-tree path))) (run-listbox-selection-page #:title (G_ "Timezone") #:info-text (G_ "Please select a timezone.") #:listbox-items timezones - #:listbox-item->text identity + #:listbox-item->text (cut gettext <> "iso_3166-1") #:button-text (if (null? path) (G_ "Exit") (G_ "Back")) -- cgit v1.2.3 From 14755829dc268a3983036908750f4ea40c5224b3 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 17 Apr 2019 11:51:31 +0200 Subject: installer: Sort items with 'string-locale key is pressed, otherwise nothing will happen. @@ -249,7 +250,7 @@ (define (fill-listbox listbox items) items)) (define (sort-listbox-items listbox-items) - "Return LISTBOX-ITEMS sorted using the 'string<=' procedure on the text + "Return LISTBOX-ITEMS sorted using the 'string-localetext item))) @@ -258,7 +259,7 @@ (define (sort-listbox-items listbox-items) (sort items (lambda (a b) (let ((text-a (cdr a)) (text-b (cdr b))) - (string<= text-a text-b)))))) + (string-locale Date: Wed, 17 Apr 2019 15:11:21 +0200 Subject: installer: Translate keyboard layout names. * gnu/installer.scm (installer-program)[installer-builder]: Call 'bindtextdomain' for "xkeyboard-config". * gnu/installer/newt/keymap.scm (run-keymap-page): Add calls to 'gettext'. --- gnu/installer.scm | 4 ++++ gnu/installer/newt/keymap.scm | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'gnu/installer/newt') diff --git a/gnu/installer.scm b/gnu/installer.scm index 5baead8137..881c40ee9b 100644 --- a/gnu/installer.scm +++ b/gnu/installer.scm @@ -353,6 +353,10 @@ (define installer-builder (bindtextdomain "iso_3166-1" ;territories #+(file-append iso-codes "/share/locale")) + ;; Likewise for XKB keyboard layout names. + (bindtextdomain "xkeyboard-config" + #+(file-append xkeyboard-config "/share/locale")) + (let* ((current-installer newt-installer) (steps (#$steps current-installer))) ((installer-init current-installer)) diff --git a/gnu/installer/newt/keymap.scm b/gnu/installer/newt/keymap.scm index 948b54783c..623bfe079d 100644 --- a/gnu/installer/newt/keymap.scm +++ b/gnu/installer/newt/keymap.scm @@ -97,7 +97,8 @@ (define keymap-steps (run-layout-page (sort-layouts layouts) (lambda (layout) - (x11-keymap-layout-description layout)))))) + (gettext (x11-keymap-layout-description layout) + "xkeyboard-config")))))) ;; Propose the user to select a variant among those supported by the ;; previously selected layout. (installer-step @@ -111,15 +112,16 @@ (define keymap-steps (run-variant-page (sort-variants variants) (lambda (variant) - (x11-keymap-variant-description - variant)))))))))) + (gettext (x11-keymap-variant-description variant) + "xkeyboard-config")))))))))) (define (format-result result) (let ((layout (x11-keymap-layout-name (result-step result 'layout))) (variant (and=> (result-step result 'variant) (lambda (variant) - (x11-keymap-variant-name variant))))) + (gettext (x11-keymap-variant-name variant) + "xkeyboard-config"))))) (list layout (or variant "")))) (format-result (run-installer-steps #:steps keymap-steps))) -- cgit v1.2.3 From 9015e63996156dfaafecef182d20128f268c2719 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 17 Apr 2019 15:16:08 +0200 Subject: installer: Sort keyboard layouts according to language and translations. Previously, we would always (1) put English first, and (2) sort the other layouts based on their English description. This fixes both issues. * gnu/installer/newt/keymap.scm (sort-layouts)[layoutconfiguration)) @@ -64,14 +65,29 @@ (define (run-variant-page variants variant->text) (define (sort-layouts layouts) "Sort LAYOUTS list by putting the US layout ahead and return it." + (define (layout <>))) + (lambda (main others) + (append (sort main layout Date: Tue, 23 Apr 2019 00:08:54 +0200 Subject: installer: Run 'guix system init' with the right locale. * gnu/installer/utils.scm (run-shell-command): Add #:locale and honor it. * gnu/installer/newt/final.scm (run-install-shell): Add 'locale' parameter; pass it to 'install-system'. (run-final-page): Obtain locale from RESULT; pass it to 'run-install-shell'. * gnu/installer/final.scm (install-system): Add 'locale' parameter; pass it to 'run-shell-command'. --- gnu/installer/final.scm | 8 +++++--- gnu/installer/newt/final.scm | 9 +++++---- gnu/installer/utils.scm | 14 +++++++++++++- 3 files changed, 23 insertions(+), 8 deletions(-) (limited to 'gnu/installer/newt') diff --git a/gnu/installer/final.scm b/gnu/installer/final.scm index e1c62f5ce0..07946f72c3 100644 --- a/gnu/installer/final.scm +++ b/gnu/installer/final.scm @@ -24,13 +24,15 @@ (define-module (gnu installer final) #:use-module (guix build utils) #:export (install-system)) -(define (install-system) +(define (install-system locale) "Start COW-STORE service on target directory and launch guix install command -in a subshell." +in a subshell. LOCALE must be the locale name under which that command will +run, or #f." (let ((install-command (format #f "guix system init ~a ~a" (%installer-configuration-file) (%installer-target-dir)))) (mkdir-p (%installer-target-dir)) (start-service 'cow-store (list (%installer-target-dir))) - (false-if-exception (run-shell-command install-command)))) + (false-if-exception (run-shell-command install-command + #:locale locale)))) diff --git a/gnu/installer/newt/final.scm b/gnu/installer/newt/final.scm index 645c1e8689..f492c5dbb7 100644 --- a/gnu/installer/newt/final.scm +++ b/gnu/installer/newt/final.scm @@ -65,22 +65,23 @@ (define (run-install-failed-page) (G_ "The final system installation step failed. You can retry the \ last step, or restart the installer."))) -(define (run-install-shell) +(define (run-install-shell locale) (clear-screen) (newt-suspend) - (let ((install-ok? (install-system))) + (let ((install-ok? (install-system locale))) (newt-resume) install-ok?)) (define (run-final-page result prev-steps) - (let* ((configuration (format-configuration prev-steps result)) + (let* ((configuration (format-configuration prev-steps result)) (user-partitions (result-step result 'partition)) + (locale (result-step result 'locale)) (install-ok? (with-mounted-partitions user-partitions (configuration->file configuration) (run-config-display-page) - (run-install-shell)))) + (run-install-shell locale)))) (if install-ok? (run-install-success-page) (run-install-failed-page)))) diff --git a/gnu/installer/utils.scm b/gnu/installer/utils.scm index e91f90a84d..256722729c 100644 --- a/gnu/installer/utils.scm +++ b/gnu/installer/utils.scm @@ -54,9 +54,21 @@ (define (read-percentage percentage) (and result (string->number (match:substring result 1))))) -(define (run-shell-command command) +(define* (run-shell-command command #:key locale) + "Run COMMAND, a string, with Bash, and in the given LOCALE." (call-with-temporary-output-file (lambda (file port) + (when locale + (let ((supported? (false-if-exception + (setlocale LC_ALL locale)))) + ;; If LOCALE is not supported, then set LANGUAGE, which might at + ;; least give us translated messages. + (if supported? + (format port "export LC_ALL=\"~a\"~%" locale) + (format port "export LANGUAGE=\"~a\"~%" + (string-take locale + (string-index locale #\_)))))) + (format port "~a~%" command) ;; (format port "exit~%") (close port) -- cgit v1.2.3