]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
msginit: Fix encoding of second title line, part 1.
authorBruno Haible <bruno@clisp.org>
Fri, 18 Jul 2025 19:34:55 +0000 (21:34 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 18 Jul 2025 19:34:55 +0000 (21:34 +0200)
Reported by Matilin Torre <watilin@protonmail.com> in
<https://lists.gnu.org/archive/html/bug-gettext/2025-07/msg00024.html>.

* gettext-tools/src/msginit.c: Include xstriconv.h.
(get_title): Don't set OUTPUT_CHARSET; this does not work any more since 2005,
when an optimization was made in dcigettext.c. Instead, use xstr_iconv().

gettext-tools/src/msginit.c

index 4182ec9e30585735b047e1b15cb43b87c395caaa..1387d42e329bc5304381e6548c72aaa4c16d33a0 100644 (file)
@@ -77,6 +77,7 @@
 #include "spawn-pipe.h"
 #include "wait-process.h"
 #include "xsetenv.h"
+#include "xstriconv.h"
 #include "str-list.h"
 #include "propername.h"
 #include "gettext.h"
@@ -1644,14 +1645,13 @@ get_title ()
   /* This is tricky.  We want the translation in the given locale specified by
      the command line, not the current locale.  But we want it in the encoding
      that we put into the header entry, not the encoding of that locale.
-     We could avoid the use of OUTPUT_CHARSET by using a separate message
-     catalog and bind_textdomain_codeset(), but that doesn't seem worth the
-     trouble for one single message.  */
+     We could avoid the use of xstr_iconv() by using a separate message catalog
+     and bind_textdomain_codeset(), but that doesn't seem worth the trouble
+     for one single message.  */
   const char *encoding;
   const char *tmp;
   char *old_LC_ALL;
   char *old_LANGUAGE;
-  char *old_OUTPUT_CHARSET;
   const char *msgid;
   const char *english;
   const char *result;
@@ -1662,7 +1662,7 @@ get_title ()
   english = xasprintf ("%s translations for %%s package",
                        englishname_of_language ());
 
-  /* Save LC_ALL, LANGUAGE, OUTPUT_CHARSET environment variables.  */
+  /* Save LC_ALL, LANGUAGE environment variables.  */
 
   tmp = getenv ("LC_ALL");
   old_LC_ALL = (tmp != NULL ? xstrdup (tmp) : NULL);
@@ -1670,12 +1670,8 @@ get_title ()
   tmp = getenv ("LANGUAGE");
   old_LANGUAGE = (tmp != NULL ? xstrdup (tmp) : NULL);
 
-  tmp = getenv ("OUTPUT_CHARSET");
-  old_OUTPUT_CHARSET = (tmp != NULL ? xstrdup (tmp) : NULL);
-
   xsetenv ("LC_ALL", locale, 1);
   unsetenv ("LANGUAGE");
-  xsetenv ("OUTPUT_CHARSET", encoding, 1);
 
   if (setlocale (LC_ALL, "") == NULL)
     /* Nonexistent locale.  Use the English title.  */
@@ -1690,13 +1686,14 @@ get_title ()
       result = gettext (msgid);
       if (result != msgid && strcmp (result, msgid) != 0)
         /* Use the English and the foreign title.  */
-        result = xasprintf ("%s\n%s", english, result);
+        result = xasprintf ("%s\n%s", english,
+                            xstr_iconv (result, locale_charset (), encoding));
       else
         /* No translation found.  Use the English title.  */
         result = english;
     }
 
-  /* Restore LC_ALL, LANGUAGE, OUTPUT_CHARSET environment variables.  */
+  /* Restore LC_ALL, LANGUAGE environment variables.  */
 
   if (old_LC_ALL != NULL)
     xsetenv ("LC_ALL", old_LC_ALL, 1), free (old_LC_ALL);
@@ -1708,11 +1705,6 @@ get_title ()
   else
     unsetenv ("LANGUAGE");
 
-  if (old_OUTPUT_CHARSET != NULL)
-    xsetenv ("OUTPUT_CHARSET", old_OUTPUT_CHARSET, 1), free (old_OUTPUT_CHARSET);
-  else
-    unsetenv ("OUTPUT_CHARSET");
-
   setlocale (LC_ALL, "");
 
   return result;