This v2 doesn't change the other patches, only this one, because it was
the one I wasn't happy with.  It changes from v1 as the separate output
"locale" is not generated, but instead the mo files are placed into
share/locale with the expected names.

>From c8aff861461b599095d55b9f694e074d433c72bb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
 <rosen644...@gmail.com>
Date: Sat, 24 Oct 2020 20:36:21 +0200
Subject: [PATCH 3/4] gnu: grub: Add locale output.

* gnu/bootloader/grub.scm (define-module): Use (guix packages).
(grub-configuration-file)[locale-config]: Use locale output from grub.
* gnu/packages/bootloaders.scm (grub)[outputs]: Define output "locale".
[arguments]: Populate "locale" output with new phase 'install-locale.
---
 gnu/bootloader/grub.scm      | 35 ++++++++++++++++++++++++-----------
 gnu/packages/bootloaders.scm | 16 +++++++++++++++-
 2 files changed, 39 insertions(+), 12 deletions(-)

diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm
index f1479024e6..7cce9e1da7 100644
--- a/gnu/bootloader/grub.scm
+++ b/gnu/bootloader/grub.scm
@@ -25,6 +25,7 @@
 
 (define-module (gnu bootloader grub)
   #:use-module (guix build union)
+  #:use-module (guix packages)
   #:use-module (guix records)
   #:use-module (guix store)
   #:use-module (guix utils)
@@ -402,18 +403,30 @@ menuentry ~s {
                  #:port #~port)))
 
   (define locale-config
-    #~(let ((locale #$(and locale
-                           (locale-definition-source
-                            (locale-name->definition locale)))))
-        (when locale
-          (format port "\
+    (let* ((entry (first all-entries))
+           (device (menu-entry-device entry))
+           (bootloader (bootloader-configuration-bootloader config))
+           (grub (bootloader-package bootloader))
+           (locale-dir (normalize-file (file-append grub "/share/locale")
+                                       (menu-entry-device-mount-point entry)
+                                       store-directory-prefix)))
+      #~(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))))
+~a
+set locale_dir=~a
+set lang=~a~%"
+                    #$(grub-root-search device
+                                        ;; We search an auto-generated file
+                                        ;; because the locale name might not
+                                        ;; match the .mo file name.
+                                        (file-append locale-dir
+                                                     "/e...@quot.mo"))
+                    #$locale-dir
+                    locale)))))
 
   (define keyboard-layout-config
     (let* ((layout (bootloader-configuration-keyboard-layout config))
diff --git a/gnu/packages/bootloaders.scm b/gnu/packages/bootloaders.scm
index 7034085d67..8057a6dd8a 100644
--- a/gnu/packages/bootloaders.scm
+++ b/gnu/packages/bootloaders.scm
@@ -148,7 +148,21 @@
                       (substitute* "Makefile.in"
                         (("test_unset grub_func_test")
                           "test_unset"))
-                      #t)))
+                      #t))
+                  (add-after 'install 'install-locale-for-boot
+                    ;; Install mo files with the expected names at boot-time.
+                    (lambda* (#:key outputs #:allow-other-keys)
+                      (let* ((out (assoc-ref outputs "out"))
+                             (locale (string-append out "/share/locale")))
+                        (for-each (lambda (file)
+                                    (let ((mo (string-append
+                                               (basename file ".gmo")
+                                               ".mo")))
+                                      (copy-file file
+                                                 (string-append locale
+                                                                "/" mo))))
+                                  (find-files "po" "\\.gmo$"))
+                        #t))))
        ;; Disable tests on ARM and AARCH64 platforms.
        #:tests? ,(not (any (cute string-prefix? <> (or (%current-target-system)
                                                        (%current-system)))
-- 
2.28.0

Reply via email to