Skip to content

Commit 5910980

Browse files
committed
correct behavior for LANG(UAGE)
The environment variables LANGUAGE or LANG are now ignored, when neither LC_ALL nor LC_MESSAGES are set to a valid locale (not C or POSIX). This fixes https://rt.cpan.org/Public/Bug/Display.html?id=81315
1 parent 9045f08 commit 5910980

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

lib/Locale/gettext_pp.pm

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,22 @@ sub nl_putenv ($)
475475
sub __load_domain
476476
{
477477
my ($domainname, $category, $category_name) = @_;
478+
479+
# If no locale was selected for the requested locale category,
480+
# l10n is disabled completely. This matches the behavior of GNU
481+
# gettext.
482+
if ($category != LC_MESSAGES) {
483+
# Not supported.
484+
return [];
485+
}
486+
487+
my $locale;
488+
unless ($category == 1729) {
489+
$locale = POSIX::setlocale ($category);
490+
if (!defined $locale || 'C' eq $locale || 'POSIX' eq $locale) {
491+
return [];
492+
}
493+
}
478494

479495
$domainname = $__gettext_pp_textdomain
480496
unless defined $domainname && length $domainname;
@@ -489,8 +505,12 @@ sub __load_domain
489505
if (defined $ENV{LANGUAGE} && length $ENV{LANGUAGE}) {
490506
@locales = split /:/, $ENV{LANGUAGE};
491507
$cache_key = $ENV{LANGUAGE};
508+
} elsif (!defined $locale) {
509+
# The system does not have LC_MESSAGES. Guess the value.
510+
@locales = $cache_key = __locale_category ($category,
511+
$category_name);
492512
} else {
493-
@locales = $cache_key = __locale_category ($category, $category_name);
513+
@locales = $cache_key = $locale;
494514
}
495515

496516
# Have we looked that one up already?
@@ -700,7 +720,7 @@ sub __locale_category
700720
(?:\.[-_A-Za-z0-9]+)?
701721
)?
702722
(?:\@[-_A-Za-z0-9]+)?$/x);
703-
723+
704724
unless ($value) {
705725
$value = $ENV{LC_ALL};
706726
$value = $ENV{$category_name} unless defined $value && length $value;

0 commit comments

Comments
 (0)