1 /* Message list charset and locale charset handling.
2 Copyright (C) 2001-2003, 2005-2007, 2009 Free Software Foundation, Inc.
3 Written by Bruno Haible <haible@clisp.cons.org>, 2001.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "msgl-charset.h"
31 #include "po-charset.h"
32 #include "localcharset.h"
38 #include "xvasprintf.h"
43 #define _(str) gettext (str)
46 compare_po_locale_charsets (const msgdomain_list_ty *mdlp)
48 const char *locale_code;
49 const char *canon_locale_code;
53 /* Check whether the locale encoding and the PO file's encoding are the
54 same. Otherwise emit a warning. */
55 locale_code = locale_charset ();
56 canon_locale_code = po_charset_canonicalize (locale_code);
58 for (k = 0; k < mdlp->nitems; k++)
60 const message_list_ty *mlp = mdlp->item[k]->messages;
62 for (j = 0; j < mlp->nitems; j++)
63 if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete)
65 const char *header = mlp->item[j]->msgstr;
69 const char *charsetstr = c_strstr (header, "charset=");
71 if (charsetstr != NULL)
75 const char *canon_charset;
77 charsetstr += strlen ("charset=");
78 len = strcspn (charsetstr, " \t\n");
79 charset = (char *) xmalloca (len + 1);
80 memcpy (charset, charsetstr, len);
83 canon_charset = po_charset_canonicalize (charset);
84 if (canon_charset == NULL)
85 error (EXIT_FAILURE, 0,
87 present charset \"%s\" is not a portable encoding name"),
90 if (canon_locale_code != canon_charset)
92 multiline_warning (xasprintf (_("warning: ")),
94 Locale charset \"%s\" is different from\n\
95 input file charset \"%s\".\n\
96 Output of '%s' might be incorrect.\n\
97 Possible workarounds are:\n\
98 "), locale_code, canon_charset, basename (program_name)));
99 multiline_warning (NULL,
101 - Set LC_ALL to a locale with encoding %s.\n\
103 if (canon_locale_code != NULL)
104 multiline_warning (NULL,
106 - Convert the translation catalog to %s using 'msgconv',\n\
108 then convert back to %s using 'msgconv'.\n\
109 "), canon_locale_code, basename (program_name), canon_charset));
110 if (strcmp (canon_charset, "UTF-8") != 0
111 && (canon_locale_code == NULL
112 || strcmp (canon_locale_code, "UTF-8") != 0))
113 multiline_warning (NULL,
115 - Set LC_ALL to a locale with encoding %s,\n\
116 convert the translation catalog to %s using 'msgconv',\n\
118 then convert back to %s using 'msgconv'.\n\
119 "), "UTF-8", "UTF-8", basename (program_name), canon_charset));
126 if (canon_locale_code == NULL && !warned)
127 multiline_warning (xasprintf (_("warning: ")),
129 Locale charset \"%s\" is not a portable encoding name.\n\
130 Output of '%s' might be incorrect.\n\
131 A possible workaround is to set LC_ALL=C.\n\
132 "), locale_code, basename (program_name)));