[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: Save and restore LC_MESSAGES
From: |
Gavin D. Smith |
Subject: |
branch master updated: Save and restore LC_MESSAGES |
Date: |
Fri, 21 Oct 2022 17:04:07 -0400 |
This is an automated email from the git hooks/post-receive script.
gavin pushed a commit to branch master
in repository texinfo.
The following commit(s) were added to refs/heads/master by this push:
new 178d1f4d6f Save and restore LC_MESSAGES
178d1f4d6f is described below
commit 178d1f4d6f4c5f10657e891a1a8552b2f93da6e5
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Fri Oct 21 22:03:56 2022 +0100
Save and restore LC_MESSAGES
* tp/Texinfo/Translations.pm (gdt):
Save and restore LC_MESSAGES rather than LC_ALL, as this seems
safer than switching LC_ALL and not switching it back (see change
on 2022-10-20). Don't do this on MS-Windows where there were
problems before with LC_MESSAGES (see change on 2021-02-27).
---
ChangeLog | 10 ++++++
tp/Texinfo/Translations.pm | 80 ++++++++++++++++++++++++++--------------------
2 files changed, 55 insertions(+), 35 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index db938cdbf7..678553dd00 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2022-10-21 Gavin Smith <gavinsmith0123@gmail.com>
+
+ Save and restore LC_MESSAGES
+
+ * tp/Texinfo/Translations.pm (gdt):
+ Save and restore LC_MESSAGES rather than LC_ALL, as this seems
+ safer than switching LC_ALL and not switching it back (see change
+ on 2022-10-20). Don't do this on MS-Windows where there were
+ problems before with LC_MESSAGES (see change on 2021-02-27).
+
2022-10-21 Patrice Dumas <pertusus@free.fr>
* doc/refcard/txicmdcheck (read_refidx): filter out @sortas.
diff --git a/tp/Texinfo/Translations.pm b/tp/Texinfo/Translations.pm
index cffae3aeca..cac99ac9e9 100644
--- a/tp/Texinfo/Translations.pm
+++ b/tp/Texinfo/Translations.pm
@@ -26,7 +26,7 @@ use strict;
#no autovivification qw(fetch delete exists store strict);
use Encode;
-use POSIX qw(setlocale LC_ALL);
+use POSIX qw(setlocale LC_ALL LC_MESSAGES);
use Locale::Messages;
# note that there is a circular dependency with the parser module, as
@@ -62,40 +62,20 @@ sub _decode_i18n_string($$)
return Encode::decode($encoding, $string);
}
-# Get document translation - handle translations of in-document strings.
-# Return a parsed Texinfo tree
-sub gdt($$;$$$)
+sub _switch_messages_locale
{
- my ($self, $message, $context, $type, $lang) = @_;
-
- # In addition to being settable from the command line,
- # the language needs to be dynamic in case there is an untranslated string
- # from another language that needs to be translated.
- $lang = $self->get_conf('documentlanguage') if ($self and !defined($lang));
- $lang = $DEFAULT_LANGUAGE if (!defined($lang));
-
- my $re = join '|', map { quotemeta $_ } keys %$context
- if (defined($context) and ref($context));
-
- my $saved_LC_ALL = POSIX::setlocale(LC_ALL);
- my $saved_LANGUAGE = $ENV{'LANGUAGE'};
-
- # We need to set LC_MESSAGES to a valid locale other than "C" or "POSIX"
- # for translation via LANGUAGE to work. (The locale is "C" if the
- # tests are being run.)
- # Set LC_ALL rather than LC_MESSAGES for Perl for MS-Windows.
-
my $locale;
our $working_locale;
if ($working_locale) {
- $locale = POSIX::setlocale(LC_ALL, $working_locale);
+ $locale = POSIX::setlocale(LC_MESSAGES, $working_locale);
}
if (!$locale) {
- $locale = POSIX::setlocale(LC_ALL, "en_US.UTF-8");
+ $locale = POSIX::setlocale(LC_MESSAGES, "en_US.UTF-8");
}
if (!$locale) {
- $locale = POSIX::setlocale(LC_ALL, "en_US")
+ $locale = POSIX::setlocale(LC_MESSAGES, "en_US")
}
+ # try the output of 'locale -a' (but only once)
our $locale_command;
if (!$locale and !$locale_command) {
$locale_command = "locale -a";
@@ -103,13 +83,43 @@ sub gdt($$;$$$)
if ($? == 0) {
foreach my $try (@local_command_locales) {
next if $try eq 'C' or $try eq 'POSIX';
- $locale = POSIX::setlocale(LC_ALL, $try);
+ $locale = POSIX::setlocale(LC_MESSAGES, $try);
last if $locale;
}
}
}
$working_locale = $locale;
+}
+# Get document translation - handle translations of in-document strings.
+# Return a parsed Texinfo tree
+sub gdt($$;$$$)
+{
+ my ($self, $message, $context, $type, $lang) = @_;
+
+ # In addition to being settable from the command line,
+ # the language needs to be dynamic in case there is an untranslated string
+ # from another language that needs to be translated.
+ $lang = $self->get_conf('documentlanguage') if ($self and !defined($lang));
+ $lang = $DEFAULT_LANGUAGE if (!defined($lang));
+
+ my $re = join '|', map { quotemeta $_ } keys %$context
+ if (defined($context) and ref($context));
+
+ my ($saved_LC_MESSAGES, $saved_LANGUAGE);
+
+ # We need to set LC_MESSAGES to a valid locale other than "C" or "POSIX"
+ # for translation via LANGUAGE to work. (The locale is "C" if the
+ # tests are being run.)
+ # LC_MESSAGES was reported not to exit for Perl on MS-Windows. We
+ # could use LC_ALL instead, but (a) it's not clear if this would help,
+ # and (b) this could interfere with the LC_CTYPE setting in XSParagraph.
+
+ if ($^O ne 'MSWin32') {
+ $saved_LC_MESSAGES = POSIX::setlocale(LC_MESSAGES);
+ _switch_messages_locale();
+ }
+ $saved_LANGUAGE = $ENV{'LANGUAGE'};
Locale::Messages::textdomain($strings_textdomain);
@@ -172,20 +182,20 @@ sub gdt($$;$$$)
my $translated_message = Locale::Messages::gettext($message);
Locale::Messages::textdomain($messages_textdomain);
+
if (!defined($saved_LANGUAGE)) {
delete ($ENV{'LANGUAGE'});
} else {
$ENV{'LANGUAGE'} = $saved_LANGUAGE;
}
- # Don't restore LC_ALL because this can clobber LC_CTYPE which needs
- # to be set to 'UTF-8' in XSParagraph for iterating over UTF-8 sequences.
- #
- # if (defined($saved_LC_ALL)) {
- # POSIX::setlocale(LC_ALL, $saved_LC_ALL);
- # } else {
- # POSIX::setlocale(LC_ALL, '');
- # }
+ if ($^O ne 'MSWin32') {
+ if (defined($saved_LC_MESSAGES)) {
+ POSIX::setlocale(LC_MESSAGES, $saved_LC_MESSAGES);
+ } else {
+ POSIX::setlocale(LC_MESSAGES, '');
+ }
+ }
my $translation_result = $translated_message;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: Save and restore LC_MESSAGES,
Gavin D. Smith <=