unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / Atom feed
* [bug#35394] [PATCH 0/3] Bootloader localization
@ 2019-04-23 13:17 Miguel
  2019-04-23 13:26 ` [bug#35394] [PATCH 1/3] system: Add locale to boot-parameters Miguel
                   ` (6 more replies)
  0 siblings, 7 replies; 20+ messages in thread
From: Miguel @ 2019-04-23 13:17 UTC (permalink / raw)
  To: 35394

Hello Guix!

As a Grub translator, I've been hacking a little bit in order to
provide locale information to Grub. I use Guix in a daily basis, as my
main computer operating system, and I this is a key step in order to
provide a better experience to the all kind of users, who may do not
know other languages than their native one.

My current idea, implemented in the following patches, is something
along these lines:
  1. Store locale information into boot-parameters file. This patch
  contains a quite silly test that requires wiser review.
  2. Provide this information to the bootloader at the configuration
  time. This, ideally, should provided at installation time too, but
  I'm stuck seeing my first messages in english when grub asks for the
  whole-disk encryption passphrase as I don't know how to create a
  working core.img yet.
  3. Add a snippet to the generated grub.cfg file with the language
  information. Some configurations, as /boot in a separate partition,
  does not work with this patch, but take it as a proof of concept.

Lacking points:
  1. No support for other bootloaders yet. I don't know any of them too
  much, but I'm unaware of their localization support.
  2. Grub installation process is not transactional enough. I have some
  ideas for that, to be discussed in another thread, although one key
  point is tightly related with this topic: /boot/grub/locale
  generation. Having this folder as a derivation would make explicit
  the dependency, but I have to work more on this and I'm open to any
  ideas.

WDYT?

Best regards,
Miguel

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [bug#35394] [PATCH 1/3] system: Add locale to boot-parameters.
  2019-04-23 13:17 [bug#35394] [PATCH 0/3] Bootloader localization Miguel
@ 2019-04-23 13:26 ` Miguel
  2019-04-23 13:26 ` [bug#35394] [PATCH 2/3] system: Provide locale information to the bootloader Miguel
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 20+ messages in thread
From: Miguel @ 2019-04-23 13:26 UTC (permalink / raw)
  To: 35394

[-- Attachment #1: Type: text/plain, Size: 626 bytes --]

system: Add locale to boot-parameters.

* gnu/system.scm (<boot-parameters>): New locale field.
(boot-parameters-locale): New accessor.
(read-boot-parameters): Read locale field.
(operating-system-boot-parameters): Add locale to boot-parameters form.
(opeating-system-boot-parameters-file): Add locale to file-like object.
* tests/boot-parameters.scm: New test file.
* Makefile.am (SCM_TESTS): Add tests/boot-parameters.scm.
---
 Makefile.am               |   1 +
 gnu/system.scm            |  19 +++-
 tests/boot-parameters.scm | 232 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 248 insertions(+), 4 deletions(-)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-system-Add-locale-to-boot-parameters.patch --]
[-- Type: text/x-patch, Size: 13930 bytes --]

From ca81983f4fcab05472088b181406f21c80441c57 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
 <rosen644835@gmail.com>
Date: Mon, 22 Apr 2019 14:44:11 +0200
Subject: [PATCH 1/3] system: Add locale to boot-parameters.

* gnu/system.scm (<boot-parameters>): New locale field.
(boot-parameters-locale): New accessor.
(read-boot-parameters): Read locale field.
(operating-system-boot-parameters): Add locale to boot-parameters form.
(opeating-system-boot-parameters-file): Add locale to file-like object.
* tests/boot-parameters.scm: New test file.
* Makefile.am (SCM_TESTS): Add tests/boot-parameters.scm.
---
 Makefile.am               |   1 +
 gnu/system.scm            |  19 +++-
 tests/boot-parameters.scm | 232 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 248 insertions(+), 4 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 99d6ed64b6..6e174588db 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -347,6 +347,7 @@ SCM_TESTS =					\
   tests/base16.scm				\
   tests/base32.scm				\
   tests/base64.scm				\
+  tests/boot-parameters.scm			\
   tests/channels.scm				\
   tests/cpan.scm				\
   tests/cpio.scm				\
diff --git a/gnu/system.scm b/gnu/system.scm
index 24243eb707..385d93150c 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -5,6 +5,7 @@
 ;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
 ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;; Copyright © 2019 Meiyo Peng <meiyo.peng@gmail.com>
+;;; Copyright © 2019 Miguel Ángel Arruga Vivas <rosen644835@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -118,6 +119,7 @@
             boot-parameters-kernel
             boot-parameters-kernel-arguments
             boot-parameters-initrd
+            boot-parameters-locale
             read-boot-parameters
             read-boot-parameters-file
             boot-parameters->menu-entry
@@ -251,7 +253,8 @@ directly by the user."
   (store-mount-point boot-parameters-store-mount-point)
   (kernel           boot-parameters-kernel)
   (kernel-arguments boot-parameters-kernel-arguments)
-  (initrd           boot-parameters-initrd))
+  (initrd           boot-parameters-initrd)
+  (locale           boot-parameters-locale))
 
 (define (ensure-not-/dev device)
   "If DEVICE starts with a slash, return #f.  This is meant to filter out
@@ -329,7 +332,12 @@ file system labels."
          (('store ('device _) ('mount-point mount-point) _ ...)
           mount-point)
          (_                                       ;the old format
-          "/")))))
+          "/")))
+
+      (locale
+       (match (assq 'locale rest)
+         ((_ locale) locale)
+         (#f         #f)))))
     (x                                            ;unsupported format
      (warning (G_ "unrecognized boot parameters at '~a'~%")
               (port-filename port))
@@ -973,6 +981,7 @@ parameters of OS.  When SYSTEM-KERNEL-ARGUMENTS? is true, add kernel arguments
 such as '--root' and '--load' to <boot-parameters>."
   (let* ((initrd          (operating-system-initrd-file os))
          (store           (operating-system-store-file-system os))
+         (locale          (operating-system-locale os))
          (bootloader      (bootloader-configuration-bootloader
                            (operating-system-bootloader os)))
          (bootloader-name (bootloader-name bootloader))
@@ -988,7 +997,8 @@ such as '--root' and '--load' to <boot-parameters>."
      (initrd initrd)
      (bootloader-name bootloader-name)
      (store-device (ensure-not-/dev (file-system-device store)))
-     (store-mount-point (file-system-mount-point store)))))
+     (store-mount-point (file-system-mount-point store))
+     (locale locale))))
 
 (define (device->sexp device)
   "Serialize DEVICE as an sexp (really, as an object with a read syntax.)"
@@ -1031,7 +1041,8 @@ being stored into the \"parameters\" file)."
                     (store
                      (device
                       #$(device->sexp (boot-parameters-store-device params)))
-                     (mount-point #$(boot-parameters-store-mount-point params))))
+                     (mount-point #$(boot-parameters-store-mount-point params)))
+                    (locale #$(boot-parameters-locale params)))
                  #:set-load-path? #f)))
 
 (define-gexp-compiler (operating-system-compiler (os <operating-system>)
diff --git a/tests/boot-parameters.scm b/tests/boot-parameters.scm
new file mode 100644
index 0000000000..9ec1e6ddd3
--- /dev/null
+++ b/tests/boot-parameters.scm
@@ -0,0 +1,232 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2019 Miguel Ángel Arruga Vivas <rosen644835@gmail.com>
+;;;
+;;; 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/>.
+
+;;; Commentary:
+;;;
+;;; Test boot parameters value storage and compatibility.
+;;;
+;;; Code:
+
+(define-module (test-boot-parameters)
+  #:use-module (gnu bootloader)
+  #:use-module (gnu bootloader grub)
+  #:use-module (gnu system)
+  #:use-module (gnu system file-systems)
+  #:use-module (gnu system uuid)
+  #:use-module (guix gexp)
+  #:use-module (guix store)
+  #:use-module (guix tests)
+  #:use-module (srfi srfi-64)
+  #:use-module (rnrs bytevectors))
+
+;; For whitebox testing
+(define operating-system-boot-parameters
+  (@@ (gnu system) operating-system-boot-parameters))
+
+(define %default-label "GNU with Linux-libre 99.1.2")
+(define %default-kernel-path
+  (string-append (%store-prefix)
+                 "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-linux-libre-99.1.2"))
+(define %default-kernel
+  (string-append %default-kernel-path "/" (system-linux-image-file-name)))
+(define %default-kernel-arguments '())
+(define %default-initrd-path
+  (string-append (%store-prefix) "/wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww-initrd"))
+(define %default-initrd (string-append %default-initrd-path "/initrd.cpio.gz"))
+(define %default-root-device (uuid "abcdef12-3456-7890-abcd-ef1234567890"))
+(define %default-store-device (uuid "01234567-89ab-cdef-0123-456789abcdef"))
+(define %default-store-mount-point (%store-prefix))
+(define %default-locale "es_ES.utf8")
+(define %root-path "/")
+
+(define %grub-boot-parameters
+  (boot-parameters
+   (bootloader-name 'grub)
+   (label %default-label)
+   (root-device %default-root-device)
+   (kernel %default-kernel)
+   (kernel-arguments %default-kernel-arguments)
+   (initrd %default-initrd)
+   (store-device %default-store-device)
+   (store-mount-point %default-store-mount-point)
+   (locale %default-locale)))
+
+(define %default-operating-system
+  (operating-system
+    (host-name "host")
+    (timezone "Europe/Berlin")
+    (locale %default-locale)
+
+    (bootloader (bootloader-configuration
+                 (bootloader grub-bootloader)
+                 (target "/dev/sda")))
+    (file-systems (cons* (file-system
+                           (device %default-root-device)
+                           (mount-point %root-path)
+                           (type "ext4"))
+		         (file-system
+                           (device %default-store-device)
+                           (mount-point %default-store-mount-point)
+                           (type "btrfs"))
+                         %base-file-systems))))
+
+(define (quote-uuid uuid)
+  (list 'uuid (uuid-type uuid) (uuid-bytevector uuid)))
+
+(define* (test-read-boot-parameters
+          #:key
+          (version 0)
+          (bootloader-name 'grub)
+          (label %default-label)
+          (root-device (quote-uuid %default-root-device))
+          (kernel %default-kernel)
+          (kernel-arguments %default-kernel-arguments)
+          (initrd %default-initrd)
+          (with-store #t)
+          (store-device
+           (quote-uuid %default-store-device))
+          (store-mount-point %default-store-mount-point)
+          (locale %default-locale))
+  (define (generate-boot-parameters)
+    (define (sexp-or-nothing fmt val)
+      (cond ((eq? 'false val) (format #f fmt #f))
+            (val              (format #f fmt val))
+            (else             "")))
+    (format #f "(boot-parameters ~a~a~a~a~a~a~a~a~a)"
+            (sexp-or-nothing "(version ~S) " version)
+            (sexp-or-nothing "(label ~S) " label)
+            (sexp-or-nothing "(root-device ~S) " root-device)
+            (sexp-or-nothing "(kernel ~S) " kernel)
+            (sexp-or-nothing "(kernel-arguments ~S) " kernel-arguments)
+            (sexp-or-nothing "(initrd ~S) " initrd)
+            (if with-store
+                (format #f "(store ~a~a)"
+                        (sexp-or-nothing "(device ~S) " store-device)
+                        (sexp-or-nothing "(mount-point ~S)" store-mount-point))
+                "")
+            (sexp-or-nothing "(locale ~S) " locale)
+            (sexp-or-nothing "(bootloader-name ~a)" bootloader-name)))
+  (let ((str (generate-boot-parameters)))
+    (call-with-input-string str read-boot-parameters)))
+
+(test-begin "boot-parameters")
+
+;; XXX: <warning: unrecognized boot parameters at '#f'>
+(test-assert "read, construction, mandatory fields"
+  (not (or (test-read-boot-parameters #:version #f)
+           (test-read-boot-parameters #:version 'false)
+           (test-read-boot-parameters #:version -1)
+           (test-read-boot-parameters #:version "0")
+           (test-read-boot-parameters #:root-device #f)
+           (test-read-boot-parameters #:kernel #f)
+           (test-read-boot-parameters #:label #f))))
+
+(test-assert "read, construction, optional fields"
+  (and (test-read-boot-parameters #:bootloader-name #f)
+       (test-read-boot-parameters #:kernel-arguments #f)
+       (test-read-boot-parameters #:with-store #f)
+       (test-read-boot-parameters #:store-device #f)
+       (test-read-boot-parameters #:store-device 'false)
+       (test-read-boot-parameters #:store-mount-point #f)
+       (test-read-boot-parameters #:locale #f)
+       (test-read-boot-parameters #:bootloader-name #f #:kernel-arguments #f
+                                  #:with-store #f #:locale #f)))
+
+;; No default case, match error
+(test-error "read, construction, missing initrd" #t
+            (test-read-boot-parameters #:initrd #f))
+
+(test-equal "read, default equality"
+  %grub-boot-parameters
+  (test-read-boot-parameters))
+
+(test-equal "read, root-device, label"
+  (file-system-label "my-root")
+  (boot-parameters-root-device
+   (test-read-boot-parameters #:root-device '(file-system-label "my-root"))))
+
+(test-equal "read, root-device, /dev node"
+  "/dev/sda2"
+  (boot-parameters-root-device
+   (test-read-boot-parameters #:root-device "/dev/sda2")))
+
+(test-equal "read, kernel, only store path"
+  %default-kernel
+  (boot-parameters-kernel
+   (test-read-boot-parameters #:kernel %default-kernel-path)))
+
+(test-equal "read, initrd, apply concatenation"
+  "/a/b"
+  (boot-parameters-initrd
+   (test-read-boot-parameters #:initrd (list 'string-append "/a" "/b"))))
+
+(test-eq "read, bootloader-name, default value"
+  'grub
+  (boot-parameters-bootloader-name
+   (test-read-boot-parameters #:bootloader-name #f)))
+
+(test-eq "read, kernel-arguments, default value"
+  '()
+  (boot-parameters-kernel-arguments
+   (test-read-boot-parameters #:kernel-arguments #f)))
+
+(test-assert "read, store-device, filter /dev"
+  (not (boot-parameters-store-device
+        (test-read-boot-parameters #:store-device "/dev/sda3"))))
+
+(test-assert "read, no-store, filter /dev from root"
+  (not (boot-parameters-store-device
+        (test-read-boot-parameters #:root-device "/dev/sda3" #:with-store #f))))
+
+(test-assert "read, no store-device, filter /dev from root"
+  (not (boot-parameters-store-device
+        (test-read-boot-parameters #:root-device "/dev/sda3"
+                                   #:store-device #f))))
+
+(test-assert "read, store-device #f, filter /dev from root"
+  (not (boot-parameters-store-device
+        (test-read-boot-parameters #:root-device "/dev/sda3"
+                                   #:store-device 'false))))
+
+(test-equal "read, store-device, label (legacy)"
+  (file-system-label "my-store")
+  (boot-parameters-store-device
+   (test-read-boot-parameters #:store-device "my-store")))
+
+(test-equal "read, store-device, from root"
+  %default-root-device
+  (boot-parameters-store-device
+   (test-read-boot-parameters #:with-store #f)))
+
+(test-equal "read, no store-mount-point, default"
+  %root-path
+  (boot-parameters-store-mount-point
+   (test-read-boot-parameters #:store-mount-point #f)))
+
+(test-equal "read, no store, default store-mount-point"
+  %root-path
+  (boot-parameters-store-mount-point
+   (test-read-boot-parameters #:with-store #f)))
+
+(test-equal "from os, locale"
+  %default-locale
+  (boot-parameters-locale
+   (operating-system-boot-parameters %default-operating-system
+                                     %default-root-device)))
+
+(test-end "boot-parameters")
-- 
2.21.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [bug#35394] [PATCH 2/3] system: Provide locale information to the bootloader.
  2019-04-23 13:17 [bug#35394] [PATCH 0/3] Bootloader localization Miguel
  2019-04-23 13:26 ` [bug#35394] [PATCH 1/3] system: Add locale to boot-parameters Miguel
@ 2019-04-23 13:26 ` Miguel
  2019-04-23 13:26 ` [bug#35394] [PATCH 3/3] system: Use locale information in grub.cfg Miguel
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 20+ messages in thread
From: Miguel @ 2019-04-23 13:26 UTC (permalink / raw)
  To: 35394

[-- Attachment #1: Type: text/plain, Size: 719 bytes --]

system: Provide locale information to the bootloader. 

* gnu/bootloader/depthcharge.scm (depthcharge-configuration-file): Add
locale keyword.
* gnu/bootloader/extlinux.scm (extlinux-configuration-file): Likewise.
* gnu/bootloader/grub.scm (grub-configuration-file): Likewise.
* gnu/system.scm (operating-system-bootcfg): Provide locale information
to the bootloader.
* guix/system/script.scm (reinstall-bootloader): Use locale information
from boot-parameters.
---
 gnu/bootloader/depthcharge.scm | 3 ++-
 gnu/bootloader/extlinux.scm    | 3 ++-
 gnu/bootloader/grub.scm        | 3 ++-
 gnu/system.scm                 | 4 +++-
 guix/scripts/system.scm        | 4 +++-
 5 files changed, 12 insertions(+), 5 deletions(-)

[-- Attachment #2: 0002-system-Provide-locale-information-to-the-bootloader.patch --]
[-- Type: text/x-patch, Size: 5159 bytes --]

From e5fde74621973e54cdb2983361b90180b5367e74 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
 <rosen644835@gmail.com>
Date: Mon, 22 Apr 2019 14:44:22 +0200
Subject: [PATCH 2/3] system: Provide locale information to the bootloader.

* gnu/bootloader/depthcharge.scm (depthcharge-configuration-file): Add
locale keyword.
* gnu/bootloader/extlinux.scm (extlinux-configuration-file): Likewise.
* gnu/bootloader/grub.scm (grub-configuration-file): Likewise.
* gnu/system.scm (operating-system-bootcfg): Provide locale information
to the bootloader.
* guix/system/script.scm (reinstall-bootloader): Use locale information
from boot-parameters.
---
 gnu/bootloader/depthcharge.scm | 3 ++-
 gnu/bootloader/extlinux.scm    | 3 ++-
 gnu/bootloader/grub.scm        | 3 ++-
 gnu/system.scm                 | 4 +++-
 guix/scripts/system.scm        | 4 +++-
 5 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/gnu/bootloader/depthcharge.scm b/gnu/bootloader/depthcharge.scm
index 58cc3f3932..0e0c17a255 100644
--- a/gnu/bootloader/depthcharge.scm
+++ b/gnu/bootloader/depthcharge.scm
@@ -82,7 +82,8 @@
 (define* (depthcharge-configuration-file config entries
                                          #:key
                                          (system (%current-system))
-                                         (old-entries '()))
+                                         (old-entries '())
+                                         (locale #f))
   (match entries
     ((entry)
      (let ((kernel (menu-entry-linux entry))
diff --git a/gnu/bootloader/extlinux.scm b/gnu/bootloader/extlinux.scm
index 40108584a8..e4ccc47484 100644
--- a/gnu/bootloader/extlinux.scm
+++ b/gnu/bootloader/extlinux.scm
@@ -28,7 +28,8 @@
 (define* (extlinux-configuration-file config entries
                                       #:key
                                       (system (%current-system))
-                                      (old-entries '()))
+                                      (old-entries '())
+                                      (locale #f))
   "Return the U-Boot configuration file corresponding to CONFIG, a
 <u-boot-configuration> object, and where the store is available at STORE-FS, a
 <file-system> object.  OLD-ENTRIES is taken to be a list of menu entries
diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm
index e97a17b3e2..446f90157c 100644
--- a/gnu/bootloader/grub.scm
+++ b/gnu/bootloader/grub.scm
@@ -316,7 +316,8 @@ code."
 (define* (grub-configuration-file config entries
                                   #:key
                                   (system (%current-system))
-                                  (old-entries '()))
+                                  (old-entries '())
+                                  (locale #f))
   "Return the GRUB configuration file corresponding to CONFIG, a
 <bootloader-configuration> object, and where the store is available at
 STORE-FS, a <file-system> object.  OLD-ENTRIES is taken to be a list of menu
diff --git a/gnu/system.scm b/gnu/system.scm
index 385d93150c..5732382a3a 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -962,6 +962,7 @@ entry."
 a list of <menu-entry>, to populate the \"old entries\" menu."
   (let* ((root-fs         (operating-system-root-file-system os))
          (root-device     (file-system-device root-fs))
+         (locale          (operating-system-locale os))
          (params          (operating-system-boot-parameters
                            os root-device
                            #:system-kernel-arguments? #t))
@@ -972,7 +973,8 @@ a list of <menu-entry>, to populate the \"old entries\" menu."
        (bootloader-configuration-bootloader bootloader-conf)))
 
     (generate-config-file bootloader-conf (list entry)
-                          #:old-entries old-entries)))
+                          #:old-entries old-entries
+                          #:locale locale)))
 
 (define* (operating-system-boot-parameters os root-device
                                            #:key system-kernel-arguments?)
diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm
index 78aa6cf644..d3e0964aa9 100644
--- a/guix/scripts/system.scm
+++ b/guix/scripts/system.scm
@@ -492,6 +492,7 @@ STORE is an open connection to the store."
 
          ;; Make the specified system generation the default entry.
          (params (profile-boot-parameters %system-profile (list number)))
+         (locale (boot-parameters-locale params))
          (old-generations
           (delv number (reverse (generation-numbers %system-profile))))
          (old-params (profile-boot-parameters
@@ -503,7 +504,8 @@ STORE is an open connection to the store."
           ((bootcfg (lower-object
                      ((bootloader-configuration-file-generator bootloader)
                       bootloader-config entries
-                      #:old-entries old-entries)))
+                      #:old-entries old-entries
+                      #:locale locale)))
            (bootcfg-file -> (bootloader-configuration-file bootloader))
            (target -> "/")
            (drvs -> (list bootcfg)))
-- 
2.21.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [bug#35394] [PATCH 3/3] system: Use locale information in grub.cfg.
  2019-04-23 13:17 [bug#35394] [PATCH 0/3] Bootloader localization Miguel
  2019-04-23 13:26 ` [bug#35394] [PATCH 1/3] system: Add locale to boot-parameters Miguel
  2019-04-23 13:26 ` [bug#35394] [PATCH 2/3] system: Provide locale information to the bootloader Miguel
@ 2019-04-23 13:26 ` Miguel
  2019-04-26 10:50 ` [bug#35394] [PATCH 3/4] gnu: grub: Add locale output for bootloading Miguel
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 20+ messages in thread
From: Miguel @ 2019-04-23 13:26 UTC (permalink / raw)
  To: 35394

[-- Attachment #1: Type: text/plain, Size: 271 bytes --]

system: Use locale information in grub.cfg.

* gnu/bootloader/grub.scm (locale-config-entries): New procedure.
(grub-configuration-file): Use locale-config-entries.
---
 gnu/bootloader/grub.scm | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0003-system-Use-locale-information-in-grub.cfg.patch --]
[-- Type: text/x-patch, Size: 3361 bytes --]

From 762b00327be7a21ac3e04b10610666b0d323104b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
 <rosen644835@gmail.com>
Date: Tue, 23 Apr 2019 15:03:58 +0200
Subject: [PATCH 3/3] system: Use locale information in grub.cfg.

* gnu/bootloader/grub.scm (locale-config-entries): New procedure.
(grub-configuration-file): Use locale-config-entries.
---
 gnu/bootloader/grub.scm | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm
index 446f90157c..81c4e31e28 100644
--- a/gnu/bootloader/grub.scm
+++ b/gnu/bootloader/grub.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
 ;;; Copyright © 2017 Leo Famulari <leo@famulari.name>
 ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
+;;; Copyright © 2019 Miguel Ángel Arruga Vivas <rosen644835@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -28,6 +29,7 @@
   #:use-module (gnu system uuid)
   #:use-module (gnu system file-systems)
   #:use-module (gnu system keyboard)
+  #:use-module (gnu system locale)
   #:autoload   (gnu packages bootloaders) (grub)
   #:autoload   (gnu packages gtk) (guile-cairo guile-rsvg)
   #:autoload   (gnu packages xorg) (xkeyboard-config)
@@ -216,6 +218,36 @@ fi~%"
                  #$(theme-colors grub-theme-color-normal)
                  #$(theme-colors grub-theme-color-highlight))))
 
+(define* (locale-config-entries config store-device store-mount-point
+                                #:key locale port)
+  "Return a gexp that writes to PORT (a port-valued gexp) the
+'grub.cfg' part concerned with locale configuration."
+  ;; FIXME: /boot in a separate partition is not suported.  The prefix must
+  ;; be removed in order to make it work.  GRUB EFI installation contains an
+  ;; usable /boot/efi/grub/locale/ folder too, but it is not used, for the
+  ;; same reason.
+  (define grub-locale-dir "/boot/grub/locale")
+  (define (grub-lang-id)
+    (let ((definition (locale-name->definition locale)))
+      (locale-definition-source definition)))
+  (define (grub-locale-file)
+    (string-append grub-locale-dir "/" (grub-lang-id) ".mo"))
+
+  (and locale
+       #~(format #$port "# Configure GRUB with the selected locale.
+
+# Set the root for the locale file
+~a
+
+if [ -d ~a ]; then
+  set locale_dir=~a
+  set lang=~a
+fi~%"
+                 #$(grub-root-search store-device (grub-locale-file))
+                 #$grub-locale-dir
+                 #$grub-locale-dir
+                 #$(grub-lang-id))))
+
 \f
 ;;;
 ;;; Configuration file.
@@ -364,6 +396,10 @@ entries corresponding to old generations of the system."
 terminal_input at_keyboard
 insmod keylayouts
 keymap ~a~%" keymap)))))
+  (define locale-config
+    (locale-config-entries config (menu-entry-device (first all-entries))
+                           (menu-entry-device-mount-point (first all-entries))
+                           #:locale locale #:port #~port))
 
   (define builder
     #~(call-with-output-file #$output
@@ -374,6 +410,7 @@ keymap ~a~%" keymap)))))
 ")
           #$sugar
           #$keyboard-layout-config
+          #$locale-config
           (format port "
 set default=~a
 set timeout=~a~%"
-- 
2.21.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [bug#35394] [PATCH 3/4] gnu: grub: Add locale output for bootloading.
  2019-04-23 13:17 [bug#35394] [PATCH 0/3] Bootloader localization Miguel
                   ` (2 preceding siblings ...)
  2019-04-23 13:26 ` [bug#35394] [PATCH 3/3] system: Use locale information in grub.cfg Miguel
@ 2019-04-26 10:50 ` Miguel
  2019-05-03 12:27   ` Miguel
  2019-04-26 10:51 ` [bug#35394] [PATCH 4/4] system: Use locale information in grub.cfg Miguel
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 20+ messages in thread
From: Miguel @ 2019-04-26 10:50 UTC (permalink / raw)
  To: 35394

[-- Attachment #1: Type: text/plain, Size: 292 bytes --]

gnu: grub: Add locale output for bootloading.

* gnu/packages/bootloaders.scm (grub): Add needed modules and new output
generated with new phase 'install-locale-folder.
---
 gnu/packages/bootloaders.scm | 33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)

[-- Attachment #2: 0003-gnu-grub-Add-locale-output-for-bootloading.patch --]
[-- Type: text/x-patch, Size: 3713 bytes --]

From bc6e8168155ea017aece23b3a6f099de4a2d2d47 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
 <rosen644835@gmail.com>
Date: Fri, 26 Apr 2019 11:56:43 +0200
Subject: [PATCH 3/4] gnu: grub: Add locale output for bootloading.

* gnu/packages/bootloaders.scm (grub): Add needed modules and new output
generated with new phase 'install-locale-folder.
---
 gnu/packages/bootloaders.scm | 33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)

diff --git a/gnu/packages/bootloaders.scm b/gnu/packages/bootloaders.scm
index b4eabaea48..e3baff267d 100644
--- a/gnu/packages/bootloaders.scm
+++ b/gnu/packages/bootloaders.scm
@@ -94,7 +94,10 @@
                                       "grub-efi-fat-serial-number.patch"))))
     (build-system gnu-build-system)
     (arguments
-     `(#:phases (modify-phases %standard-phases
+     `(#:modules ((ice-9 ftw)
+                  (guix build utils)
+                  (guix build gnu-build-system))
+       #:phases (modify-phases %standard-phases
                   (add-after 'unpack 'patch-stuff
                    (lambda* (#:key inputs #:allow-other-keys)
                      (substitute* "grub-core/Makefile.in"
@@ -127,7 +130,30 @@
                       (substitute* "Makefile.in"
                         (("grub_cmd_date grub_cmd_set_date grub_cmd_sleep")
                           "grub_cmd_date grub_cmd_sleep"))
-                      #t)))
+                      #t))
+                  (add-after 'install 'install-locale-folder
+                    (lambda* (#:key outputs #:allow-other-keys)
+                      ;; XXX: Better checks are needed here
+                      (define (lang? file)
+                        (not (or (string=? file ".") (string=? file ".."))))
+                      (define (make-lang-installer to)
+                        (lambda (in-file stat flag)
+                          (if (eq? flag 'regular)
+                              (copy-file in-file to)
+                              #t)))
+
+                      (let* ((out (assoc-ref outputs "out"))
+                             (locale (string-append out "/share/locale"))
+                             (langs (scandir locale-dir lang?))
+                             (locale-out (assoc-ref outputs "locale")))
+                        (mkdir-p locale-out)
+                        (for-each (lambda (lang)
+                                    (let ((from (string-append locale "/" lang))
+                                          (to (string-append out-path "/"
+                                                             lang ".mo")))
+                                      (ftw from (make-lang-installer to))))
+                                  langs)
+                        #t))))
        ;; Disable tests on ARM and AARCH64 platforms.
        #:tests? ,(not (any (cute string-prefix? <> (or (%current-target-system)
                                                        (%current-system)))
@@ -183,6 +209,7 @@
        ("parted" ,parted)
        ("qemu" ,qemu-minimal-2.10)
        ("xorriso" ,xorriso)))
+    (outputs '("out" "locale"))
     (home-page "https://www.gnu.org/software/grub/")
     (synopsis "GRand Unified Boot loader")
     (description
@@ -249,8 +276,6 @@ menu to select one of the installed operating systems.")
        ,@(package-inputs grub-efi)))
     (arguments
      (substitute-keyword-arguments (package-arguments grub-efi)
-       ((#:modules modules `((guix build utils) (guix build gnu-build-system)))
-        `((ice-9 ftw) ,@modules))
        ((#:phases phases)
         `(modify-phases ,phases
            (add-after 'install 'install-non-efi
-- 
2.21.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [bug#35394] [PATCH 4/4] system: Use locale information in grub.cfg.
  2019-04-23 13:17 [bug#35394] [PATCH 0/3] Bootloader localization Miguel
                   ` (3 preceding siblings ...)
  2019-04-26 10:50 ` [bug#35394] [PATCH 3/4] gnu: grub: Add locale output for bootloading Miguel
@ 2019-04-26 10:51 ` Miguel
  2019-05-03 12:27   ` Miguel
  2019-04-29  7:56 ` [bug#35394] [PATCH 0/3] Bootloader localization Ludovic Courtès
  2020-10-11 14:18 ` [bug#35394] [PATCH 1/1 v4] Grub i18n Miguel Ángel Arruga Vivas
  6 siblings, 1 reply; 20+ messages in thread
From: Miguel @ 2019-04-26 10:51 UTC (permalink / raw)
  To: 35394

[-- Attachment #1: Type: text/plain, Size: 309 bytes --]

system: Use locale information in grub.cfg.

* gnu/bootloader/grub.scm (module-declaration): Add (gnu system locale).
(locale-config-entries): New procedure.
(grub-configuration-file): Use locale-config-entries.
---
 gnu/bootloader/grub.scm | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0004-system-Use-locale-information-in-grub.cfg.patch --]
[-- Type: text/x-patch, Size: 2984 bytes --]

From 216f818bb27d3c491681c4d67e483279c3065b2f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
 <rosen644835@gmail.com>
Date: Fri, 26 Apr 2019 11:58:43 +0200
Subject: [PATCH 4/4] system: Use locale information in grub.cfg.

* gnu/bootloader/grub.scm (module-declaration): Add (gnu system locale).
(locale-config-entries): New procedure.
(grub-configuration-file): Use locale-config-entries.
---
 gnu/bootloader/grub.scm | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm
index 446f90157c..92c33063c3 100644
--- a/gnu/bootloader/grub.scm
+++ b/gnu/bootloader/grub.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
 ;;; Copyright © 2017 Leo Famulari <leo@famulari.name>
 ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
+;;; Copyright © 2019 Miguel Ángel Arruga Vivas <rosen644835@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -28,6 +29,7 @@
   #:use-module (gnu system uuid)
   #:use-module (gnu system file-systems)
   #:use-module (gnu system keyboard)
+  #:use-module (gnu system locale)
   #:autoload   (gnu packages bootloaders) (grub)
   #:autoload   (gnu packages gtk) (guile-cairo guile-rsvg)
   #:autoload   (gnu packages xorg) (xkeyboard-config)
@@ -216,6 +218,27 @@ fi~%"
                  #$(theme-colors grub-theme-color-normal)
                  #$(theme-colors grub-theme-color-highlight))))
 
+(define* (locale-config-entries config store-mount-point #:key locale port)
+  "Return a gexp that writes to PORT (a port-valued gexp) the
+'grub.cfg' part concerned with locale configuration."
+  (define grub (bootloader-package
+                (bootloader-configuration-bootloader config)))
+  (define (locale-dir)
+    #~(let ((dir #$grub:locale))
+        dir))
+  (define (lang-id)
+    (let ((definition (locale-name->definition locale)))
+      (locale-definition-source definition)))
+
+  (and locale
+       (member "locale" (package-outputs grub))
+       #~(format #$port "
+# Configure GRUB with the selected locale.
+set locale_dir=~a
+set lang=~a~%"
+                 #$(strip-mount-point store-mount-point (locale-dir))
+                 #$(lang-id))))
+
 \f
 ;;;
 ;;; Configuration file.
@@ -364,6 +387,10 @@ entries corresponding to old generations of the system."
 terminal_input at_keyboard
 insmod keylayouts
 keymap ~a~%" keymap)))))
+  (define locale-config
+    (locale-config-entries config
+                           (menu-entry-device-mount-point (first all-entries))
+                           #:locale locale #:port #~port))
 
   (define builder
     #~(call-with-output-file #$output
@@ -374,6 +401,7 @@ keymap ~a~%" keymap)))))
 ")
           #$sugar
           #$keyboard-layout-config
+          #$locale-config
           (format port "
 set default=~a
 set timeout=~a~%"
-- 
2.21.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [bug#35394] [PATCH 0/3] Bootloader localization
  2019-04-23 13:17 [bug#35394] [PATCH 0/3] Bootloader localization Miguel
                   ` (4 preceding siblings ...)
  2019-04-26 10:51 ` [bug#35394] [PATCH 4/4] system: Use locale information in grub.cfg Miguel
@ 2019-04-29  7:56 ` Ludovic Courtès
       [not found]   ` <20191021124035.531bed75@gmail.com>
  2020-10-11 14:18 ` [bug#35394] [PATCH 1/1 v4] Grub i18n Miguel Ángel Arruga Vivas
  6 siblings, 1 reply; 20+ messages in thread
From: Ludovic Courtès @ 2019-04-29  7:56 UTC (permalink / raw)
  To: Miguel; +Cc: 35394

Hi Miguel,

Miguel <rosen644835@gmail.com> skribis:

> As a Grub translator, I've been hacking a little bit in order to
> provide locale information to Grub. I use Guix in a daily basis, as my
> main computer operating system, and I this is a key step in order to
> provide a better experience to the all kind of users, who may do not
> know other languages than their native one.

Thanks a lot for this work.  FWIW, I’m holding off review and
integration after 1.0, but I’m happy if someone else reviews :-), and
I’ll be really happy to see it in master once 1.0 is out.

Ludo’.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [bug#35394] [PATCH 3/4] gnu: grub: Add locale output for bootloading.
  2019-04-26 10:50 ` [bug#35394] [PATCH 3/4] gnu: grub: Add locale output for bootloading Miguel
@ 2019-05-03 12:27   ` Miguel
  0 siblings, 0 replies; 20+ messages in thread
From: Miguel @ 2019-05-03 12:27 UTC (permalink / raw)
  To: 35394

[-- Attachment #1: Type: text/plain, Size: 424 bytes --]

Last patches contain a couple of problems, unbound variables are fixed
in the attached patch.  Commit message has been reworded. 

-----
gnu: grub: Add locale output.

* gnu/packages/bootloaders.scm (grub): Add new phase 'install-locale-folder
to generate new output used for bootloader localization.
---
 gnu/packages/bootloaders.scm | 33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)

[-- Attachment #2: 0003-gnu-grub-Add-locale-output.patch --]
[-- Type: text/x-patch, Size: 3706 bytes --]

From d8462c2b980eb8fc5eff3d97292bffea63a89ea9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
 <rosen644835@gmail.com>
Date: Fri, 26 Apr 2019 11:56:43 +0200
Subject: [PATCH 3/4] gnu: grub: Add locale output.

* gnu/packages/bootloaders.scm (grub): Add new phase 'install-locale-folder
to generate new output used for bootloader localization.
---
 gnu/packages/bootloaders.scm | 33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)

diff --git a/gnu/packages/bootloaders.scm b/gnu/packages/bootloaders.scm
index 6e6e69ff3b..71411ca954 100644
--- a/gnu/packages/bootloaders.scm
+++ b/gnu/packages/bootloaders.scm
@@ -94,7 +94,10 @@
                                       "grub-efi-fat-serial-number.patch"))))
     (build-system gnu-build-system)
     (arguments
-     `(#:phases (modify-phases %standard-phases
+     `(#:modules ((ice-9 ftw)
+                  (guix build utils)
+                  (guix build gnu-build-system))
+       #:phases (modify-phases %standard-phases
                   (add-after 'unpack 'patch-stuff
                    (lambda* (#:key inputs #:allow-other-keys)
                      (substitute* "grub-core/Makefile.in"
@@ -127,7 +130,30 @@
                       (substitute* "Makefile.in"
                         (("grub_cmd_date grub_cmd_set_date grub_cmd_sleep")
                           "grub_cmd_date grub_cmd_sleep"))
-                      #t)))
+                      #t))
+                  (add-after 'install 'install-locale-folder
+                    (lambda* (#:key outputs #:allow-other-keys)
+                      ;; XXX: Better checks are needed here
+                      (define (lang? file)
+                        (not (or (string=? file ".") (string=? file ".."))))
+                      (define (make-lang-installer to)
+                        (lambda (in-file stat flag)
+                          (if (eq? flag 'regular)
+                              (copy-file in-file to)
+                              #t)))
+
+                      (let* ((out (assoc-ref outputs "out"))
+                             (locale (string-append out "/share/locale"))
+                             (langs (scandir locale lang?))
+                             (locale-out (assoc-ref outputs "locale")))
+                        (mkdir-p locale-out)
+                        (for-each (lambda (lang)
+                                    (let ((from (string-append locale "/" lang))
+                                          (to (string-append locale-out "/"
+                                                             lang ".mo")))
+                                      (ftw from (make-lang-installer to))))
+                                  langs)
+                        #t))))
        ;; Disable tests on ARM and AARCH64 platforms.
        #:tests? ,(not (any (cute string-prefix? <> (or (%current-target-system)
                                                        (%current-system)))
@@ -183,6 +209,7 @@
        ("parted" ,parted)
        ("qemu" ,qemu-minimal-2.10)
        ("xorriso" ,xorriso)))
+    (outputs '("out" "locale"))
     (home-page "https://www.gnu.org/software/grub/")
     (synopsis "GRand Unified Boot loader")
     (description
@@ -249,8 +276,6 @@ menu to select one of the installed operating systems.")
        ,@(package-inputs grub-efi)))
     (arguments
      (substitute-keyword-arguments (package-arguments grub-efi)
-       ((#:modules modules `((guix build utils) (guix build gnu-build-system)))
-        `((ice-9 ftw) ,@modules))
        ((#:phases phases)
         `(modify-phases ,phases
            (add-after 'install 'install-non-efi
-- 
2.21.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [bug#35394] [PATCH 4/4] system: Use locale information in grub.cfg.
  2019-04-26 10:51 ` [bug#35394] [PATCH 4/4] system: Use locale information in grub.cfg Miguel
@ 2019-05-03 12:27   ` Miguel
  0 siblings, 0 replies; 20+ messages in thread
From: Miguel @ 2019-05-03 12:27 UTC (permalink / raw)
  To: 35394

[-- Attachment #1: Type: text/plain, Size: 342 bytes --]

This patch fixes the module uses.

---
system: Use locale information in grub.cfg.

* gnu/bootloader/grub.scm (module-declaration): Add dependencies.
(locale-config-entries): New procedure.
(grub-configuration-file): Use locale-config-entries.
---
 gnu/bootloader/grub.scm | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0004-system-Use-locale-information-in-grub.cfg.patch --]
[-- Type: text/x-patch, Size: 3223 bytes --]

From d8cd9d98670570e0a29892c8988d5b84b23662d2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
 <rosen644835@gmail.com>
Date: Fri, 26 Apr 2019 11:58:43 +0200
Subject: [PATCH 4/4] system: Use locale information in grub.cfg.

* gnu/bootloader/grub.scm (module-declaration): Add dependencies.
(locale-config-entries): New procedure.
(grub-configuration-file): Use locale-config-entries.
---
 gnu/bootloader/grub.scm | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm
index 446f90157c..13f4e57414 100644
--- a/gnu/bootloader/grub.scm
+++ b/gnu/bootloader/grub.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
 ;;; Copyright © 2017 Leo Famulari <leo@famulari.name>
 ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
+;;; Copyright © 2019 Miguel Ángel Arruga Vivas <rosen644835@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -21,6 +22,7 @@
 
 (define-module (gnu bootloader grub)
   #:use-module (guix records)
+  #:use-module (guix packages)
   #:use-module ((guix utils) #:select (%current-system))
   #:use-module (guix gexp)
   #:use-module (gnu artwork)
@@ -28,6 +30,7 @@
   #:use-module (gnu system uuid)
   #:use-module (gnu system file-systems)
   #:use-module (gnu system keyboard)
+  #:use-module (gnu system locale)
   #:autoload   (gnu packages bootloaders) (grub)
   #:autoload   (gnu packages gtk) (guile-cairo guile-rsvg)
   #:autoload   (gnu packages xorg) (xkeyboard-config)
@@ -216,6 +219,27 @@ fi~%"
                  #$(theme-colors grub-theme-color-normal)
                  #$(theme-colors grub-theme-color-highlight))))
 
+(define* (locale-config-entries config store-mount-point #:key locale port)
+  "Return a gexp that writes to PORT (a port-valued gexp) the
+'grub.cfg' part concerned with locale configuration."
+  (define grub (bootloader-package
+                (bootloader-configuration-bootloader config)))
+  (define (locale-dir)
+    #~(let ((dir #$grub:locale))
+        dir))
+  (define (lang-id)
+    (let ((definition (locale-name->definition locale)))
+      (locale-definition-source definition)))
+
+  (and locale
+       (member "locale" (package-outputs grub))
+       #~(format #$port "
+# Configure GRUB with the selected locale.
+set locale_dir=~a
+set lang=~a~%"
+                 #$(strip-mount-point store-mount-point (locale-dir))
+                 #$(lang-id))))
+
 \f
 ;;;
 ;;; Configuration file.
@@ -364,6 +388,10 @@ entries corresponding to old generations of the system."
 terminal_input at_keyboard
 insmod keylayouts
 keymap ~a~%" keymap)))))
+  (define locale-config
+    (locale-config-entries config
+                           (menu-entry-device-mount-point (first all-entries))
+                           #:locale locale #:port #~port))
 
   (define builder
     #~(call-with-output-file #$output
@@ -374,6 +402,7 @@ keymap ~a~%" keymap)))))
 ")
           #$sugar
           #$keyboard-layout-config
+          #$locale-config
           (format port "
 set default=~a
 set timeout=~a~%"
-- 
2.21.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [bug#35394] [PATCH 1/3] system: Add locale to boot-parameters.
       [not found]   ` <20191021124035.531bed75@gmail.com>
@ 2019-10-21 10:46     ` Miguel Arruga Vivas
  2019-10-21 10:46     ` [bug#35394] [PATCH 2/3] system: Provide locale information to the bootloader Miguel Arruga Vivas
  2019-10-21 10:46     ` [bug#35394] [PATCH 3/3] system: Use locale information in grub.cfg Miguel Arruga Vivas
  2 siblings, 0 replies; 20+ messages in thread
From: Miguel Arruga Vivas @ 2019-10-21 10:46 UTC (permalink / raw)
  To: 35394

[-- Attachment #1: Type: text/plain, Size: 686 bytes --]

* gnu/system.scm (define-module)[export]: Add boot-parameters-locale.
(<boot-parameters>)[locale]: New field.
[boot-parameters-locale]: New accessor.
(read-boot-parameters): Read locale field.
(operating-system-boot-parameters): Provide operating-system locale to
boot-parameters record.
(opeating-system-boot-parameters-file): Likewise.
* Makefile.am (SCM_TESTS): Add tests/boot-parameters.scm.
* tests/boot-parameters.scm: New test file.
---
 Makefile.am               |   1 +
 gnu/system.scm            |  19 ++-
 tests/boot-parameters.scm | 250 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 266 insertions(+), 4 deletions(-)
 create mode 100644 tests/boot-parameters.scm

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-system-Add-locale-to-boot-parameters.patch --]
[-- Type: text/x-patch, Size: 14861 bytes --]

From 7a811fae4f44c279f773a9ad8201f61edab100f6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
 <rosen644835@gmail.com>
Date: Mon, 21 Oct 2019 12:23:40 +0200
Subject: [PATCH 1/3] system: Add locale to boot-parameters.

* gnu/system.scm (define-module)[export]: Add boot-parameters-locale.
(<boot-parameters>)[locale]: New field.
[boot-parameters-locale]: New accessor.
(read-boot-parameters): Read locale field.
(operating-system-boot-parameters): Provide operating-system locale to
boot-parameters record.
(opeating-system-boot-parameters-file): Likewise.
* Makefile.am (SCM_TESTS): Add tests/boot-parameters.scm.
* tests/boot-parameters.scm: New test file.
---
 Makefile.am               |   1 +
 gnu/system.scm            |  19 ++-
 tests/boot-parameters.scm | 250 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 266 insertions(+), 4 deletions(-)
 create mode 100644 tests/boot-parameters.scm

diff --git a/Makefile.am b/Makefile.am
index 36767c2f47..6784ecea81 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -384,6 +384,7 @@ SCM_TESTS =					\
   tests/build-utils.scm			\
   tests/cache.scm				\
   tests/challenge.scm				\
+  tests/boot-parameters.scm			\
   tests/channels.scm				\
   tests/combinators.scm			\
   tests/containers.scm				\
diff --git a/gnu/system.scm b/gnu/system.scm
index a353b1a5c8..be49724bc3 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -5,6 +5,7 @@
 ;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
 ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;; Copyright © 2019 Meiyo Peng <meiyo.peng@gmail.com>
+;;; Copyright © 2019 Miguel Ángel Arruga Vivas <rosen644835@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -122,6 +123,7 @@
             boot-parameters-kernel
             boot-parameters-kernel-arguments
             boot-parameters-initrd
+            boot-parameters-locale
             read-boot-parameters
             read-boot-parameters-file
             boot-parameters->menu-entry
@@ -258,7 +260,8 @@ directly by the user."
   (store-mount-point boot-parameters-store-mount-point)
   (kernel           boot-parameters-kernel)
   (kernel-arguments boot-parameters-kernel-arguments)
-  (initrd           boot-parameters-initrd))
+  (initrd           boot-parameters-initrd)
+  (locale           boot-parameters-locale))
 
 (define (ensure-not-/dev device)
   "If DEVICE starts with a slash, return #f.  This is meant to filter out
@@ -341,7 +344,12 @@ file system labels."
          (('store ('device _) ('mount-point mount-point) _ ...)
           mount-point)
          (_                                       ;the old format
-          "/")))))
+          "/")))
+
+      (locale
+       (match (assq 'locale rest)
+         ((_ locale) locale)
+         (#f         #f)))))
     (x                                            ;unsupported format
      (warning (G_ "unrecognized boot parameters at '~a'~%")
               (port-filename port))
@@ -1008,6 +1016,7 @@ parameters of OS.  When SYSTEM-KERNEL-ARGUMENTS? is true, add kernel arguments
 such as '--root' and '--load' to <boot-parameters>."
   (let* ((initrd          (operating-system-initrd-file os))
          (store           (operating-system-store-file-system os))
+         (locale          (operating-system-locale os))
          (bootloader      (bootloader-configuration-bootloader
                            (operating-system-bootloader os)))
          (bootloader-name (bootloader-name bootloader))
@@ -1025,7 +1034,8 @@ such as '--root' and '--load' to <boot-parameters>."
      (bootloader-menu-entries
       (bootloader-configuration-menu-entries (operating-system-bootloader os)))
      (store-device (ensure-not-/dev (file-system-device store)))
-     (store-mount-point (file-system-mount-point store)))))
+     (store-mount-point (file-system-mount-point store))
+     (locale locale))))
 
 (define (device->sexp device)
   "Serialize DEVICE as an sexp (really, as an object with a read syntax.)"
@@ -1073,7 +1083,8 @@ being stored into the \"parameters\" file)."
                     (store
                      (device
                       #$(device->sexp (boot-parameters-store-device params)))
-                     (mount-point #$(boot-parameters-store-mount-point params))))
+                     (mount-point #$(boot-parameters-store-mount-point params)))
+                    (locale #$(boot-parameters-locale params)))
                  #:set-load-path? #f)))
 
 (define-gexp-compiler (operating-system-compiler (os <operating-system>)
diff --git a/tests/boot-parameters.scm b/tests/boot-parameters.scm
new file mode 100644
index 0000000000..3746502498
--- /dev/null
+++ b/tests/boot-parameters.scm
@@ -0,0 +1,250 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2019 Miguel Ángel Arruga Vivas <rosen644835@gmail.com>
+;;;
+;;; 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/>.
+
+;;; Commentary:
+;;;
+;;; Test boot parameters value storage and compatibility.
+;;;
+;;; Code:
+
+(define-module (test-boot-parameters)
+  #:use-module (gnu bootloader)
+  #:use-module (gnu bootloader grub)
+  #:use-module (gnu system)
+  #:use-module (gnu system file-systems)
+  #:use-module (gnu system uuid)
+  #:use-module (guix gexp)
+  #:use-module (guix store)
+  #:use-module (guix tests)
+  #:use-module (srfi srfi-64)
+  #:use-module (rnrs bytevectors))
+
+(define %default-label "GNU with Linux-libre 99.1.2")
+(define %default-kernel-path
+  (string-append (%store-prefix)
+                 "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-linux-libre-99.1.2"))
+(define %default-kernel
+  (string-append %default-kernel-path "/" (system-linux-image-file-name)))
+(define %default-kernel-arguments '())
+(define %default-initrd-path
+  (string-append (%store-prefix) "/wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww-initrd"))
+(define %default-initrd (string-append %default-initrd-path "/initrd.cpio.gz"))
+(define %default-root-device (uuid "abcdef12-3456-7890-abcd-ef1234567890"))
+(define %default-store-device (uuid "01234567-89ab-cdef-0123-456789abcdef"))
+(define %default-store-mount-point (%store-prefix))
+(define %default-locale "es_ES.utf8")
+(define %root-path "/")
+
+(define %grub-boot-parameters
+  (boot-parameters
+   (bootloader-name 'grub)
+   (bootloader-menu-entries '())
+   (label %default-label)
+   (root-device %default-root-device)
+   (kernel %default-kernel)
+   (kernel-arguments %default-kernel-arguments)
+   (initrd %default-initrd)
+   (store-device %default-store-device)
+   (store-mount-point %default-store-mount-point)
+   (locale %default-locale)))
+
+(define %default-operating-system
+  (operating-system
+    (host-name "host")
+    (timezone "Europe/Berlin")
+    (locale %default-locale)
+
+    (bootloader (bootloader-configuration
+                 (bootloader grub-bootloader)
+                 (target "/dev/sda")))
+    (file-systems (cons* (file-system
+                           (device %default-root-device)
+                           (mount-point %root-path)
+                           (type "ext4"))
+		         (file-system
+                           (device %default-store-device)
+                           (mount-point %default-store-mount-point)
+                           (type "btrfs"))
+                         %base-file-systems))))
+
+(define (quote-uuid uuid)
+  (list 'uuid (uuid-type uuid) (uuid-bytevector uuid)))
+
+;; Call read-boot-parameters with the desired string as input.
+(define* (test-read-boot-parameters
+          #:key
+          (version 0)
+          (bootloader-name 'grub)
+          (bootloader-menu-entries '())
+          (label %default-label)
+          (root-device (quote-uuid %default-root-device))
+          (kernel %default-kernel)
+          (kernel-arguments %default-kernel-arguments)
+          (initrd %default-initrd)
+          (with-store #t)
+          (store-device
+           (quote-uuid %default-store-device))
+          (store-mount-point %default-store-mount-point)
+          (locale %default-locale))
+  (define (generate-boot-parameters)
+    (define (sexp-or-nothing fmt val)
+      (cond ((eq? 'false val) (format #f fmt #f))
+            (val              (format #f fmt val))
+            (else             "")))
+    (format #f "(boot-parameters~a~a~a~a~a~a~a~a~a~a)"
+            (sexp-or-nothing " (version ~S)" version)
+            (sexp-or-nothing " (label ~S)" label)
+            (sexp-or-nothing " (root-device ~S)" root-device)
+            (sexp-or-nothing " (kernel ~S)" kernel)
+            (sexp-or-nothing " (kernel-arguments ~S)" kernel-arguments)
+            (sexp-or-nothing " (initrd ~S)" initrd)
+            (if with-store
+                (format #f " (store~a~a)"
+                        (sexp-or-nothing " (device ~S)" store-device)
+                        (sexp-or-nothing " (mount-point ~S)"
+                                         store-mount-point))
+                "")
+            (sexp-or-nothing " (locale ~S)" locale)
+            (sexp-or-nothing " (bootloader-name ~a)" bootloader-name)
+            (sexp-or-nothing " (bootloader-menu-entries ~S)"
+                             bootloader-menu-entries)))
+  (let ((str (generate-boot-parameters)))
+    (call-with-input-string str read-boot-parameters)))
+
+(test-begin "boot-parameters")
+
+;; XXX: <warning: unrecognized boot parameters at '#f'>
+(test-assert "read, construction, mandatory fields"
+  (not (or (test-read-boot-parameters #:version #f)
+           (test-read-boot-parameters #:version 'false)
+           (test-read-boot-parameters #:version -1)
+           (test-read-boot-parameters #:version "0")
+           (test-read-boot-parameters #:root-device #f)
+           (test-read-boot-parameters #:kernel #f)
+           (test-read-boot-parameters #:label #f))))
+
+(test-assert "read, construction, optional fields"
+  (and (test-read-boot-parameters #:bootloader-name #f)
+       (test-read-boot-parameters #:bootloader-menu-entries #f)
+       (test-read-boot-parameters #:kernel-arguments #f)
+       (test-read-boot-parameters #:with-store #f)
+       (test-read-boot-parameters #:store-device #f)
+       (test-read-boot-parameters #:store-device 'false)
+       (test-read-boot-parameters #:store-mount-point #f)
+       (test-read-boot-parameters #:locale #f)
+       (test-read-boot-parameters #:bootloader-name #f #:kernel-arguments #f
+                                  #:with-store #f #:locale #f)))
+
+(test-equal "read, default equality"
+  %grub-boot-parameters
+  (test-read-boot-parameters))
+
+(test-equal "read, root-device, label"
+  (file-system-label "my-root")
+  (boot-parameters-root-device
+   (test-read-boot-parameters #:root-device '(file-system-label "my-root"))))
+
+(test-equal "read, root-device, /dev node"
+  "/dev/sda2"
+  (boot-parameters-root-device
+   (test-read-boot-parameters #:root-device "/dev/sda2")))
+
+(test-equal "read, kernel, only store path"
+  %default-kernel
+  (boot-parameters-kernel
+   (test-read-boot-parameters #:kernel %default-kernel-path)))
+
+(test-equal "read, kernel, full-path"
+  %default-kernel
+  (boot-parameters-kernel
+   (test-read-boot-parameters #:kernel %default-kernel)))
+
+;; XXX: No default case, match error.
+(test-error "read, construction, missing initrd" #t
+            (test-read-boot-parameters #:initrd #f))
+
+(test-equal "read, initrd, old format"
+  "/a/b"
+  (boot-parameters-initrd
+   (test-read-boot-parameters #:initrd (list 'string-append "/a" "/b"))))
+
+ ;; Compatibility reasons specified in gnu/system.scm.
+(test-eq "read, bootloader-name, default value"
+  'grub
+  (boot-parameters-bootloader-name
+   (test-read-boot-parameters #:bootloader-name #f)))
+
+(test-eq "read, bootloader-menu-entries, default value"
+  '()
+  (boot-parameters-bootloader-menu-entries
+   (test-read-boot-parameters #:bootloader-menu-entries #f)))
+
+(test-eq "read, kernel-arguments, default value"
+  '()
+  (boot-parameters-kernel-arguments
+   (test-read-boot-parameters #:kernel-arguments #f)))
+
+(test-assert "read, store-device, filter /dev"
+  (not (boot-parameters-store-device
+        (test-read-boot-parameters #:store-device "/dev/sda3"))))
+
+(test-assert "read, no-store, filter /dev from root"
+  (not (boot-parameters-store-device
+        (test-read-boot-parameters #:root-device "/dev/sda3" #:with-store #f))))
+
+(test-assert "read, no store-device, filter /dev from root"
+  (not (boot-parameters-store-device
+        (test-read-boot-parameters #:root-device "/dev/sda3"
+                                   #:store-device #f))))
+
+(test-assert "read, store-device #f, filter /dev from root"
+  (not (boot-parameters-store-device
+        (test-read-boot-parameters #:root-device "/dev/sda3"
+                                   #:store-device 'false))))
+
+(test-equal "read, store-device, label (legacy)"
+  (file-system-label "my-store")
+  (boot-parameters-store-device
+   (test-read-boot-parameters #:store-device "my-store")))
+
+(test-equal "read, store-device, from root"
+  %default-root-device
+  (boot-parameters-store-device
+   (test-read-boot-parameters #:with-store #f)))
+
+(test-equal "read, no store-mount-point, default"
+  %root-path
+  (boot-parameters-store-mount-point
+   (test-read-boot-parameters #:store-mount-point #f)))
+
+(test-equal "read, no store, default store-mount-point"
+  %root-path
+  (boot-parameters-store-mount-point
+   (test-read-boot-parameters #:with-store #f)))
+
+;; For whitebox testing
+(define operating-system-boot-parameters
+  (@@ (gnu system) operating-system-boot-parameters))
+
+(test-equal "from os, locale"
+  %default-locale
+  (boot-parameters-locale
+   (operating-system-boot-parameters %default-operating-system
+                                     %default-root-device)))
+
+(test-end "boot-parameters")
-- 
2.23.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [bug#35394] [PATCH 2/3] system: Provide locale information to the bootloader.
       [not found]   ` <20191021124035.531bed75@gmail.com>
  2019-10-21 10:46     ` [bug#35394] [PATCH 1/3] system: Add locale to boot-parameters Miguel Arruga Vivas
@ 2019-10-21 10:46     ` Miguel Arruga Vivas
  2019-10-21 10:46     ` [bug#35394] [PATCH 3/3] system: Use locale information in grub.cfg Miguel Arruga Vivas
  2 siblings, 0 replies; 20+ messages in thread
From: Miguel Arruga Vivas @ 2019-10-21 10:46 UTC (permalink / raw)
  To: 35394

[-- Attachment #1: Type: text/plain, Size: 663 bytes --]

* gnu/bootloader/depthcharge.scm (depthcharge-configuration-file): Add
locale keyword.
* gnu/bootloader/extlinux.scm (extlinux-configuration-file): Likewise.
* gnu/bootloader/grub.scm (grub-configuration-file): Likewise.
* gnu/system.scm (operating-system-bootcfg): Provide locale information
to the bootloader.
* guix/system/script.scm (reinstall-bootloader): Use locale information
from boot-parameters.
---
 gnu/bootloader/depthcharge.scm | 3 ++-
 gnu/bootloader/extlinux.scm    | 3 ++-
 gnu/bootloader/grub.scm        | 3 ++-
 gnu/system.scm                 | 4 +++-
 guix/scripts/system.scm        | 4 +++-
 5 files changed, 12 insertions(+), 5 deletions(-)

[-- Attachment #2: 0002-system-Provide-locale-information-to-the-bootloader.patch --]
[-- Type: text/x-patch, Size: 5184 bytes --]

From 4b3e52ff532b93611893a60a02d3fe21dca98276 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
 <rosen644835@gmail.com>
Date: Mon, 22 Apr 2019 14:44:22 +0200
Subject: [PATCH 2/3] system: Provide locale information to the bootloader.

* gnu/bootloader/depthcharge.scm (depthcharge-configuration-file): Add
locale keyword.
* gnu/bootloader/extlinux.scm (extlinux-configuration-file): Likewise.
* gnu/bootloader/grub.scm (grub-configuration-file): Likewise.
* gnu/system.scm (operating-system-bootcfg): Provide locale information
to the bootloader.
* guix/system/script.scm (reinstall-bootloader): Use locale information
from boot-parameters.
---
 gnu/bootloader/depthcharge.scm | 3 ++-
 gnu/bootloader/extlinux.scm    | 3 ++-
 gnu/bootloader/grub.scm        | 3 ++-
 gnu/system.scm                 | 4 +++-
 guix/scripts/system.scm        | 4 +++-
 5 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/gnu/bootloader/depthcharge.scm b/gnu/bootloader/depthcharge.scm
index 58cc3f3932..0e0c17a255 100644
--- a/gnu/bootloader/depthcharge.scm
+++ b/gnu/bootloader/depthcharge.scm
@@ -82,7 +82,8 @@
 (define* (depthcharge-configuration-file config entries
                                          #:key
                                          (system (%current-system))
-                                         (old-entries '()))
+                                         (old-entries '())
+                                         (locale #f))
   (match entries
     ((entry)
      (let ((kernel (menu-entry-linux entry))
diff --git a/gnu/bootloader/extlinux.scm b/gnu/bootloader/extlinux.scm
index 40108584a8..e4ccc47484 100644
--- a/gnu/bootloader/extlinux.scm
+++ b/gnu/bootloader/extlinux.scm
@@ -28,7 +28,8 @@
 (define* (extlinux-configuration-file config entries
                                       #:key
                                       (system (%current-system))
-                                      (old-entries '()))
+                                      (old-entries '())
+                                      (locale #f))
   "Return the U-Boot configuration file corresponding to CONFIG, a
 <u-boot-configuration> object, and where the store is available at STORE-FS, a
 <file-system> object.  OLD-ENTRIES is taken to be a list of menu entries
diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm
index d984d5f5e3..a0d068d1bd 100644
--- a/gnu/bootloader/grub.scm
+++ b/gnu/bootloader/grub.scm
@@ -316,7 +316,8 @@ code."
 (define* (grub-configuration-file config entries
                                   #:key
                                   (system (%current-system))
-                                  (old-entries '()))
+                                  (old-entries '())
+                                  (locale #f))
   "Return the GRUB configuration file corresponding to CONFIG, a
 <bootloader-configuration> object, and where the store is available at
 STORE-FS, a <file-system> object.  OLD-ENTRIES is taken to be a list of menu
diff --git a/gnu/system.scm b/gnu/system.scm
index be49724bc3..00f24f2e39 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -997,6 +997,7 @@ entry."
 a list of <menu-entry>, to populate the \"old entries\" menu."
   (let* ((root-fs         (operating-system-root-file-system os))
          (root-device     (file-system-device root-fs))
+         (locale          (operating-system-locale os))
          (params          (operating-system-boot-parameters
                            os root-device
                            #:system-kernel-arguments? #t))
@@ -1007,7 +1008,8 @@ a list of <menu-entry>, to populate the \"old entries\" menu."
        (bootloader-configuration-bootloader bootloader-conf)))
 
     (generate-config-file bootloader-conf (list entry)
-                          #:old-entries old-entries)))
+                          #:old-entries old-entries
+                          #:locale locale)))
 
 (define* (operating-system-boot-parameters os root-device
                                            #:key system-kernel-arguments?)
diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm
index 27b014db68..f008405115 100644
--- a/guix/scripts/system.scm
+++ b/guix/scripts/system.scm
@@ -386,6 +386,7 @@ STORE is an open connection to the store."
          ;; Make the specified system generation the default entry.
          (params (first (profile-boot-parameters %system-profile
                                                  (list number))))
+         (locale (boot-parameters-locale params))
          (old-generations
           (delv number (reverse (generation-numbers %system-profile))))
          (old-params (profile-boot-parameters
@@ -398,7 +399,8 @@ STORE is an open connection to the store."
           ((bootcfg (lower-object
                      ((bootloader-configuration-file-generator bootloader)
                       bootloader-config entries
-                      #:old-entries old-entries)))
+                      #:old-entries old-entries
+                      #:locale locale)))
            (drvs -> (list bootcfg)))
         (mbegin %store-monad
           (show-what-to-build* drvs)
-- 
2.23.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [bug#35394] [PATCH 3/3] system: Use locale information in grub.cfg.
       [not found]   ` <20191021124035.531bed75@gmail.com>
  2019-10-21 10:46     ` [bug#35394] [PATCH 1/3] system: Add locale to boot-parameters Miguel Arruga Vivas
  2019-10-21 10:46     ` [bug#35394] [PATCH 2/3] system: Provide locale information to the bootloader Miguel Arruga Vivas
@ 2019-10-21 10:46     ` Miguel Arruga Vivas
  2 siblings, 0 replies; 20+ messages in thread
From: Miguel Arruga Vivas @ 2019-10-21 10:46 UTC (permalink / raw)
  To: 35394

[-- Attachment #1: Type: text/plain, Size: 311 bytes --]

* gnu/bootloader/grub.scm (define-module): Add new dependency.
(grub-configuration-file)[locale-config]: New variable with generated
locale configuration when locale parameter has been provided.
[builder]: Add locale-config.
---
 gnu/bootloader/grub.scm | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0003-system-Use-locale-information-in-grub.cfg.patch --]
[-- Type: text/x-patch, Size: 2400 bytes --]

From c5f4f7d0d3564731dc29f563b70a05ab83eec061 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
 <rosen644835@gmail.com>
Date: Sat, 19 Oct 2019 13:28:48 +0200
Subject: [PATCH 3/3] system: Use locale information in grub.cfg.

* gnu/bootloader/grub.scm (define-module): Add new dependency.
(grub-configuration-file)[locale-config]: New variable with generated
locale configuration when locale parameter has been provided.
[builder]: Add locale-config.
---
 gnu/bootloader/grub.scm | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm
index a0d068d1bd..8c3bab6fa7 100644
--- a/gnu/bootloader/grub.scm
+++ b/gnu/bootloader/grub.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
 ;;; Copyright © 2017 Leo Famulari <leo@famulari.name>
 ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
+;;; Copyright © 2019 Miguel Ángel Arruga Vivas <rosen644835@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -28,6 +29,7 @@
   #:use-module (gnu system uuid)
   #:use-module (gnu system file-systems)
   #:use-module (gnu system keyboard)
+  #:use-module (gnu system locale)
   #:autoload   (gnu packages bootloaders) (grub)
   #:autoload   (gnu packages gtk) (guile-cairo guile-rsvg)
   #:autoload   (gnu packages xorg) (xkeyboard-config)
@@ -353,6 +355,20 @@ entries corresponding to old generations of the system."
                #:system system
                #:port #~port))
 
+  (define locale-config
+    #~(let ((locale #$(and locale
+                           (locale-definition-source
+                            (locale-name->definition locale)))))
+        (when locale
+          (format port "\
+# Localization configuration.
+if search --file --set boot_partition /grub/grub.cfg; then
+    set locale_dir=(${boot_partition})/grub/locale
+else
+    set locale_dir=/boot/grub/locale
+fi
+set lang=~a~%" locale))))
+
   (define keyboard-layout-config
     (let ((layout (bootloader-configuration-keyboard-layout config))
           (grub   (bootloader-package
@@ -372,6 +388,7 @@ keymap ~a~%" keymap)))))
 # will be lost upon reconfiguration.
 ")
           #$sugar
+          #$locale-config
           #$keyboard-layout-config
           (format port "
 set default=~a
-- 
2.23.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [bug#35394] [PATCH 1/1 v4] Grub i18n
  2019-04-23 13:17 [bug#35394] [PATCH 0/3] Bootloader localization Miguel
                   ` (5 preceding siblings ...)
  2019-04-29  7:56 ` [bug#35394] [PATCH 0/3] Bootloader localization Ludovic Courtès
@ 2020-10-11 14:18 ` Miguel Ángel Arruga Vivas
  2020-10-17 16:32   ` Ludovic Courtès
  6 siblings, 1 reply; 20+ messages in thread
From: Miguel Ángel Arruga Vivas @ 2020-10-11 14:18 UTC (permalink / raw)
  To: 35394

[-- Attachment #1: Type: text/plain, Size: 288 bytes --]

Hi,

This is the latest version of the patch, that could be applied to
master.

They have been reduced to one patch, and as on previous versions of this
series of patches only the grub messages are translated, not the menu
entries generated by guix (yet).

WDYT?

Best regards,
Miguel
--

[-- Attachment #2: 0001-service-add-locale-to-grub.patch --]
[-- Type: text/x-patch, Size: 9680 bytes --]

From 885a7c167faafa295b0f3edaae1ee456eacf1e63 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
 <rosen644835@gmail.com>
Date: Sat, 2 Nov 2019 18:18:45 +0100
Subject: [PATCH] system: Use locale information in grub.cfg.

* gnu/bootloader/grub.scm (define-module): Add new dependency.
(grub-configuration-file): Add locale keyword.
(grub-configuration-file)[locale-config]: New variable with generated
locale configuration when locale parameter has been provided.
[builder]: Add locale-config.
* gnu/machine/ssh.scm (roll-back-managed-host): Use locale information
from boot-parameters.
* gnu/system.scm (define-module)[export]: Add boot-parameters-locale.
(<boot-parameters>)[locale]: New field.
[boot-parameters-locale]: New accessor.
(read-boot-parameters): Read locale field.
(operating-system-boot-parameters): Provide operating-system locale to
oboot-parameters record.
(operating-system-boot-parameters-file): Likewise.
(operating-system-bootcfg): Provide locale information to the bootloader.
* guix/system/script.scm (reinstall-bootloader): Likewise.
---
 gnu/bootloader/grub.scm | 18 ++++++++++++++++++
 gnu/machine/ssh.scm     |  3 +++
 gnu/system.scm          | 13 +++++++++++++
 guix/scripts/system.scm |  2 ++
 4 files changed, 36 insertions(+)

diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm
index 516a7d48c8..611580a350 100644
--- a/gnu/bootloader/grub.scm
+++ b/gnu/bootloader/grub.scm
@@ -4,6 +4,7 @@
 ;;; Copyright © 2017 Leo Famulari <leo@famulari.name>
 ;;; Copyright © 2017, 2020 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;; Copyright © 2019, 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+;;; Copyright © 2019 Miguel Ángel Arruga Vivas <rosen644835@gmail.com>
 ;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 ;;; Copyright © 2020 Stefan <stefan-guix@vodafonemail.de>
 ;;;
@@ -33,6 +34,7 @@
   #:use-module (gnu system uuid)
   #:use-module (gnu system file-systems)
   #:use-module (gnu system keyboard)
+  #:use-module (gnu system locale)
   #:use-module (gnu packages bootloaders)
   #:autoload   (gnu packages gtk) (guile-cairo guile-rsvg)
   #:autoload   (gnu packages xorg) (xkeyboard-config)
@@ -334,6 +336,7 @@ code."
 
 (define* (grub-configuration-file config entries
                                   #:key
+                                  (locale #f)
                                   (system (%current-system))
                                   (old-entries '())
                                   store-directory-prefix)
@@ -398,6 +401,20 @@ menuentry ~s {
                  #:store-directory-prefix store-directory-prefix
                  #:port #~port)))
 
+  (define locale-config
+    #~(let ((locale #$(and locale
+                           (locale-definition-source
+                            (locale-name->definition locale)))))
+        (when locale
+          (format port "\
+# Localization configuration.
+if search --file --set boot_partition /grub/grub.cfg; then
+    set locale_dir=(${boot_partition})/grub/locale
+else
+    set locale_dir=/boot/grub/locale
+fi
+set lang=~a~%" locale))))
+
   (define keyboard-layout-config
     (let* ((layout (bootloader-configuration-keyboard-layout config))
            (grub   (bootloader-package
@@ -422,6 +439,7 @@ keymap ~a~%" #$keymap))))
 # will be lost upon reconfiguration.
 ")
           #$(sugar)
+          #$locale-config
           #$keyboard-layout-config
           (format port "
 set default=~a
diff --git a/gnu/machine/ssh.scm b/gnu/machine/ssh.scm
index 35b42add48..72ba6bfacf 100644
--- a/gnu/machine/ssh.scm
+++ b/gnu/machine/ssh.scm
@@ -484,11 +484,14 @@ an environment type of 'managed-host."
                                             (drop boot-parameters 2)))
                        (bootloader -> (operating-system-bootloader
                                        (machine-operating-system machine)))
+                       (locale -> (boot-parameters-locale
+                                   (second boot-parameters)))
                        (bootcfg (lower-object
                                  ((bootloader-configuration-file-generator
                                    (bootloader-configuration-bootloader
                                     bootloader))
                                   bootloader entries
+                                  #:locale locale
                                   #:old-entries old-entries)))
                        (remote-result (machine-remote-eval machine remote-exp)))
     (when (eqv? 'error remote-result)
diff --git a/gnu/system.scm b/gnu/system.scm
index ab1b0ff3de..32e0eeaf17 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -5,6 +5,7 @@
 ;;; Copyright © 2016 Chris Marusich <cmmarusich@gmail.com>
 ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
 ;;; Copyright © 2019 Meiyo Peng <meiyo.peng@gmail.com>
+;;; Copyright © 2019 Miguel Ángel Arruga Vivas <rosen644835@gmail.com>
 ;;; Copyright © 2020 Danny Milosavljevic <dannym@scratchpost.org>
 ;;; Copyright © 2020 Brice Waegeneire <brice@waegenei.re>
 ;;; Copyright © 2020 Florian Pelz <pelzflorian@pelzflorian.de>
@@ -147,6 +148,7 @@
             boot-parameters-kernel-arguments
             boot-parameters-initrd
             boot-parameters-multiboot-modules
+            boot-parameters-locale
             read-boot-parameters
             read-boot-parameters-file
             boot-parameters->menu-entry
@@ -291,6 +293,7 @@ directly by the user."
    boot-parameters-bootloader-menu-entries)
   (store-device     boot-parameters-store-device)
   (store-mount-point boot-parameters-store-mount-point)
+  (locale           boot-parameters-locale)
   (kernel           boot-parameters-kernel)
   (kernel-arguments boot-parameters-kernel-arguments)
   (initrd           boot-parameters-initrd)
@@ -368,6 +371,11 @@ file system labels."
          ((_ args) args)
          (#f       '())))
 
+      (locale
+       (match (assq 'locale rest)
+         ((_ locale) locale)
+         (#f         #f)))
+
       (store-device
        ;; Linux device names like "/dev/sda1" are not suitable GRUB device
        ;; identifiers, so we just filter them out.
@@ -1214,6 +1222,7 @@ a list of <menu-entry>, to populate the \"old entries\" menu."
   (let* ((file-systems    (operating-system-file-systems os))
          (root-fs         (operating-system-root-file-system os))
          (root-device     (file-system-device root-fs))
+         (locale          (operating-system-locale os))
          (params          (operating-system-boot-parameters
                            os root-device
                            #:system-kernel-arguments? #t))
@@ -1225,6 +1234,7 @@ a list of <menu-entry>, to populate the \"old entries\" menu."
        (bootloader-configuration-bootloader bootloader-conf)))
 
     (generate-config-file bootloader-conf (list entry)
+                          #:locale locale
                           #:old-entries old-entries
                           #:store-directory-prefix
 			  (btrfs-store-subvolume-file-name file-systems))))
@@ -1264,6 +1274,7 @@ such as '--root' and '--load' to <boot-parameters>."
   (let* ((initrd          (and (not (operating-system-hurd os))
                                (operating-system-initrd-file os)))
          (store           (operating-system-store-file-system os))
+         (locale          (operating-system-locale os))
          (bootloader      (bootloader-configuration-bootloader
                            (operating-system-bootloader os)))
          (bootloader-name (bootloader-name bootloader))
@@ -1282,6 +1293,7 @@ such as '--root' and '--load' to <boot-parameters>."
      (bootloader-name bootloader-name)
      (bootloader-menu-entries
       (bootloader-configuration-menu-entries (operating-system-bootloader os)))
+     (locale locale)
      (store-device (ensure-not-/dev (file-system-device store)))
      (store-mount-point (file-system-mount-point store)))))
 
@@ -1334,6 +1346,7 @@ being stored into the \"parameters\" file)."
                              (or (and=> (operating-system-bootloader os)
                                         bootloader-configuration-menu-entries)
                                  '())))
+                     (locale #$(boot-parameters-locale params))
                      (store
                       (device
                        #$(device->sexp (boot-parameters-store-device params)))
diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm
index 939559e719..9ed5c26483 100644
--- a/guix/scripts/system.scm
+++ b/guix/scripts/system.scm
@@ -384,6 +384,7 @@ STORE is an open connection to the store."
          ;; Make the specified system generation the default entry.
          (params (first (profile-boot-parameters %system-profile
                                                  (list number))))
+         (locale (boot-parameters-locale params))
          (old-generations
           (delv number (reverse (generation-numbers %system-profile))))
          (old-params (profile-boot-parameters
@@ -396,6 +397,7 @@ STORE is an open connection to the store."
           ((bootcfg (lower-object
                      ((bootloader-configuration-file-generator bootloader)
                       bootloader-config entries
+                      #:locale locale
                       #:old-entries old-entries)))
            (drvs -> (list bootcfg)))
         (mbegin %store-monad
-- 
2.28.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [bug#35394] [PATCH 1/1 v4] Grub i18n
  2020-10-11 14:18 ` [bug#35394] [PATCH 1/1 v4] Grub i18n Miguel Ángel Arruga Vivas
@ 2020-10-17 16:32   ` Ludovic Courtès
  2020-10-18 15:09     ` [bug#35394] [PATCH 4/4 " Miguel Ángel Arruga Vivas
  0 siblings, 1 reply; 20+ messages in thread
From: Ludovic Courtès @ 2020-10-17 16:32 UTC (permalink / raw)
  To: Miguel Ángel Arruga Vivas; +Cc: 35394

Hi Miguel,

Miguel Ángel Arruga Vivas <rosen644835@gmail.com> skribis:

> This is the latest version of the patch, that could be applied to
> master.
>
> They have been reduced to one patch, and as on previous versions of this
> series of patches only the grub messages are translated, not the menu
> entries generated by guix (yet).

Sounds good.  I think the way you split patches in v3 was fine too (the
added test was also a nice bonus), so I actually have a slight
preference for v3.

>>From 885a7c167faafa295b0f3edaae1ee456eacf1e63 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
>  <rosen644835@gmail.com>
> Date: Sat, 2 Nov 2019 18:18:45 +0100
> Subject: [PATCH] system: Use locale information in grub.cfg.
>
> * gnu/bootloader/grub.scm (define-module): Add new dependency.
> (grub-configuration-file): Add locale keyword.
> (grub-configuration-file)[locale-config]: New variable with generated
> locale configuration when locale parameter has been provided.
> [builder]: Add locale-config.
> * gnu/machine/ssh.scm (roll-back-managed-host): Use locale information
> from boot-parameters.
> * gnu/system.scm (define-module)[export]: Add boot-parameters-locale.
> (<boot-parameters>)[locale]: New field.
> [boot-parameters-locale]: New accessor.
> (read-boot-parameters): Read locale field.
> (operating-system-boot-parameters): Provide operating-system locale to
> oboot-parameters record.
> (operating-system-boot-parameters-file): Likewise.
> (operating-system-bootcfg): Provide locale information to the bootloader.
> * guix/system/script.scm (reinstall-bootloader): Likewise.

This (and v3) LGTM!  We’ll have to do another round of testing before
1.2.

¡Gracias!

Ludo’.




^ permalink raw reply	[flat|nested] 20+ messages in thread

* [bug#35394] [PATCH 4/4 v4] Grub i18n
  2020-10-17 16:32   ` Ludovic Courtès
@ 2020-10-18 15:09     ` Miguel Ángel Arruga Vivas
  2020-10-18 15:43       ` Miguel Ángel Arruga Vivas
  0 siblings, 1 reply; 20+ messages in thread
From: Miguel Ángel Arruga Vivas @ 2020-10-18 15:09 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 35394

[-- Attachment #1: Type: text/plain, Size: 1311 bytes --]

Hi Ludo,

Ludovic Courtès <ludo@gnu.org> writes:
> Sounds good.  I think the way you split patches in v3 was fine too (the
> added test was also a nice bonus), so I actually have a slight
> preference for v3.
> (...)
> This (and v3) LGTM!  We’ll have to do another round of testing before
> 1.2.

I plan to push them today.  The code is the same as v4 (as it contained
the code for roll-back in ssh.scm) plus the test from v3, with only
cosmetic changes to avoid touching other lines and an update for
multiboot-modules in the test.  Thank you very much for your review.

Nonetheless, I have a nice last minute addition for this to keep this
open for a bit more. :-)

It brings the whole glibc-locales to the grub and extlinux configuration
builders, and changes again boot-parameters.  It would be optimal to
create a minimal locale with the desired locale, as glibc-utf8-locales
doesn't work with my to-go test target (es_ES.utf8) because setlocale
raises an exception.

I have in my TODO list to extract translate-label somewhere else, even
though I'm not sure where could it fit, and to sanitize some inputs to
ensure the correct generation.  The latter should be ready this week,
the first depends on finding (or creating) the right place.

WDYT?

Happy hacking!
Miguel

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-system-nls-for-boot-labels.patch --]
[-- Type: text/x-patch, Size: 13365 bytes --]

From e21128a7ed6557198ee74706921a0a24bbbc7b65 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
 <rosen644835@gmail.com>
Date: Sat, 17 Oct 2020 21:27:51 +0200
Subject: [PATCH] system: nls for boot labels.

* gnu/bootloader/extlinux.scm (extlinux-configuration-file): Add
keyword locale.
[translate-label]: New function that formats the label after
translation.
[menu-entry->gexp]: Use translate-label.
[init-gettext]: Init gettext with the language provided through the
configuration.
[builder]: Use init-gettext, define G_ and translate strings.
* gnu/bootloader/grub.scm (eye-candy): Translate string.
(grub-configuration-file)[translate-label]: New function.
[menu-entry->gexp]: Use translate-label.
[init-gettext]: New g-exp variable.
[locale-config]: Translate string.
[builder]: Use init-gettext, define G_ and translate strings.
* gnu/system.scm (kernel->boot-label): Modify return type, and
document it, to allow correct translation of the labels.
* po/guix/POTFILES.in: Add gnu/bootloader/grub.scm.
* tests/boot-parameters.scm (%default-label): Update to the new
format.
(%old-label): Renamed from old %default-label.
(read old format): New test case.
---
 gnu/bootloader/extlinux.scm | 48 +++++++++++++++++++++++---
 gnu/bootloader/grub.scm     | 68 ++++++++++++++++++++++++++++++++-----
 gnu/system.scm              | 21 ++++++------
 po/guix/POTFILES.in         |  2 ++
 tests/boot-parameters.scm   |  6 +++-
 5 files changed, 119 insertions(+), 26 deletions(-)

diff --git a/gnu/bootloader/extlinux.scm b/gnu/bootloader/extlinux.scm
index 6b5ff298e7..40e02319f0 100644
--- a/gnu/bootloader/extlinux.scm
+++ b/gnu/bootloader/extlinux.scm
@@ -27,6 +27,7 @@
 
 (define* (extlinux-configuration-file config entries
                                       #:key
+                                      (locale #f)
                                       (system (%current-system))
                                       (old-entries '())
                                       #:allow-other-keys)
@@ -38,8 +39,38 @@ corresponding to old generations of the system."
   (define all-entries
     (append entries (bootloader-configuration-menu-entries config)))
 
+  (define (translate-label label)
+    (match label
+      (('hurd name version)
+       ;; TRANSLATORS: The first parameter is the capitalized package name
+       ;; for the Hurd kernel, which uses the definite article in English.
+       ;; The second parameter contains the version string.
+       #~(format #f (G_ "GNU with the ~a ~a") package version))
+      (('linux name version)
+       ;; TRANSLATORS: The first parameter is the capitalized package name
+       ;; for Linux kernel, which doesn't use the definite article in
+       ;; English.  The second parameter contains the version string.
+       #~(format #f (G_ "GNU with ~a ~a") package version))
+      (('unknown)
+       ;; TRANSLATORS: This is the label for an unknown system to be booted.
+       #~(G_ "GNU"))
+      ((? string? old-format)
+       ;; We cannot translate properly the old format.
+       #~old-format)))
+
+  (define init-gettext
+    #~(let ((locale #$(and locale
+                           (locale-definition-name
+                            (locale-name->definition locale)))))
+        (when locale
+          (setenv "GUIX_LOCPATH" (string-append #$glibc-locales
+                                                "/lib/locale/"))
+          (bindtextdomain "guix" (string-append #$guix "/share/locale"))
+          (textdomain "guix")
+          (setlocale LC_ALL locale))))
+
   (define (menu-entry->gexp entry)
-    (let ((label (menu-entry-label entry))
+    (let ((label (translate-label (menu-entry-label entry)))
           (kernel (menu-entry-linux entry))
           (kernel-arguments (menu-entry-linux-arguments entry))
           (initrd (menu-entry-initrd entry)))
@@ -57,13 +88,20 @@ corresponding to old generations of the system."
   (define builder
     #~(call-with-output-file #$output
         (lambda (port)
+          #$init-gettext
+          ;; Ensure xgettext extracts translatable messages
+          ;; with our current keywords.
+          (define G_ gettext)
           (let ((timeout #$(bootloader-configuration-timeout config)))
-            (format port "# This file was generated from your Guix configuration.  Any changes
-# will be lost upon reconfiguration.
-UI menu.c32
-MENU TITLE GNU Guix Boot Options
+            (format port "~aUI menu.c32
+MENU TITLE ~a
 PROMPT ~a
 TIMEOUT ~a~%"
+                    (G_ "\
+# This file was generated from your Guix configuration.  Any changes
+# will be lost upon reconfiguration.
+") ;; Keep line break to not duplicate grub.scm message.
+                    (G_ "GNU Guix Boot Options")
                     (if (> timeout 0) 1 0)
                     ;; timeout is expressed in 1/10s of seconds.
                     (* 10 timeout))
diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm
index 611580a350..d05abf9bc9 100644
--- a/gnu/bootloader/grub.scm
+++ b/gnu/bootloader/grub.scm
@@ -35,8 +35,10 @@
   #:use-module (gnu system file-systems)
   #:use-module (gnu system keyboard)
   #:use-module (gnu system locale)
+  #:use-module (gnu packages base)
   #:use-module (gnu packages bootloaders)
   #:autoload   (gnu packages gtk) (guile-cairo guile-rsvg)
+  #:use-module (gnu packages package-management)
   #:autoload   (gnu packages xorg) (xkeyboard-config)
   #:use-module (ice-9 match)
   #:use-module (ice-9 regex)
@@ -182,7 +184,7 @@ fi~%"
 
   (and image
        #~(format #$port "
-# Set 'root' to the partition that contains /gnu/store.
+# ~a
 ~a
 
 ~a
@@ -196,6 +198,8 @@ else
   set menu_color_normal=cyan/blue
   set menu_color_highlight=white/blue
 fi~%"
+                 (G_
+		  "Set 'root' to the partition that contains /gnu/store.")
                  #$(grub-root-search store-device font-file)
                  #$(setup-gfxterm config font-file)
                  #$(grub-setup-io config)
@@ -348,8 +352,28 @@ STORE-DIRECTORY-PREFIX may be used to specify a store prefix, as is required
 when booting a root file system on a Btrfs subvolume."
   (define all-entries
     (append entries (bootloader-configuration-menu-entries config)))
+
+  (define (translate-label label)
+    (match label
+      (('hurd name version)
+       ;; TRANSLATORS: The first parameter is the capitalized package name
+       ;; for the Hurd kernel, which uses the definite article in English.
+       ;; The second parameter contains the version string.
+       #~(format #f (G_ "GNU with the ~a ~a") package version))
+      (('linux name version)
+       ;; TRANSLATORS: The first parameter is the capitalized package name
+       ;; for Linux kernel, which doesn't use the definite article in
+       ;; English.  The second parameter contains the version string.
+       #~(format #f (G_ "GNU with ~a ~a") package version))
+      (('unknown)
+       ;; TRANSLATORS: This is the label for an unknown system to be booted.
+       #~(G_ "GNU"))
+      ((? string? old-format)
+       ;; We cannot translate properly the old format.
+       #~old-format)))
+
   (define (menu-entry->gexp entry)
-    (let ((label (menu-entry-label entry))
+    (let ((label (translate-label (menu-entry-label entry)))
           (linux (menu-entry-linux entry))
           (device (menu-entry-device entry))
           (device-mount-point (menu-entry-device-mount-point entry)))
@@ -401,19 +425,36 @@ menuentry ~s {
                  #:store-directory-prefix store-directory-prefix
                  #:port #~port)))
 
+  (define init-gettext
+    #~(let ((locale #$(and locale
+                           (locale-definition-name
+                            (locale-name->definition locale)))))
+        (when locale
+          (setenv "GUIX_LOCPATH" (string-append #$glibc-locales
+                                                "/lib/locale/"))
+          (bindtextdomain "guix" (string-append #$guix "/share/locale"))
+          (textdomain "guix")
+          (setlocale LC_ALL locale))))
+
   (define locale-config
     #~(let ((locale #$(and locale
                            (locale-definition-source
                             (locale-name->definition locale)))))
         (when locale
           (format port "\
-# Localization configuration.
+# ~a
 if search --file --set boot_partition /grub/grub.cfg; then
     set locale_dir=(${boot_partition})/grub/locale
 else
     set locale_dir=/boot/grub/locale
 fi
-set lang=~a~%" locale))))
+set lang=~a~%"
+                  ;; XXX: This should sanitized with a function that
+                  ;; inserts # at the beginning of each line.
+                  ;; TRANSLATORS: This must be one line or start each line
+                  ;; with #.
+                  (G_ "Localization configuration.")
+                  locale))))
 
   (define keyboard-layout-config
     (let* ((layout (bootloader-configuration-keyboard-layout config))
@@ -434,10 +475,17 @@ keymap ~a~%" #$keymap))))
   (define builder
     #~(call-with-output-file #$output
         (lambda (port)
+          #$init-gettext
+          ;; Ensure xgettext extracts translatable messages
+          ;; with our current keywords.
+          (define G_ gettext)
           (format port
-                  "# This file was generated from your Guix configuration.  Any changes
+                  ;; XXX: This should sanitized with a function to
+                  ;; ensure the # at the beginning of each line.
+                  (G_ "\
+# This file was generated from your Guix configuration.  Any changes
 # will be lost upon reconfiguration.
-")
+"))
           #$(sugar)
           #$locale-config
           #$keyboard-layout-config
@@ -450,16 +498,18 @@ set timeout=~a~%"
 
           #$@(if (pair? old-entries)
                  #~((format port "
-submenu \"GNU system, old configurations...\" {~%")
+submenu \"~a\" {~%"
+                            (G_ "GNU system, old configurations..."))
                     #$@(map menu-entry->gexp old-entries)
                     (format port "}~%"))
                  #~())
           (format port "
 if [ \"${grub_platform}\" == efi ]; then
-  menuentry \"Firmware setup\" {
+  menuentry \"~a\" {
     fwsetup
   }
-fi~%"))))
+fi~%"
+                  (G_ "Firmware setup")))))
 
   ;; Since this file is rather unique, there's no point in trying to
   ;; substitute it.
diff --git a/gnu/system.scm b/gnu/system.scm
index a3122eaa65..1257aa6223 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -1194,20 +1194,19 @@ listed in OS.  The C library expects to find it under
                     #:libcs (operating-system-locale-libcs os)))
 
 (define* (kernel->boot-label kernel #:key hurd)
-  "Return a label for the bootloader menu entry that boots KERNEL."
+  "Return a label for the bootloader menu entry that boots KERNEL.
+Label is a list that contains the kernel identifier, @code{'hurd} or
+@code{'linux}, its title name and the version, or @code{'unknown}."
   (cond ((package? hurd)
-         (string-append "GNU with the "
-                        (string-titlecase (package-name hurd)) " "
-                        (package-version hurd)))
+         (list 'hurd (string-titlecase (package-name hurd))
+               (package-version hurd)))
         ((package? kernel)
-         (string-append "GNU with "
-                        (string-titlecase (package-name kernel)) " "
-                        (package-version kernel)))
+         (list 'linux (string-titlecase (package-name kernel))
+               (package-version kernel)))
         ((inferior-package? kernel)
-         (string-append "GNU with "
-                        (string-titlecase (inferior-package-name kernel)) " "
-                        (inferior-package-version kernel)))
-        (else "GNU")))
+         (list 'linux (string-titlecase (inferior-package-name kernel))
+               (inferior-package-version kernel)))
+        (else '(unknown))))
 
 (define (operating-system-default-label os)
   "Return the default label for OS, as it will appear in the bootloader menu
diff --git a/po/guix/POTFILES.in b/po/guix/POTFILES.in
index b877fac9df..4386c8763d 100644
--- a/po/guix/POTFILES.in
+++ b/po/guix/POTFILES.in
@@ -40,6 +40,8 @@ gnu/installer/user.scm
 gnu/installer/utils.scm
 gnu/machine/ssh.scm
 gnu/packages/bootstrap.scm
+gnu/bootloader/grub.scm
+gnu/bootloader/extlinux.scm
 guix/build/utils.scm
 guix/scripts.scm
 guix/scripts/build.scm
diff --git a/tests/boot-parameters.scm b/tests/boot-parameters.scm
index d7e579bc89..678de1475f 100644
--- a/tests/boot-parameters.scm
+++ b/tests/boot-parameters.scm
@@ -34,7 +34,8 @@
   #:use-module (srfi srfi-64)
   #:use-module (rnrs bytevectors))
 
-(define %default-label "GNU with Linux-libre 99.1.2")
+(define %old-label "GNU with Linux-libre 99.1.2")
+(define %default-label '(linux "Linux-libre" "99.1.2"))
 (define %default-kernel-path
   (string-append (%store-prefix)
                  "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-linux-libre-99.1.2"))
@@ -156,6 +157,9 @@
                                   #:with-store #false
                                   #:locale #false)))
 
+(test-assert "read, read old format"
+  (test-read-boot-parameters #:label %old-label))
+
 (test-equal "read, default equality"
   %grub-boot-parameters
   (test-read-boot-parameters))
-- 
2.28.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [bug#35394] [PATCH 4/4 v4] Grub i18n
  2020-10-18 15:09     ` [bug#35394] [PATCH 4/4 " Miguel Ángel Arruga Vivas
@ 2020-10-18 15:43       ` Miguel Ángel Arruga Vivas
  2020-10-19  8:50         ` Ludovic Courtès
  0 siblings, 1 reply; 20+ messages in thread
From: Miguel Ángel Arruga Vivas @ 2020-10-18 15:43 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 35394

[-- Attachment #1: Type: text/plain, Size: 908 bytes --]

Sorry, please disregard the last patch, it was a non-working version.  I
tested this one with Grub and the boot-parameters test (for the label
modification).

I leave the open points for reference.

Miguel Ángel Arruga Vivas <rosen644835@gmail.com> writes:
> (...)
> It brings the whole glibc-locales to the grub and extlinux configuration
> builders, and changes again boot-parameters.  It would be optimal to
> create a minimal locale with the desired locale, as glibc-utf8-locales
> doesn't work with my to-go test target (es_ES.utf8) because setlocale
> raises an exception.
>
> I have in my TODO list to extract translate-label somewhere else, even
> though I'm not sure where could it fit, and to sanitize some inputs to
> ensure the correct generation.  The latter should be ready this week,
> the first depends on finding (or creating) the right place.

Happy hacking!
Miguel


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-system-nls-for-boot-labels.patch --]
[-- Type: text/x-patch, Size: 13766 bytes --]

From e9f3c255c13abc14e1f0decf5460b7a2f9a2d162 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
 <rosen644835@gmail.com>
Date: Sat, 17 Oct 2020 21:27:51 +0200
Subject: [PATCH] system: nls for boot labels.

* gnu/bootloader/extlinux.scm (extlinux-configuration-file): Add
keyword locale.
[translate-label]: New function that formats the label after
translation.
[menu-entry->gexp]: Use translate-label.
[init-gettext]: Init gettext with the language provided through the
configuration.
[builder]: Use init-gettext, define G_ and translate strings.
* gnu/bootloader/grub.scm (eye-candy): Translate string.
(grub-configuration-file)[translate-label]: New function.
[menu-entry->gexp]: Use translate-label.
[init-gettext]: New g-exp variable.
[locale-config]: Translate string.
[builder]: Use init-gettext, define G_ and translate strings.
* gnu/system.scm (kernel->boot-label): Modify return type, and
document it, to allow correct translation of the labels.
* po/guix/POTFILES.in: Add gnu/bootloader/grub.scm.
* tests/boot-parameters.scm (%default-label): Update to the new
format.
(%old-label): Renamed from old %default-label.
(read old format): New test case.
---
 gnu/bootloader/extlinux.scm | 52 +++++++++++++++++++++++++---
 gnu/bootloader/grub.scm     | 68 ++++++++++++++++++++++++++++++++-----
 gnu/system.scm              | 21 ++++++------
 po/guix/POTFILES.in         |  2 ++
 tests/boot-parameters.scm   |  6 +++-
 5 files changed, 123 insertions(+), 26 deletions(-)

diff --git a/gnu/bootloader/extlinux.scm b/gnu/bootloader/extlinux.scm
index 6b5ff298e7..36d0bcdae4 100644
--- a/gnu/bootloader/extlinux.scm
+++ b/gnu/bootloader/extlinux.scm
@@ -19,14 +19,19 @@
 
 (define-module (gnu bootloader extlinux)
   #:use-module (gnu bootloader)
+  #:use-module (gnu packages base)
   #:use-module (gnu packages bootloaders)
+  #:use-module (gnu packages package-management)
+  #:use-module (gnu system locale)
   #:use-module (guix gexp)
   #:use-module (guix utils)
+  #:use-module (ice-9 match)
   #:export (extlinux-bootloader
             extlinux-bootloader-gpt))
 
 (define* (extlinux-configuration-file config entries
                                       #:key
+                                      (locale #f)
                                       (system (%current-system))
                                       (old-entries '())
                                       #:allow-other-keys)
@@ -38,8 +43,38 @@ corresponding to old generations of the system."
   (define all-entries
     (append entries (bootloader-configuration-menu-entries config)))
 
+  (define (translate-label label)
+    (match label
+      (('hurd name version)
+       ;; TRANSLATORS: The first parameter is the capitalized package name
+       ;; for the Hurd kernel, which uses the definite article in English.
+       ;; The second parameter contains the version string.
+       #~(format #f (G_ "GNU with the ~a ~a") package version))
+      (('linux name version)
+       ;; TRANSLATORS: The first parameter is the capitalized package name
+       ;; for Linux kernel, which doesn't use the definite article in
+       ;; English.  The second parameter contains the version string.
+       #~(format #f (G_ "GNU with ~a ~a") package version))
+      (('unknown)
+       ;; TRANSLATORS: This is the label for an unknown system to be booted.
+       #~(G_ "GNU"))
+      ((? string? old-format)
+       ;; We cannot translate properly the old format.
+       old-format)))
+
+  (define init-gettext
+    #~(let ((locale #$(and locale
+                           (locale-definition-name
+                            (locale-name->definition locale)))))
+        (when locale
+          (setenv "GUIX_LOCPATH" (string-append #$glibc-locales
+                                                "/lib/locale/"))
+          (bindtextdomain "guix" (string-append #$guix "/share/locale"))
+          (textdomain "guix")
+          (setlocale LC_ALL locale))))
+
   (define (menu-entry->gexp entry)
-    (let ((label (menu-entry-label entry))
+    (let ((label (translate-label (menu-entry-label entry)))
           (kernel (menu-entry-linux entry))
           (kernel-arguments (menu-entry-linux-arguments entry))
           (initrd (menu-entry-initrd entry)))
@@ -57,13 +92,20 @@ corresponding to old generations of the system."
   (define builder
     #~(call-with-output-file #$output
         (lambda (port)
+          #$init-gettext
+          ;; Ensure xgettext extracts translatable messages
+          ;; with our current keywords.
+          (define G_ gettext)
           (let ((timeout #$(bootloader-configuration-timeout config)))
-            (format port "# This file was generated from your Guix configuration.  Any changes
-# will be lost upon reconfiguration.
-UI menu.c32
-MENU TITLE GNU Guix Boot Options
+            (format port "~aUI menu.c32
+MENU TITLE ~a
 PROMPT ~a
 TIMEOUT ~a~%"
+                    (G_ "\
+# This file was generated from your Guix configuration.  Any changes
+# will be lost upon reconfiguration.
+") ;; Keep line break to not duplicate grub.scm message.
+                    (G_ "GNU Guix Boot Options")
                     (if (> timeout 0) 1 0)
                     ;; timeout is expressed in 1/10s of seconds.
                     (* 10 timeout))
diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm
index 611580a350..e4df9b5009 100644
--- a/gnu/bootloader/grub.scm
+++ b/gnu/bootloader/grub.scm
@@ -35,8 +35,10 @@
   #:use-module (gnu system file-systems)
   #:use-module (gnu system keyboard)
   #:use-module (gnu system locale)
+  #:use-module (gnu packages base)
   #:use-module (gnu packages bootloaders)
   #:autoload   (gnu packages gtk) (guile-cairo guile-rsvg)
+  #:use-module (gnu packages package-management)
   #:autoload   (gnu packages xorg) (xkeyboard-config)
   #:use-module (ice-9 match)
   #:use-module (ice-9 regex)
@@ -182,7 +184,7 @@ fi~%"
 
   (and image
        #~(format #$port "
-# Set 'root' to the partition that contains /gnu/store.
+# ~a
 ~a
 
 ~a
@@ -196,6 +198,8 @@ else
   set menu_color_normal=cyan/blue
   set menu_color_highlight=white/blue
 fi~%"
+                 (G_
+		  "Set 'root' to the partition that contains /gnu/store.")
                  #$(grub-root-search store-device font-file)
                  #$(setup-gfxterm config font-file)
                  #$(grub-setup-io config)
@@ -348,8 +352,28 @@ STORE-DIRECTORY-PREFIX may be used to specify a store prefix, as is required
 when booting a root file system on a Btrfs subvolume."
   (define all-entries
     (append entries (bootloader-configuration-menu-entries config)))
+
+  (define (translate-label label)
+    (match label
+      (('hurd name version)
+       ;; TRANSLATORS: The first parameter is the capitalized package name
+       ;; for the Hurd kernel, which uses the definite article in English.
+       ;; The second parameter contains the version string.
+       #~(format #f (G_ "GNU with the ~a ~a") package version))
+      (('linux name version)
+       ;; TRANSLATORS: The first parameter is the capitalized package name
+       ;; for Linux kernel, which doesn't use the definite article in
+       ;; English.  The second parameter contains the version string.
+       #~(format #f (G_ "GNU with ~a ~a") package version))
+      (('unknown)
+       ;; TRANSLATORS: This is the label for an unknown system to be booted.
+       #~(G_ "GNU"))
+      ((? string? old-format)
+       ;; We cannot translate properly the old format.
+       old-format)))
+
   (define (menu-entry->gexp entry)
-    (let ((label (menu-entry-label entry))
+    (let ((label (translate-label (menu-entry-label entry)))
           (linux (menu-entry-linux entry))
           (device (menu-entry-device entry))
           (device-mount-point (menu-entry-device-mount-point entry)))
@@ -401,19 +425,36 @@ menuentry ~s {
                  #:store-directory-prefix store-directory-prefix
                  #:port #~port)))
 
+  (define init-gettext
+    #~(let ((locale #$(and locale
+                           (locale-definition-name
+                            (locale-name->definition locale)))))
+        (when locale
+          (setenv "GUIX_LOCPATH" (string-append #$glibc-locales
+                                                "/lib/locale/"))
+          (bindtextdomain "guix" (string-append #$guix "/share/locale"))
+          (textdomain "guix")
+          (setlocale LC_ALL locale))))
+
   (define locale-config
     #~(let ((locale #$(and locale
                            (locale-definition-source
                             (locale-name->definition locale)))))
         (when locale
           (format port "\
-# Localization configuration.
+# ~a
 if search --file --set boot_partition /grub/grub.cfg; then
     set locale_dir=(${boot_partition})/grub/locale
 else
     set locale_dir=/boot/grub/locale
 fi
-set lang=~a~%" locale))))
+set lang=~a~%"
+                  ;; XXX: This should sanitized with a function that
+                  ;; inserts # at the beginning of each line.
+                  ;; TRANSLATORS: This must be one line or start each line
+                  ;; with #.
+                  (G_ "Localization configuration.")
+                  locale))))
 
   (define keyboard-layout-config
     (let* ((layout (bootloader-configuration-keyboard-layout config))
@@ -434,10 +475,17 @@ keymap ~a~%" #$keymap))))
   (define builder
     #~(call-with-output-file #$output
         (lambda (port)
+          #$init-gettext
+          ;; Ensure xgettext extracts translatable messages
+          ;; with our current keywords.
+          (define G_ gettext)
           (format port
-                  "# This file was generated from your Guix configuration.  Any changes
+                  ;; XXX: This should sanitized with a function to
+                  ;; ensure the # at the beginning of each line.
+                  (G_ "\
+# This file was generated from your Guix configuration.  Any changes
 # will be lost upon reconfiguration.
-")
+"))
           #$(sugar)
           #$locale-config
           #$keyboard-layout-config
@@ -450,16 +498,18 @@ set timeout=~a~%"
 
           #$@(if (pair? old-entries)
                  #~((format port "
-submenu \"GNU system, old configurations...\" {~%")
+submenu \"~a\" {~%"
+                            (G_ "GNU system, old configurations..."))
                     #$@(map menu-entry->gexp old-entries)
                     (format port "}~%"))
                  #~())
           (format port "
 if [ \"${grub_platform}\" == efi ]; then
-  menuentry \"Firmware setup\" {
+  menuentry \"~a\" {
     fwsetup
   }
-fi~%"))))
+fi~%"
+                  (G_ "Firmware setup")))))
 
   ;; Since this file is rather unique, there's no point in trying to
   ;; substitute it.
diff --git a/gnu/system.scm b/gnu/system.scm
index a3122eaa65..1257aa6223 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -1194,20 +1194,19 @@ listed in OS.  The C library expects to find it under
                     #:libcs (operating-system-locale-libcs os)))
 
 (define* (kernel->boot-label kernel #:key hurd)
-  "Return a label for the bootloader menu entry that boots KERNEL."
+  "Return a label for the bootloader menu entry that boots KERNEL.
+Label is a list that contains the kernel identifier, @code{'hurd} or
+@code{'linux}, its title name and the version, or @code{'unknown}."
   (cond ((package? hurd)
-         (string-append "GNU with the "
-                        (string-titlecase (package-name hurd)) " "
-                        (package-version hurd)))
+         (list 'hurd (string-titlecase (package-name hurd))
+               (package-version hurd)))
         ((package? kernel)
-         (string-append "GNU with "
-                        (string-titlecase (package-name kernel)) " "
-                        (package-version kernel)))
+         (list 'linux (string-titlecase (package-name kernel))
+               (package-version kernel)))
         ((inferior-package? kernel)
-         (string-append "GNU with "
-                        (string-titlecase (inferior-package-name kernel)) " "
-                        (inferior-package-version kernel)))
-        (else "GNU")))
+         (list 'linux (string-titlecase (inferior-package-name kernel))
+               (inferior-package-version kernel)))
+        (else '(unknown))))
 
 (define (operating-system-default-label os)
   "Return the default label for OS, as it will appear in the bootloader menu
diff --git a/po/guix/POTFILES.in b/po/guix/POTFILES.in
index b877fac9df..4386c8763d 100644
--- a/po/guix/POTFILES.in
+++ b/po/guix/POTFILES.in
@@ -40,6 +40,8 @@ gnu/installer/user.scm
 gnu/installer/utils.scm
 gnu/machine/ssh.scm
 gnu/packages/bootstrap.scm
+gnu/bootloader/grub.scm
+gnu/bootloader/extlinux.scm
 guix/build/utils.scm
 guix/scripts.scm
 guix/scripts/build.scm
diff --git a/tests/boot-parameters.scm b/tests/boot-parameters.scm
index d7e579bc89..678de1475f 100644
--- a/tests/boot-parameters.scm
+++ b/tests/boot-parameters.scm
@@ -34,7 +34,8 @@
   #:use-module (srfi srfi-64)
   #:use-module (rnrs bytevectors))
 
-(define %default-label "GNU with Linux-libre 99.1.2")
+(define %old-label "GNU with Linux-libre 99.1.2")
+(define %default-label '(linux "Linux-libre" "99.1.2"))
 (define %default-kernel-path
   (string-append (%store-prefix)
                  "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-linux-libre-99.1.2"))
@@ -156,6 +157,9 @@
                                   #:with-store #false
                                   #:locale #false)))
 
+(test-assert "read, read old format"
+  (test-read-boot-parameters #:label %old-label))
+
 (test-equal "read, default equality"
   %grub-boot-parameters
   (test-read-boot-parameters))
-- 
2.28.0


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [bug#35394] [PATCH 4/4 v4] Grub i18n
  2020-10-18 15:43       ` Miguel Ángel Arruga Vivas
@ 2020-10-19  8:50         ` Ludovic Courtès
  2020-10-19 11:41           ` Miguel Ángel Arruga Vivas
  0 siblings, 1 reply; 20+ messages in thread
From: Ludovic Courtès @ 2020-10-19  8:50 UTC (permalink / raw)
  To: Miguel Ángel Arruga Vivas; +Cc: 35394

Hi!

Miguel Ángel Arruga Vivas <rosen644835@gmail.com> skribis:

> From e9f3c255c13abc14e1f0decf5460b7a2f9a2d162 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
>  <rosen644835@gmail.com>
> Date: Sat, 17 Oct 2020 21:27:51 +0200
> Subject: [PATCH] system: nls for boot labels.
>
> * gnu/bootloader/extlinux.scm (extlinux-configuration-file): Add
> keyword locale.
> [translate-label]: New function that formats the label after
> translation.
> [menu-entry->gexp]: Use translate-label.
> [init-gettext]: Init gettext with the language provided through the
> configuration.
> [builder]: Use init-gettext, define G_ and translate strings.
> * gnu/bootloader/grub.scm (eye-candy): Translate string.
> (grub-configuration-file)[translate-label]: New function.
> [menu-entry->gexp]: Use translate-label.
> [init-gettext]: New g-exp variable.
> [locale-config]: Translate string.
> [builder]: Use init-gettext, define G_ and translate strings.
> * gnu/system.scm (kernel->boot-label): Modify return type, and
> document it, to allow correct translation of the labels.
> * po/guix/POTFILES.in: Add gnu/bootloader/grub.scm.
> * tests/boot-parameters.scm (%default-label): Update to the new
> format.
> (%old-label): Renamed from old %default-label.
> (read old format): New test case.

[...]

>  (define* (extlinux-configuration-file config entries
>                                        #:key
> +                                      (locale #f)
>                                        (system (%current-system))
>                                        (old-entries '())
>                                        #:allow-other-keys)
> @@ -38,8 +43,38 @@ corresponding to old generations of the system."
>    (define all-entries
>      (append entries (bootloader-configuration-menu-entries config)))
>  
> +  (define (translate-label label)
> +    (match label
> +      (('hurd name version)
> +       ;; TRANSLATORS: The first parameter is the capitalized package name
> +       ;; for the Hurd kernel, which uses the definite article in English.
> +       ;; The second parameter contains the version string.
> +       #~(format #f (G_ "GNU with the ~a ~a") package version))
> +      (('linux name version)
> +       ;; TRANSLATORS: The first parameter is the capitalized package name
> +       ;; for Linux kernel, which doesn't use the definite article in
> +       ;; English.  The second parameter contains the version string.
> +       #~(format #f (G_ "GNU with ~a ~a") package version))
> +      (('unknown)
> +       ;; TRANSLATORS: This is the label for an unknown system to be booted.
> +       #~(G_ "GNU"))
> +      ((? string? old-format)
> +       ;; We cannot translate properly the old format.
> +       old-format)))

It’s not good that we’re baking assumptions about the label here: the
user is free to choose the label they want in the ‘label’ field, and we
don’t want to replicate “GNU with the” etc. in each bootloader.

It’s also not great that we’re changing the boot parameters again as
this can make compatibility trickier down the road.

(Brainstorm…)

I would simply translate it on the client side by temporarily setting
LANGUAGE to the target locale.  The downside is that this will not be
translated if the target locale is not supported by the host.

Alternately, we could have:

  (define (formatted-i18n-string locale fmt . args)
    (computed-file "formatted-i18n-string"
                   #~(begin
                       (textdomain …)
                       (setlocale …)
                       (call-with-output-file #$output
                         (lambda (port)
                           (format port …))))))

We would then need to adjust all bootloaders to read the label from that
file.  If the user-supplied ‘label’ is a plain string, we’d wrap it in
(plain-file …) so that ‘label’ is always a file-like object.

WDYT?

Thanks,
Ludo’.




^ permalink raw reply	[flat|nested] 20+ messages in thread

* [bug#35394] [PATCH 4/4 v4] Grub i18n
  2020-10-19  8:50         ` Ludovic Courtès
@ 2020-10-19 11:41           ` Miguel Ángel Arruga Vivas
  2020-10-19 13:21             ` Ludovic Courtès
  0 siblings, 1 reply; 20+ messages in thread
From: Miguel Ángel Arruga Vivas @ 2020-10-19 11:41 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 35394

Hi Ludo,

Thanks for your review and your ideas, I'll comment inline.

Ludovic Courtès <ludo@gnu.org> writes:
>> +  (define (translate-label label)
>> +    (match label
>> +      (('hurd name version)
>> +       ;; TRANSLATORS: The first parameter is the capitalized package name
>> +       ;; for the Hurd kernel, which uses the definite article in English.
>> +       ;; The second parameter contains the version string.
>> +       #~(format #f (G_ "GNU with the ~a ~a") package version))
>> +      (('linux name version)
>> +       ;; TRANSLATORS: The first parameter is the capitalized package name
>> +       ;; for Linux kernel, which doesn't use the definite article in
>> +       ;; English.  The second parameter contains the version string.
>> +       #~(format #f (G_ "GNU with ~a ~a") package version))
>> +      (('unknown)
>> +       ;; TRANSLATORS: This is the label for an unknown system to be booted.
>> +       #~(G_ "GNU"))
>> +      ((? string? old-format)
>> +       ;; We cannot translate properly the old format.
>> +       old-format)))
>
> It’s not good that we’re baking assumptions about the label here: the
> user is free to choose the label they want in the ‘label’ field, and we
> don’t want to replicate “GNU with the” etc. in each bootloader.

I guess the main problem here was calling it 'old-format', as this is
the format that would be received for the labels provided by the user
too, I should have called it 'fixed-label' instead.  I didn't though of
this at first so that was the name, but the user provided label works as
always: the installation image was the first example I checked, as it
does exactly that---that startled me a bit until I noticed, by the way.

> It’s also not great that we’re changing the boot parameters again as
> this can make compatibility trickier down the road.

That was an important point of this design, and the reason why I created
the test in the first place: the tests try to cover all the
possibilities, the old format and the new one(s). :-)

> (Brainstorm…)
>
> I would simply translate it on the client side by temporarily setting
> LANGUAGE to the target locale.  The downside is that this will not be
> translated if the target locale is not supported by the host.
>
> Alternately, we could have:
>
>   (define (formatted-i18n-string locale fmt . args)
>     (computed-file "formatted-i18n-string"
>                    #~(begin
>                        (textdomain …)
>                        (setlocale …)
>                        (call-with-output-file #$output
>                          (lambda (port)
>                            (format port …))))))

I'd prefer this option, as it avoids triggering the translation on the
client side, and it could be used in other places too if needed.  It
needs xgettext support and a tag (like F_ or L_) would be very concise,
and useful from my point of view.  There are some other places
(e.g. gnu/machine/ssh.scm:395) which use string-append for user visible
strings[1].  They should be localized with a proper format, and
including the format call into the i18n call itself helps to ensure
that.

> We would then need to adjust all bootloaders to read the label from that
> file.  If the user-supplied ‘label’ is a plain string, we’d wrap it in
> (plain-file …) so that ‘label’ is always a file-like object.

I'll probably raise some questions about the design here and there, and
maybe open another thread for the point before, but as soon as I have
anything tangible, I'll send a patch. :-)

Happy hacking!
Miguel

[1] https://www.gnu.org/software/gettext/manual/gettext.html#No-string-concatenation




^ permalink raw reply	[flat|nested] 20+ messages in thread

* [bug#35394] [PATCH 4/4 v4] Grub i18n
  2020-10-19 11:41           ` Miguel Ángel Arruga Vivas
@ 2020-10-19 13:21             ` Ludovic Courtès
  2020-10-19 13:44               ` Miguel Ángel Arruga Vivas
  0 siblings, 1 reply; 20+ messages in thread
From: Ludovic Courtès @ 2020-10-19 13:21 UTC (permalink / raw)
  To: Miguel Ángel Arruga Vivas; +Cc: 35394

Hi,

Miguel Ángel Arruga Vivas <rosen644835@gmail.com> skribis:

>> (Brainstorm…)
>>
>> I would simply translate it on the client side by temporarily setting
>> LANGUAGE to the target locale.  The downside is that this will not be
>> translated if the target locale is not supported by the host.
>>
>> Alternately, we could have:
>>
>>   (define (formatted-i18n-string locale fmt . args)
>>     (computed-file "formatted-i18n-string"
>>                    #~(begin
>>                        (textdomain …)
>>                        (setlocale …)
>>                        (call-with-output-file #$output
>>                          (lambda (port)
>>                            (format port …))))))
>
> I'd prefer this option, as it avoids triggering the translation on the
> client side, and it could be used in other places too if needed.  It
> needs xgettext support and a tag (like F_ or L_) would be very concise,
> and useful from my point of view.

That’s OK, we can do (as we did in other places) something like:

  (define-syntax formatted-i18n-string
    (syntax-rules (G_ N_)
      ((_ locale (G_ fmt) args ...)
       (%formatted-i18n-string locale fmt args ...))
      …))

That way, xgettext is happy.

> There are some other places (e.g. gnu/machine/ssh.scm:395) which use
> string-append for user visible strings[1].  They should be localized
> with a proper format, and including the format call into the i18n call
> itself helps to ensure that.

Yup!

>> We would then need to adjust all bootloaders to read the label from that
>> file.  If the user-supplied ‘label’ is a plain string, we’d wrap it in
>> (plain-file …) so that ‘label’ is always a file-like object.
>
> I'll probably raise some questions about the design here and there, and
> maybe open another thread for the point before, but as soon as I have
> anything tangible, I'll send a patch. :-)

Sure!

We may end up delaying that post-release if there’s potential for
breakage.  We’ll see.

Thanks!

Ludo’.




^ permalink raw reply	[flat|nested] 20+ messages in thread

* [bug#35394] [PATCH 4/4 v4] Grub i18n
  2020-10-19 13:21             ` Ludovic Courtès
@ 2020-10-19 13:44               ` Miguel Ángel Arruga Vivas
  0 siblings, 0 replies; 20+ messages in thread
From: Miguel Ángel Arruga Vivas @ 2020-10-19 13:44 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 35394

[-- Attachment #1: Type: text/plain, Size: 571 bytes --]

Hi,

I take note about your comments, just one quick thing:

Ludovic Courtès <ludo@gnu.org> writes:
> We may end up delaying that post-release if there’s potential for
> breakage.  We’ll see.

With the release coming this week I wouldn't push anything more of this
into this release unless it's the most expected feature, which it isn't
by far.  I can test Grub and be really confident about not breaking
anything, but I don't almost any experience with the other bootloaders,
and neither lots of places nor time to test them.

Happy hacking!
Miguel

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 658 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2020-10-19 13:46 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-23 13:17 [bug#35394] [PATCH 0/3] Bootloader localization Miguel
2019-04-23 13:26 ` [bug#35394] [PATCH 1/3] system: Add locale to boot-parameters Miguel
2019-04-23 13:26 ` [bug#35394] [PATCH 2/3] system: Provide locale information to the bootloader Miguel
2019-04-23 13:26 ` [bug#35394] [PATCH 3/3] system: Use locale information in grub.cfg Miguel
2019-04-26 10:50 ` [bug#35394] [PATCH 3/4] gnu: grub: Add locale output for bootloading Miguel
2019-05-03 12:27   ` Miguel
2019-04-26 10:51 ` [bug#35394] [PATCH 4/4] system: Use locale information in grub.cfg Miguel
2019-05-03 12:27   ` Miguel
2019-04-29  7:56 ` [bug#35394] [PATCH 0/3] Bootloader localization Ludovic Courtès
     [not found]   ` <20191021124035.531bed75@gmail.com>
2019-10-21 10:46     ` [bug#35394] [PATCH 1/3] system: Add locale to boot-parameters Miguel Arruga Vivas
2019-10-21 10:46     ` [bug#35394] [PATCH 2/3] system: Provide locale information to the bootloader Miguel Arruga Vivas
2019-10-21 10:46     ` [bug#35394] [PATCH 3/3] system: Use locale information in grub.cfg Miguel Arruga Vivas
2020-10-11 14:18 ` [bug#35394] [PATCH 1/1 v4] Grub i18n Miguel Ángel Arruga Vivas
2020-10-17 16:32   ` Ludovic Courtès
2020-10-18 15:09     ` [bug#35394] [PATCH 4/4 " Miguel Ángel Arruga Vivas
2020-10-18 15:43       ` Miguel Ángel Arruga Vivas
2020-10-19  8:50         ` Ludovic Courtès
2020-10-19 11:41           ` Miguel Ángel Arruga Vivas
2020-10-19 13:21             ` Ludovic Courtès
2020-10-19 13:44               ` Miguel Ángel Arruga Vivas

unofficial mirror of guix-patches@gnu.org 

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/guix-patches/1 guix-patches/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 guix-patches guix-patches/ https://yhetil.org/guix-patches \
		guix-patches@gnu.org
	public-inbox-index guix-patches

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://news.yhetil.org/yhetil.gnu.guix.patches


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git