@@ -475,6 +475,22 @@ sub nl_putenv ($)
475
475
sub __load_domain
476
476
{
477
477
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
+ }
478
494
479
495
$domainname = $__gettext_pp_textdomain
480
496
unless defined $domainname && length $domainname ;
@@ -489,8 +505,12 @@ sub __load_domain
489
505
if (defined $ENV {LANGUAGE } && length $ENV {LANGUAGE }) {
490
506
@locales = split /:/, $ENV {LANGUAGE };
491
507
$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 );
492
512
} else {
493
- @locales = $cache_key = __locale_category ( $category , $category_name ) ;
513
+ @locales = $cache_key = $locale ;
494
514
}
495
515
496
516
# Have we looked that one up already?
@@ -700,7 +720,7 @@ sub __locale_category
700
720
(?:\. [-_A-Za-z0-9]+)?
701
721
)?
702
722
(?:\@ [-_A-Za-z0-9]+)?$ /x );
703
-
723
+
704
724
unless ($value ) {
705
725
$value = $ENV {LC_ALL };
706
726
$value = $ENV {$category_name } unless defined $value && length $value ;
0 commit comments