Subject: [bug#35394] [PATCH 4/4 v4] Grub i18n

From: Ludovic Courtès <[email-masked]>
Date: Mon, 19 Oct 2020 10:50:13 +0200

Hi!

Miguel Ángel Arruga Vivas <[email-masked]> skribis:

> From e9f3c255c13abc14e1f0decf5460b7a2f9a2d162 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
>  <[email-masked]>
> 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’.