]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Fix two msginit bugs, occurring when --locale is given.
authorBruno Haible <bruno@clisp.org>
Mon, 26 Nov 2001 13:42:58 +0000 (13:42 +0000)
committerBruno Haible <bruno@clisp.org>
Sun, 21 Jun 2009 21:25:16 +0000 (23:25 +0200)
src/ChangeLog
src/msginit.c

index 9c5ac6d83bf57050ff9c32ba47b9b5f19b164b7b..13f1621144d9c3ccfd0a1ab00c08c56c328f1c7c 100644 (file)
@@ -1,3 +1,10 @@
+2001-11-25  Bruno Haible  <bruno@clisp.org>
+
+       * 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  <bruno@clisp.org>
 
        * urlget.c (fetch): Call execute_java_class with quiet=true. If Java
index 2b8422806c7e9bb221e7aa0e0d9ddc77c0447685..60336a4492968d9cb7b382d680cfebf40db6992e 100644 (file)
@@ -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.  */