summaryrefslogtreecommitdiffstats
path: root/perl-install/common.pm
diff options
context:
space:
mode:
authorMartin Whitaker <mageia@martin-whitaker.me.uk>2025-11-02 12:50:05 +0000
committerMartin Whitaker <mageia@martin-whitaker.me.uk>2025-11-02 18:20:25 +0000
commitb518f9f16b0fc09802d238eef91de41ed54de282 (patch)
tree767b002668bf26c851b8bfee986bef75eee0ad62 /perl-install/common.pm
parent46d9cd2601cdf11081c4f83fa0be21b3dbc060f2 (diff)
downloaddrakx-b518f9f16b0fc09802d238eef91de41ed54de282.tar
drakx-b518f9f16b0fc09802d238eef91de41ed54de282.tar.gz
drakx-b518f9f16b0fc09802d238eef91de41ed54de282.tar.bz2
drakx-b518f9f16b0fc09802d238eef91de41ed54de282.tar.xz
drakx-b518f9f16b0fc09802d238eef91de41ed54de282.zip
Use POSIX::setlocale() instead of c::setlocale().HEADmaster
Since Perl 5.28, Perl has used the thread-safe uselocale() functions from the C standard library when setting the locale. Once a thread-safe locale setting has been made, the Locale::gettext functions will use those settings, not the global locale settings. So calling the drakx c::setlocale() and c::init_setlocale() functions, which still use the underlying setlocale() function from the C standard library normally has no effect. However, prior to Perl 5.38, there was a bug in Perl that could cause the main thread to revert to using the global locale settings, and it it would seem this bug was being triggered by the stage2 installer, meaning it still properly translated the UI after the language selection step. Now we have a newer version of Perl, this is no longer so, and the UI contiues to be in English after the user has selected a different language (mga#34656). The POSIX::setlocale() function affects the thread-safe locale, so can be used to fix this bug. This patch removes the c::setlocale() function to prevent reintroduction of this bug, and moves the c::init_locale() function to the common module.
Diffstat (limited to 'perl-install/common.pm')
-rw-r--r--perl-install/common.pm21
1 files changed, 18 insertions, 3 deletions
diff --git a/perl-install/common.pm b/perl-install/common.pm
index 508e6b31f..23ae4ea6f 100644
--- a/perl-install/common.pm
+++ b/perl-install/common.pm
@@ -7,10 +7,11 @@ BEGIN { eval { require Locale::gettext } } #- allow common.pm to be used in drak
use log;
use run_program;
+use POSIX qw(locale_h);
use Exporter;
our @ISA = qw(Exporter);
-our @EXPORT = qw($SECTORSIZE N P N_ check_for_xserver files_exist formatTime MB formatXiB get_libdir get_parent_uid is_running is_uefi kernel_uefi_type makedev mageia_release mageia_release_info mount_efivars removeXiBSuffix require_root_capability setVirtual set_alternative set_l10n_sort set_permissions to_utf8 translate uefi_type unmakedev);
+our @EXPORT = qw($SECTORSIZE N P N_ check_for_xserver files_exist formatTime MB formatXiB get_libdir get_parent_uid init_setlocale is_running is_uefi kernel_uefi_type makedev mageia_release mageia_release_info mount_efivars removeXiBSuffix require_root_capability setVirtual set_alternative set_l10n_sort set_permissions to_utf8 translate uefi_type unmakedev);
# perl_checker: RE-EXPORT-ALL
push @EXPORT, @MDK::Common::EXPORT;
@@ -34,6 +35,20 @@ our $SECTORSIZE = 512;
=over
+=item init_setlocale()
+
+Initialise all locale categories. Set LC_NUMERIC to 'C' (otherwise eval "1.5" returns 1
+in fr_FR for example). Set all other categories according to the current value of the
+LC_ALL environment variable, or if that is undefined, the LANG environment variable, or
+if that is undefined, the system default.
+
+=cut
+
+sub init_setlocale() {
+ setlocale(LC_ALL, '');
+ setlocale(LC_NUMERIC, 'C');
+}
+
=item N($format, ...)
translate a message by calling gettext(). eg:
@@ -171,8 +186,8 @@ only LC_COLLATE will have no effect.
sub set_l10n_sort() {
my $collation_locale = $ENV{LC_ALL};
if (!$collation_locale) {
- $collation_locale = c::setlocale(c::LC_COLLATE());
- $collation_locale =~ /UTF-8/ or c::setlocale(c::LC_COLLATE(), "$collation_locale.UTF-8");
+ $collation_locale = setlocale(LC_COLLATE);
+ $collation_locale =~ /UTF-8/ or setlocale(LC_COLLATE, "$collation_locale.UTF-8");
}
}