From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id EDkqNxNbjF/YTwAA0tVLHw (envelope-from ) for ; Sun, 18 Oct 2020 15:11:15 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id cPf2MhNbjF8zQQAAbx9fmQ (envelope-from ) for ; Sun, 18 Oct 2020 15:11:15 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 6BE6D9403A6 for ; Sun, 18 Oct 2020 15:11:15 +0000 (UTC) Received: from localhost ([::1]:54940 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kUAL4-00038X-Cj for larch@yhetil.org; Sun, 18 Oct 2020 11:11:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45542) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kUAKs-00034n-HU for guix-patches@gnu.org; Sun, 18 Oct 2020 11:11:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:55566) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kUAKs-00071f-7O for guix-patches@gnu.org; Sun, 18 Oct 2020 11:11:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kUAKs-0006br-2v for guix-patches@gnu.org; Sun, 18 Oct 2020 11:11:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#35394] [PATCH 4/4 v4] Grub i18n Resent-From: Miguel =?UTF-8?Q?=C3=81ngel?= Arruga Vivas Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 18 Oct 2020 15:11:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35394 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 35394@debbugs.gnu.org Received: via spool by 35394-submit@debbugs.gnu.org id=B35394.160303381025341 (code B ref 35394); Sun, 18 Oct 2020 15:11:02 +0000 Received: (at 35394) by debbugs.gnu.org; 18 Oct 2020 15:10:10 +0000 Received: from localhost ([127.0.0.1]:38879 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kUAK2-0006ae-1Q for submit@debbugs.gnu.org; Sun, 18 Oct 2020 11:10:10 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:36520) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kUAJz-0006a3-Om for 35394@debbugs.gnu.org; Sun, 18 Oct 2020 11:10:08 -0400 Received: by mail-wm1-f65.google.com with SMTP id e2so10224715wme.1 for <35394@debbugs.gnu.org>; Sun, 18 Oct 2020 08:10:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=w6fxZtXY72/hWK/l+KR9n/t4tp2Z7ZneMmOGgoILZfY=; b=iTUEARvaSwz73NSfkzb1su9XwwmM2o+048Wkk7rUei/NNoE/fpvQNDBMkgdjRMbkdq aEUn4yiUXEDkznNWprmi8pp3q8cb6GiM//aHtXMFImt1AA7Pb9x0JL4QwgZslXKW27p0 IBUII5UdtFTo5o+FS7qdA+XS11wUtIwR3W+YueXRw/ehnbQb1EyURhIpcDKnaCJP/K1F Do0M0XPrVQe92pHM9gqcwWbZUmCZ/QzSwld+XVKgXmtATevYrtFjEiXPDlzoHSooj3oI jFAO+66O09Xn3XXpR8JyvIMKYWwro3SA/PTMjf5xX7kunNbRO4eRuB8aDWWT6LFDd/sH aNCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=w6fxZtXY72/hWK/l+KR9n/t4tp2Z7ZneMmOGgoILZfY=; b=Ey+dyT4Crk2yuBhvr3v1EtUCYgMcn8Qw3xBXrDWeKFGehTOw9WopUO0l+VaBEXdcI9 VJqTAVYAMuI4/PCp+3lL/gtPFavOt4GbgQAwfXTCB6dqWzKa1oGfCvbpco4ujn5rgju8 3hJUCwYqM7ruUTCpQZ6Xt9OjL3FlC3J/84xaU0ohbExLPdi0iLhY+XB9SJ9f2hcCPlWR RQ38VwkeSHVnxhbWfvtApuvoZR+tpazlQ7HCywmCJcBPu2cbbWbpY8JzeDRv6dY4R7Sh B+p/LLAAUhDWBTNJxRUT14UDhCUQx0IV+TH1zSwEkhcs96AiqW+JIjJa01r8tf9Spr9Y e7mw== X-Gm-Message-State: AOAM532VJl324jJLcuNjf7d0lSkriTqUWwR4UBAFbyjm7FsJd/evVQbF bS5ggDwrhK4qxAePnCmrD65Tq8nmKdhyYA== X-Google-Smtp-Source: ABdhPJyyuUqKYe3NIsmec6GZBlUC7+smTn1F6lcAL+nuq8P2xoKpMtIIFtNkCe8GWg1xONSI19Mt5A== X-Received: by 2002:a05:600c:2256:: with SMTP id a22mr13532655wmm.138.1603033801553; Sun, 18 Oct 2020 08:10:01 -0700 (PDT) Received: from unfall (218.139.134.37.dynamic.jazztel.es. [37.134.139.218]) by smtp.gmail.com with ESMTPSA id a3sm14284098wrh.94.2020.10.18.08.10.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Oct 2020 08:10:00 -0700 (PDT) From: Miguel =?UTF-8?Q?=C3=81ngel?= Arruga Vivas References: <20190423151702.05258473@gmail.com> <87ft6k7sn2.fsf@gmail.com> <87362c6cew.fsf@gnu.org> Date: Sun, 18 Oct 2020 17:09:02 +0200 In-Reply-To: <87362c6cew.fsf@gnu.org> ("Ludovic =?UTF-8?Q?Court=C3=A8s?="'s message of "Sat, 17 Oct 2020 18:32:39 +0200") Message-ID: <87v9f7po4x.fsf_-_@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: 0.2 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -0.8 (/) X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=fail (rsa verify failed) header.d=gmail.com header.s=20161025 header.b=iTUEARva; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Spam-Score: 0.09 X-TUID: 0sfVXjuXwxTQ --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Ludo, Ludovic Court=C3=A8s 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=E2=80=99ll have to do another round of testing be= fore > 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 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-system-nls-for-boot-labels.patch Content-Description: 0001-system-nls-for-boot-labels.patch >From e21128a7ed6557198ee74706921a0a24bbbc7b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?= 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 --=-=-=--