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,
21
#ifndef DRIZZLED_GETTEXT_H
22
#define DRIZZLED_GETTEXT_H
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)
68
The casts to 'const char *' serve the purpose of producing warnings
69
for invalid uses of the value returned from these functions.
70
On pre-ANSI systems without 'const', the config.h file is supposed to
71
contain "#define const". */
72
# define gettext(Msgid) ((const char *) (Msgid))
73
# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid))
74
# define dcgettext(Domainname, Msgid, Category) \
75
((void) (Category), dgettext (Domainname, Msgid))
76
# define ngettext(Msgid1, Msgid2, N) \
78
? ((void) (Msgid2), (const char *) (Msgid1)) \
79
: ((void) (Msgid1), (const char *) (Msgid2)))
80
# define dngettext(Domainname, Msgid1, Msgid2, N) \
81
((void) (Domainname), ngettext (Msgid1, Msgid2, N))
82
# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
83
((void) (Category), dngettext(Domainname, Msgid1, Msgid2, N))
84
# define textdomain(Domainname) ((const char *) (Domainname))
85
# define bindtextdomain(Domainname, Dirname) \
86
((void) (Domainname), (const char *) (Dirname))
87
# define bind_textdomain_codeset(Domainname, Codeset) \
88
((void) (Domainname), (const char *) (Codeset))
92
/* A pseudo function call that serves as a marker for the automated
93
extraction of messages, but does not call gettext(). The run-time
94
translation is done at a different place in the code.
95
The argument, String, should be a literal string. Concatenated strings
96
and other string expressions won't work.
97
The macro's expansion is not parenthesized, so that it is suitable as
98
initializer for static 'char[]' or 'const char[]' variables. */
99
#define gettext_noop(String) String
101
/* The separator between msgctxt and msgid in a .mo file. */
102
#define GETTEXT_CONTEXT_GLUE "\004"
104
/* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a
105
MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be
106
short and rarely need to change.
107
The letter 'p' stands for 'particular' or 'special'. */
108
#ifdef DEFAULT_TEXT_DOMAIN
109
# define pgettext(Msgctxt, Msgid) \
110
pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
112
# define pgettext(Msgctxt, Msgid) \
113
pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
115
#define dpgettext(Domainname, Msgctxt, Msgid) \
116
pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
117
#define dcpgettext(Domainname, Msgctxt, Msgid, Category) \
118
pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category)
119
#ifdef DEFAULT_TEXT_DOMAIN
120
# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
121
npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
123
# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
124
npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
126
#define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
127
npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
128
#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \
129
npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category)
139
pgettext_aux (const char *domain,
140
const char *msg_ctxt_id, const char *msgid,
143
const char *translation = dcgettext (domain, msg_ctxt_id, category);
144
if (translation == msg_ctxt_id)
158
npgettext_aux (const char *domain,
159
const char *msg_ctxt_id, const char *msgid,
160
const char *msgid_plural, unsigned long int n,
163
const char *translation =
164
dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
165
if (translation == msg_ctxt_id || translation == msgid_plural)
166
return (n == 1 ? msgid : msgid_plural);
171
/* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID
172
can be arbitrary expressions. But for string literals these macros are
173
less efficient than those above. */
177
/* We need to turn these off explicitly for drizzle */
178
#define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 0
180
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
184
#define pgettext_expr(Msgctxt, Msgid) \
185
dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES)
186
#define dpgettext_expr(Domainname, Msgctxt, Msgid) \
187
dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
197
dcpgettext_expr (const char *domain,
198
const char *msgctxt, const char *msgid,
201
size_t msgctxt_len = strlen (msgctxt) + 1;
202
size_t msgid_len = strlen (msgid) + 1;
203
const char *translation;
204
#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
205
char msg_ctxt_id[msgctxt_len + msgid_len];
209
(msgctxt_len + msgid_len <= sizeof (buf)
211
: (char *) malloc (msgctxt_len + msgid_len));
212
if (msg_ctxt_id != NULL)
215
memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
216
msg_ctxt_id[msgctxt_len - 1] = '\004';
217
memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
218
translation = dcgettext (domain, msg_ctxt_id, category);
219
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
220
if (msg_ctxt_id != buf)
223
if (translation != msg_ctxt_id)
229
#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \
230
dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
231
#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
232
dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
242
dcnpgettext_expr (const char *domain,
243
const char *msgctxt, const char *msgid,
244
const char *msgid_plural, unsigned long int n,
247
size_t msgctxt_len = strlen (msgctxt) + 1;
248
size_t msgid_len = strlen (msgid) + 1;
249
const char *translation;
250
#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
251
char msg_ctxt_id[msgctxt_len + msgid_len];
255
(msgctxt_len + msgid_len <= sizeof (buf)
257
: (char *) malloc (msgctxt_len + msgid_len));
258
if (msg_ctxt_id != NULL)
261
memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
262
msg_ctxt_id[msgctxt_len - 1] = '\004';
263
memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
264
translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
265
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
266
if (msg_ctxt_id != buf)
269
if (!(translation == msg_ctxt_id || translation == msgid_plural))
272
return (n == 1 ? msgid : msgid_plural);
275
#define _(String) gettext(String)
276
#define N_(String) gettext_noop(String)
277
#endif /* DRIZZLED_GETTEXT_H */