Package: initramfs-tools Version: 0.130 Severity: normal Tags: l10n patch Hello,
when trying to add l10n support to the cryptsetup initramfs script I was surprised to realize that apparently no initramfs component has l10n support yet. Probably that's because most messages from initramfs are more targeted at developers. Unfortunately, that's not true for the initramfs scripts of cryptsetup. Here, we need to ask users for input (passphrase) and therefore the messages we print are targeted at normal users. There's also an open bugreport that requests support for translated strings[1]. I first thought about adding all the required locale and gettext stuff to initramfs in the cryptroot hook, but after thinking about it again, I think it should be done in initramfs itself instead. Other initramfs components might want to use it as well. That's why I'd like to add locale and gettext support to initramfs but make it optional. Without any prompts targeted at endusers, there's no real need to bloat the initramfs with locales and gettext files. But e.g. in the cryptsetup package, we would enable it. I've prepared a patch that optionally adds locale and gettext support to initramfs (depending on a initramfs.conf variable). You can find the patch attached to this bugreport or as a merge request on Salsa[2]. Whatever you prefer ;) Would be awesome if you could consider to merge it. It's a prerequisite for adding l10n support to the cryptsetup initramfs scripts. Cheers, jonas [1] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=688735 [2] https://salsa.debian.org/kernel-team/initramfs-tools/merge_requests/4
>From c3a3e94a87946d0eb782b3147409ac37123febdf Mon Sep 17 00:00:00 2001 From: Jonas Meurer <jo...@freesources.org> Date: Sun, 17 Jun 2018 01:37:03 +0200 Subject: [PATCH] Add support for locales and gettext to initramfs --- conf/initramfs.conf | 8 ++++++++ hooks/locales | 47 +++++++++++++++++++++++++++++++++++++++++++++++ initramfs-tools.8 | 11 +++++++++++ initramfs.conf.5 | 5 +++++ mkinitramfs | 1 + scripts/functions | 16 ++++++++++++++++ 6 files changed, 88 insertions(+) create mode 100755 hooks/locales diff --git a/conf/initramfs.conf b/conf/initramfs.conf index 1319536..12a361c 100644 --- a/conf/initramfs.conf +++ b/conf/initramfs.conf @@ -38,6 +38,14 @@ BUSYBOX=auto KEYMAP=n # +# LOCALES: [ y | n ] +# +# Add locales and gettext to the initramfs. +# + +LOCALES=n + +# # COMPRESS: [ gzip | bzip2 | lzma | lzop | xz ] # diff --git a/hooks/locales b/hooks/locales new file mode 100755 index 0000000..8320f67 --- /dev/null +++ b/hooks/locales @@ -0,0 +1,47 @@ +#!/bin/sh + +PREREQ="" + +prereqs() +{ + echo "$PREREQ" +} + +case $1 in +# get pre-requisites +prereqs) + prereqs + exit 0 + ;; +esac + +# Hook to load locales and gettext into initramfs if requested by LOCALES=y +if [ "$LOCALES" != "y" ] && [ "$LOCALES" != "Y" ]; then + exit 0 +fi + +if [ ! -x /usr/bin/locale ]; then + echo "locale is missing. Please install the 'locales' package." + exit 0 +fi + +. /usr/share/initramfs-tools/hook-functions + +# Copy binaries required for gettext support +copy_exec /usr/bin/envsubst +copy_exec /usr/bin/gettext +copy_exec /usr/bin/gettext.sh +copy_exec /usr/bin/ngettext + +# Copy locale files except LC_COLLATE. It's not needed for localized string +# support and usually is by far the biggest locale file. +for file in $(find /usr/lib/locale -type f \! -name LC_COLLATE 2>/dev/null); do + copy_file locale_file $file +done + +# Write locale variables to initramfs conf.d +for line in $(locale); do + if [ "${line#LC_COLLATE}" = "$line" ]; then + echo "export $line" >>${DESTDIR}/conf/conf.d/locales + fi +done diff --git a/initramfs-tools.8 b/initramfs-tools.8 index 32cce2d..0481131 100644 --- a/initramfs-tools.8 +++ b/initramfs-tools.8 @@ -424,6 +424,17 @@ user to investigate the situation. panic "Frobnication failed" .RE +.TP +\fB\fI +gettext_support +Either loads /usr/bin/gettext.sh (if available) or provides dummy functions +eval_gettext() and eval_ngettext() functions otherwise. +.RS +.PP +.B Example: +gettext_support +.RE + .SS Subdirectories Both /usr/share/initramfs-tools/scripts and /etc/initramfs-tools/scripts contains the following subdirectories. diff --git a/initramfs.conf.5 b/initramfs.conf.5 index 569834c..4587e2f 100644 --- a/initramfs.conf.5 +++ b/initramfs.conf.5 @@ -57,6 +57,11 @@ that might need input will normally set this variable automatically, so there should normally be no need to set this. .TP +\fB LOCALES +If set to 'y', locales and gettext will be installed into the initramfs and +locale environment variables will be set. + +.TP \fB COMPRESS Specifies the compression method used for the initramfs image. .B mkinitramfs diff --git a/mkinitramfs b/mkinitramfs index 24715d5..ab9ede5 100755 --- a/mkinitramfs +++ b/mkinitramfs @@ -203,6 +203,7 @@ export DESTDIR export DPKG_ARCH export verbose export KEYMAP +export LOCALES export MODULES export BUSYBOX export RESUME diff --git a/scripts/functions b/scripts/functions index 0b7ca10..2cc3261 100644 --- a/scripts/functions +++ b/scripts/functions @@ -463,3 +463,19 @@ mount_bottom() { : } + +# Load /usr/bin/gettext.sh if available, provide dummy functions eval_gettext() +# and eval_ngettext() otherwise. +gettext_support() +{ + if [ -f "/usr/bin/gettext.sh" ]; then + . /usr/bin/gettext.sh + else + eval_gettext() { + echo "$1" + } + eval_ngettext() { + echo "$1" + } + fi +} -- 2.11.0