[bug#74190,v2,2/3] install: Change the territory when we have learned it.

Message ID 03b8e561289d30b4af84ff1392eb27a51609dba3.1731881786.git.pelzflorian@pelzflorian.de
State New
Headers
Series install: Enable pt_BR locale. |

Commit Message

pelzflorian (Florian Pelz) Nov. 17, 2024, 11:48 p.m. UTC
Typically, the LANGUAGE has already been set in the run-language-page
step.  But for languages like pt, we must know the territory.

* gnu/installer/newt/locale.scm (run-territory-page): Call ‘setenv’ for
the ‘LANGUAGE’ variable.

Change-Id: Ie6308c359e0bdb2d37fac0c844cfd879e96e231a
---
Note: I’ve tested this in QEMU and with it, a zh_CN, pt_BR locale gets
applied visibly.  Also, it repeats exactly what was done in
‘run-language-page’.  Context: when the installer enters the
encompassing ‘run-locale-page’ procedure, it runs the installer
sub-steps ‘run-language-page’ and ‘run-territory-page’ in
immediate succession with no way to go back just one sub-step.
Esperanto does not go through ‘run-territory-page’ and is not broken
by this change.

 gnu/installer/newt/locale.scm | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
  

Comments

pelzflorian (Florian Pelz) Nov. 18, 2024, 10:26 a.m. UTC | #1
Florian Pelz <pelzflorian@pelzflorian.de> writes:
> Note: I’ve tested this in QEMU and with it, a zh_CN, pt_BR locale gets
> applied visibly.  Also, it repeats exactly what was done in
> ‘run-language-page’.  Context: when the installer enters the
> encompassing ‘run-locale-page’ procedure, it runs the installer
> sub-steps ‘run-language-page’ and ‘run-territory-page’ in
> immediate succession with no way to go back just one sub-step.

Oh well, I’ve found this should not be true for српски (Serbian) when
pressing the back button from the Latin/Cyrillic codeset selection
sub-step.  In theory, it would set an invalid LANGUAGE like sr_RS_RS and
thus print messages in English.  But there is no Serb translation and
the back button does not even work (in current master and 1.4.0).

We could search for some other way to pass the country code to the
run-territory-page other than (getenv "LANGUAGE"), such as set! it in
some variable or strip the territory from (getenv "LANGUAGE").

Is this worth it?  Currently it does not make a difference anyway.

Regards,
Florian
  
Ludovic Courtès Nov. 20, 2024, 12:07 p.m. UTC | #2
"pelzflorian (Florian Pelz)" <pelzflorian@pelzflorian.de> skribis:

> Florian Pelz <pelzflorian@pelzflorian.de> writes:
>> Note: I’ve tested this in QEMU and with it, a zh_CN, pt_BR locale gets
>> applied visibly.  Also, it repeats exactly what was done in
>> ‘run-language-page’.  Context: when the installer enters the
>> encompassing ‘run-locale-page’ procedure, it runs the installer
>> sub-steps ‘run-language-page’ and ‘run-territory-page’ in
>> immediate succession with no way to go back just one sub-step.
>
> Oh well, I’ve found this should not be true for српски (Serbian) when
> pressing the back button from the Latin/Cyrillic codeset selection
> sub-step.  In theory, it would set an invalid LANGUAGE like sr_RS_RS and
> thus print messages in English.  But there is no Serb translation and
> the back button does not even work (in current master and 1.4.0).
>
> We could search for some other way to pass the country code to the
> run-territory-page other than (getenv "LANGUAGE"), such as set! it in
> some variable or strip the territory from (getenv "LANGUAGE").
>
> Is this worth it?  Currently it does not make a difference anyway.

Yeah, let’s not bother too much if it’s purely theoretical at this
point.

Ludo’.
  

Patch

diff --git a/gnu/installer/newt/locale.scm b/gnu/installer/newt/locale.scm
index 0be9db449e..df168baca9 100644
--- a/gnu/installer/newt/locale.scm
+++ b/gnu/installer/newt/locale.scm
@@ -2,6 +2,7 @@ 
 ;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;; Copyright © 2019 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2024 Janneke Nieuwenhuizen <janneke@gnu.org>
+;;; Copyright © 2024 Florian Pelz <pelzflorian@pelzflorian.de>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -24,9 +25,6 @@  (define-module (gnu installer newt locale)
   #:use-module (gnu installer newt page)
   #:use-module (guix i18n)
   #: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))
 
@@ -52,16 +50,22 @@  (define (run-language-page languages language->text)
   result)
 
 (define (run-territory-page territories territory->text)
-  (let ((title (G_ "Locale location")))
+  (define result
     (run-listbox-selection-page
-     #:title title
+     #:title (G_ "Locale location")
      #:info-text (G_ "Choose a territory for this language.")
      #:listbox-items territories
      #:listbox-item->text territory->text
      #:button-text (G_ "Back")
      #:button-callback-procedure
      (lambda _
-       (abort-to-prompt 'installer-step 'abort)))))
+       (abort-to-prompt 'installer-step 'abort))))
+
+  ;; Some languages, such as pt, cannot be installed early in the
+  ;; run-language-page step.  Install them now, when we know the territory.
+  (setenv "LANGUAGE" (string-append (getenv "LANGUAGE") "_" result))
+
+  result)
 
 (define (run-codeset-page codesets)
   (let ((title (G_ "Locale codeset")))