From: Bruno Haible Date: Mon, 26 Nov 2001 13:42:58 +0000 (+0000) Subject: Fix two msginit bugs, occurring when --locale is given. X-Git-Tag: v0.11~270 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3bc7861e4d2ee9835b9b5c8609f092b3bd18dbb1;p=thirdparty%2Fgettext.git Fix two msginit bugs, occurring when --locale is given. --- diff --git a/src/ChangeLog b/src/ChangeLog index 9c5ac6d83..13f162114 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2001-11-25 Bruno Haible + + * msginit.c (canonical_locale_charset): Return the charset of 'locale' + if available. + (get_title): Return a correct value even if 'locale' is a nonexistent + locale. + 2001-11-24 Bruno Haible * urlget.c (fetch): Call execute_java_class with quiet=true. If Java diff --git a/src/msginit.c b/src/msginit.c index 2b8422806..60336a449 100644 --- a/src/msginit.c +++ b/src/msginit.c @@ -629,10 +629,38 @@ language_of_locale (locale) static const char * canonical_locale_charset () { + const char *tmp; + char *old_LC_ALL; const char *charset; - /* Get the current locale's charset and canonicalize it. */ - charset = locale_charset (); + /* Save LC_ALL environment variable. */ + + tmp = getenv ("LC_ALL"); + old_LC_ALL = (tmp != NULL ? xstrdup (tmp) : NULL); + + setenv ("LC_ALL", locale, 1); + +#ifdef HAVE_SETLOCALE + if (setlocale (LC_ALL, "") == NULL) + /* Nonexistent locale. Use anything. */ + charset = ""; + else +#endif + /* Get the locale's charset. */ + charset = locale_charset (); + + /* Restore LC_ALL environment variable. */ + + if (old_LC_ALL != NULL) + setenv ("LC_ALL", old_LC_ALL, 1), free (old_LC_ALL); + else + unsetenv ("LC_ALL"); + +#ifdef HAVE_SETLOCALE + setlocale (LC_ALL, ""); +#endif + + /* Canonicalize it. */ charset = po_charset_canonicalize (charset); if (charset == NULL) charset = po_charset_ascii; @@ -1350,6 +1378,10 @@ get_title () encoding = canonical_locale_charset (); + /* First, the English title. */ + english = xasprintf ("%s translations for %%s package", + englishname_of_language ()); + /* Save LC_ALL, LANGUAGE, OUTPUT_CHARSET environment variables. */ tmp = getenv ("LC_ALL"); @@ -1366,25 +1398,25 @@ get_title () setenv ("OUTPUT_CHARSET", encoding, 1); #ifdef HAVE_SETLOCALE - setlocale (LC_ALL, ""); -#endif - - /* First, the English title. */ - english = xasprintf ("%s translations for %%s package", - englishname_of_language ()); - - /* Fetch the translation. */ - /* TRANSLATORS: "English" needs to be replaced by your language. - For example in it.po write "Traduzioni italiani ...", - *not* "Traduzioni inglesi ...". */ - msgid = N_("English translations for %s package"); - result = gettext (msgid); - if (result != msgid && strcmp (result, msgid) != 0) - /* Use the English and the foreign title. */ - result = xasprintf ("%s\n%s", english, result); - else - /* No translation found. Use the English title. */ + if (setlocale (LC_ALL, "") == NULL) + /* Nonexistent locale. Use the English title. */ result = english; + else +#endif + { + /* Fetch the translation. */ + /* TRANSLATORS: "English" needs to be replaced by your language. + For example in it.po write "Traduzioni italiani ...", + *not* "Traduzioni inglesi ...". */ + msgid = N_("English translations for %s package"); + result = gettext (msgid); + if (result != msgid && strcmp (result, msgid) != 0) + /* Use the English and the foreign title. */ + result = xasprintf ("%s\n%s", english, result); + else + /* No translation found. Use the English title. */ + result = english; + } /* Restore LC_ALL, LANGUAGE, OUTPUT_CHARSET environment variables. */