1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
Convenience header for conditional use of GNU <libintl.h>.
4
Copyright (C) 1995-1998, 2000-2002, 2004-2006 Free Software Foundation, Inc.
6
This program is free software; you can redistribute it and/or modify it
7
under the terms of the GNU General Public License as published
8
by the Free Software Foundation; either version 2, or (at your option)
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Library General Public License for more details.
16
You should have received a copy of the GNU General Public
17
License along with this program; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22
#define _LIBGETTEXT_H 1
24
/* NLS can be disabled through the configure --disable-nls option. */
25
#if defined(ENABLE_NLS)
27
/* Get declarations of GNU message catalog functions. */
30
/* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by
31
the gettext() and ngettext() macros. This is an alternative to calling
32
textdomain(), and is useful for libraries. */
33
# ifdef DEFAULT_TEXT_DOMAIN
35
# define gettext(Msgid) \
36
dgettext (DEFAULT_TEXT_DOMAIN, Msgid)
38
# define ngettext(Msgid1, Msgid2, N) \
39
dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N)
44
/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
45
chokes if dcgettext is defined as a macro. So include it now, to make
46
later inclusions of <locale.h> a NOP. We don't include <libintl.h>
47
as well because people using "gettext.h" will not include <libintl.h>,
48
and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
54
/* Many header files from the libstdc++ coming with g++ 3.3 or newer include
55
<libintl.h>, which chokes if dcgettext is defined as a macro. So include
56
it now, to make later inclusions of <libintl.h> a NOP. */
57
#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3)
59
# if defined(__GLIBC__)
60
# if (__GLIBC__ >= 2) || defined(_GLIBCXX_HAVE_LIBINTL_H)
67
The casts to 'const char *' serve the purpose of producing warnings
68
for invalid uses of the value returned from these functions.
69
On pre-ANSI systems without 'const', the config.h file is supposed to
70
contain "#define const". */
71
# define gettext(Msgid) ((const char *) (Msgid))
72
# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid))
73
# define dcgettext(Domainname, Msgid, Category) \
74
((void) (Category), dgettext (Domainname, Msgid))
75
# define ngettext(Msgid1, Msgid2, N) \
77
? ((void) (Msgid2), (const char *) (Msgid1)) \
78
: ((void) (Msgid1), (const char *) (Msgid2)))
79
# define dngettext(Domainname, Msgid1, Msgid2, N) \
80
((void) (Domainname), ngettext (Msgid1, Msgid2, N))
81
# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
82
((void) (Category), dngettext(Domainname, Msgid1, Msgid2, N))
83
# define textdomain(Domainname) ((const char *) (Domainname))
84
# define bindtextdomain(Domainname, Dirname) \
85
((void) (Domainname), (const char *) (Dirname))
86
# define bind_textdomain_codeset(Domainname, Codeset) \
87
((void) (Domainname), (const char *) (Codeset))
91
/* A pseudo function call that serves as a marker for the automated
92
extraction of messages, but does not call gettext(). The run-time
93
translation is done at a different place in the code.
94
The argument, String, should be a literal string. Concatenated strings
95
and other string expressions won't work.
96
The macro's expansion is not parenthesized, so that it is suitable as
97
initializer for static 'char[]' or 'const char[]' variables. */
98
#define gettext_noop(String) String
100
/* The separator between msgctxt and msgid in a .mo file. */
101
#define GETTEXT_CONTEXT_GLUE "\004"
103
/* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a
104
MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be
105
short and rarely need to change.
106
The letter 'p' stands for 'particular' or 'special'. */
107
#ifdef DEFAULT_TEXT_DOMAIN
108
# define pgettext(Msgctxt, Msgid) \
109
pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
111
# define pgettext(Msgctxt, Msgid) \
112
pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
114
#define dpgettext(Domainname, Msgctxt, Msgid) \
115
pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
116
#define dcpgettext(Domainname, Msgctxt, Msgid, Category) \
117
pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category)
118
#ifdef DEFAULT_TEXT_DOMAIN
119
# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
120
npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
122
# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
123
npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
125
#define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
126
npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
127
#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \
128
npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category)
138
pgettext_aux (const char *domain,
139
const char *msg_ctxt_id, const char *msgid,
142
const char *translation = dcgettext (domain, msg_ctxt_id, category);
143
if (translation == msg_ctxt_id)
157
npgettext_aux (const char *domain,
158
const char *msg_ctxt_id, const char *msgid,
159
const char *msgid_plural, unsigned long int n,
162
const char *translation =
163
dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
164
if (translation == msg_ctxt_id || translation == msgid_plural)
165
return (n == 1 ? msgid : msgid_plural);
170
/* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID
171
can be arbitrary expressions. But for string literals these macros are
172
less efficient than those above. */
176
/* We need to turn these off explicitly for drizzle */
177
#define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 0
179
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
183
#define pgettext_expr(Msgctxt, Msgid) \
184
dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES)
185
#define dpgettext_expr(Domainname, Msgctxt, Msgid) \
186
dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
196
dcpgettext_expr (const char *domain,
197
const char *msgctxt, const char *msgid,
200
size_t msgctxt_len = strlen (msgctxt) + 1;
201
size_t msgid_len = strlen (msgid) + 1;
202
const char *translation;
203
#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
204
char msg_ctxt_id[msgctxt_len + msgid_len];
208
(msgctxt_len + msgid_len <= sizeof (buf)
210
: (char *) malloc (msgctxt_len + msgid_len));
211
if (msg_ctxt_id != NULL)
214
memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
215
msg_ctxt_id[msgctxt_len - 1] = '\004';
216
memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
217
translation = dcgettext (domain, msg_ctxt_id, category);
218
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
219
if (msg_ctxt_id != buf)
222
if (translation != msg_ctxt_id)
228
#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \
229
dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
230
#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
231
dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
241
dcnpgettext_expr (const char *domain,
242
const char *msgctxt, const char *msgid,
243
const char *msgid_plural, unsigned long int n,
246
size_t msgctxt_len = strlen (msgctxt) + 1;
247
size_t msgid_len = strlen (msgid) + 1;
248
const char *translation;
249
#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
250
char msg_ctxt_id[msgctxt_len + msgid_len];
254
(msgctxt_len + msgid_len <= sizeof (buf)
256
: (char *) malloc (msgctxt_len + msgid_len));
257
if (msg_ctxt_id != NULL)
260
memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
261
msg_ctxt_id[msgctxt_len - 1] = '\004';
262
memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
263
translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
264
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
265
if (msg_ctxt_id != buf)
268
if (!(translation == msg_ctxt_id || translation == msgid_plural))
271
return (n == 1 ? msgid : msgid_plural);
274
#define _(String) gettext(String)
275
#define N_(String) gettext_noop(String)
276
#endif /* _LIBGETTEXT_H */