1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/* Message list charset and locale charset handling.
Copyright (C) 2001 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2001.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdlib.h>
#include <string.h>
#include "po-charset.h"
#include "msgl-charset.h"
#include "error.h"
#include "progname.h"
#include "xerror.h"
#include "message.h"
#include "system.h"
#include "libgettext.h"
#define _(str) gettext (str)
extern const char * locale_charset PARAMS ((void));
void
compare_po_locale_charsets (mdlp)
const msgdomain_list_ty *mdlp;
{
const char *locale_code;
const char *canon_locale_code;
bool warned;
size_t j, k;
/* Check whether the locale encoding and the PO file's encoding are the
same. Otherwise emit a warning. */
locale_code = locale_charset ();
canon_locale_code = po_charset_canonicalize (locale_code);
warned = false;
for (k = 0; k < mdlp->nitems; k++)
{
const message_list_ty *mlp = mdlp->item[k]->messages;
for (j = 0; j < mlp->nitems; j++)
if (mlp->item[j]->msgid[0] == '\0' && !mlp->item[j]->obsolete)
{
const char *header = mlp->item[j]->msgstr;
if (header != NULL)
{
const char *charsetstr = strstr (header, "charset=");
if (charsetstr != NULL)
{
size_t len;
char *charset;
const char *canon_charset;
charsetstr += strlen ("charset=");
len = strcspn (charsetstr, " \t\n");
charset = (char *) alloca (len + 1);
memcpy (charset, charsetstr, len);
charset[len] = '\0';
canon_charset = po_charset_canonicalize (charset);
if (canon_charset == NULL)
error (EXIT_FAILURE, 0,
_("\
present charset \"%s\" is not a portable encoding name"),
charset);
if (canon_locale_code != canon_charset)
{
multiline_warning (xasprintf (_("warning: ")),
xasprintf (_("\
Locale charset \"%s\" is different from\n\
input file charset \"%s\".\n\
Output of '%s' might be incorrect.\n\
Possible workarounds are:\n\
"), locale_code, canon_charset, basename (program_name)));
multiline_warning (NULL,
xasprintf (_("\
- Set LC_ALL to a locale with encoding %s.\n\
"), canon_charset));
if (canon_locale_code != NULL)
multiline_warning (NULL,
xasprintf (_("\
- Convert the translation catalog to %s using 'msgconv',\n\
then apply '%s',\n\
then convert back to %s using 'msgconv'.\n\
"), canon_locale_code, basename (program_name), canon_charset));
if (strcmp (canon_charset, "UTF-8") != 0
&& (canon_locale_code == NULL
|| strcmp (canon_locale_code, "UTF-8") != 0))
multiline_warning (NULL,
xasprintf (_("\
- Set LC_ALL to a locale with encoding %s,\n\
convert the translation catalog to %s using 'msgconv',\n\
then apply '%s',\n\
then convert back to %s using 'msgconv'.\n\
"), "UTF-8", "UTF-8", basename (program_name), canon_charset));
warned = true;
}
}
}
}
}
if (canon_locale_code == NULL && !warned)
multiline_warning (xasprintf (_("warning: ")),
xasprintf (_("\
Locale charset \"%s\" is not a portable encoding name.\n\
Output of '%s' might be incorrect.\n\
A possible workaround is to set LC_ALL=C.\n\
"), locale_code, basename (program_name)));
}
|