1 /* Convenience header for conditional use of GNU <libintl.h>.
2 Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2011 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 #define _LIBGETTEXT_H 1
20 /* NLS can be disabled through the configure --disable-nls option. */
23 /* Get declarations of GNU message catalog functions. */
26 /* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by
27 the gettext() and ngettext() macros. This is an alternative to calling
28 textdomain(), and is useful for libraries. */
29 # ifdef DEFAULT_TEXT_DOMAIN
31 # define gettext(Msgid) \
32 dgettext (DEFAULT_TEXT_DOMAIN, Msgid)
34 # define ngettext(Msgid1, Msgid2, N) \
35 dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N)
40 /* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
41 chokes if dcgettext is defined as a macro. So include it now, to make
42 later inclusions of <locale.h> a NOP. We don't include <libintl.h>
43 as well because people using "gettext.h" will not include <libintl.h>,
44 and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
50 /* Many header files from the libstdc++ coming with g++ 3.3 or newer include
51 <libintl.h>, which chokes if dcgettext is defined as a macro. So include
52 it now, to make later inclusions of <libintl.h> a NOP. */
53 #if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3)
55 # if (__GLIBC__ >= 2 && !defined __UCLIBC__) || _GLIBCXX_HAVE_LIBINTL_H
61 The casts to 'const char *' serve the purpose of producing warnings
62 for invalid uses of the value returned from these functions.
63 On pre-ANSI systems without 'const', the config.h file is supposed to
64 contain "#define const". */
66 # define gettext(Msgid) ((const char *) (Msgid))
68 # define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid))
70 # define dcgettext(Domainname, Msgid, Category) \
71 ((void) (Category), dgettext (Domainname, Msgid))
73 # define ngettext(Msgid1, Msgid2, N) \
75 ? ((void) (Msgid2), (const char *) (Msgid1)) \
76 : ((void) (Msgid1), (const char *) (Msgid2)))
78 # define dngettext(Domainname, Msgid1, Msgid2, N) \
79 ((void) (Domainname), ngettext (Msgid1, Msgid2, N))
81 # define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
82 ((void) (Category), dngettext (Domainname, Msgid1, Msgid2, N))
84 # define textdomain(Domainname) ((const char *) (Domainname))
85 # undef bindtextdomain
86 # define bindtextdomain(Domainname, Dirname) \
87 ((void) (Domainname), (const char *) (Dirname))
88 # undef bind_textdomain_codeset
89 # define bind_textdomain_codeset(Domainname, Codeset) \
90 ((void) (Domainname), (const char *) (Codeset))
94 /* Prefer gnulib's setlocale override over libintl's setlocale override. */
95 #ifdef GNULIB_defined_setlocale
97 # define setlocale rpl_setlocale
100 /* A pseudo function call that serves as a marker for the automated
101 extraction of messages, but does not call gettext(). The run-time
102 translation is done at a different place in the code.
103 The argument, String, should be a literal string. Concatenated strings
104 and other string expressions won't work.
105 The macro's expansion is not parenthesized, so that it is suitable as
106 initializer for static 'char[]' or 'const char[]' variables. */
107 #define gettext_noop(String) String
109 /* The separator between msgctxt and msgid in a .mo file. */
110 #define GETTEXT_CONTEXT_GLUE "\004"
112 /* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a
113 MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be
114 short and rarely need to change.
115 The letter 'p' stands for 'particular' or 'special'. */
116 #ifdef DEFAULT_TEXT_DOMAIN
117 # define pgettext(Msgctxt, Msgid) \
118 pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
120 # define pgettext(Msgctxt, Msgid) \
121 pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
123 #define dpgettext(Domainname, Msgctxt, Msgid) \
124 pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
125 #define dcpgettext(Domainname, Msgctxt, Msgid, Category) \
126 pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category)
127 #ifdef DEFAULT_TEXT_DOMAIN
128 # define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
129 npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
131 # define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
132 npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
134 #define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
135 npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
136 #define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \
137 npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category)
147 pgettext_aux (const char *domain
,
148 const char *msg_ctxt_id
, const char *msgid
,
151 const char *translation
= dcgettext (domain
, msg_ctxt_id
, category
);
152 if (translation
== msg_ctxt_id
)
166 npgettext_aux (const char *domain
,
167 const char *msg_ctxt_id
, const char *msgid
,
168 const char *msgid_plural
, unsigned long int n
,
171 const char *translation
=
172 dcngettext (domain
, msg_ctxt_id
, msgid_plural
, n
, category
);
173 if (translation
== msg_ctxt_id
|| translation
== msgid_plural
)
174 return (n
== 1 ? msgid
: msgid_plural
);
179 /* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID
180 can be arbitrary expressions. But for string literals these macros are
181 less efficient than those above. */
185 #if (((__GNUC__ >= 3 || __GNUG__ >= 2) && !defined __STRICT_ANSI__) \
186 /* || __STDC_VERSION__ >= 199901L */ )
187 # define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 1
189 # define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 0
192 #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
196 #define pgettext_expr(Msgctxt, Msgid) \
197 dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES)
198 #define dpgettext_expr(Domainname, Msgctxt, Msgid) \
199 dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
209 dcpgettext_expr (const char *domain
,
210 const char *msgctxt
, const char *msgid
,
213 size_t msgctxt_len
= strlen (msgctxt
) + 1;
214 size_t msgid_len
= strlen (msgid
) + 1;
215 const char *translation
;
216 #if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
217 char msg_ctxt_id
[msgctxt_len
+ msgid_len
];
221 (msgctxt_len
+ msgid_len
<= sizeof (buf
)
223 : (char *) malloc (msgctxt_len
+ msgid_len
));
224 if (msg_ctxt_id
!= NULL
)
227 memcpy (msg_ctxt_id
, msgctxt
, msgctxt_len
- 1);
228 msg_ctxt_id
[msgctxt_len
- 1] = '\004';
229 memcpy (msg_ctxt_id
+ msgctxt_len
, msgid
, msgid_len
);
230 translation
= dcgettext (domain
, msg_ctxt_id
, category
);
231 #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
232 if (msg_ctxt_id
!= buf
)
235 if (translation
!= msg_ctxt_id
)
241 #define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \
242 dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
243 #define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
244 dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
254 dcnpgettext_expr (const char *domain
,
255 const char *msgctxt
, const char *msgid
,
256 const char *msgid_plural
, unsigned long int n
,
259 size_t msgctxt_len
= strlen (msgctxt
) + 1;
260 size_t msgid_len
= strlen (msgid
) + 1;
261 const char *translation
;
262 #if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
263 char msg_ctxt_id
[msgctxt_len
+ msgid_len
];
267 (msgctxt_len
+ msgid_len
<= sizeof (buf
)
269 : (char *) malloc (msgctxt_len
+ msgid_len
));
270 if (msg_ctxt_id
!= NULL
)
273 memcpy (msg_ctxt_id
, msgctxt
, msgctxt_len
- 1);
274 msg_ctxt_id
[msgctxt_len
- 1] = '\004';
275 memcpy (msg_ctxt_id
+ msgctxt_len
, msgid
, msgid_len
);
276 translation
= dcngettext (domain
, msg_ctxt_id
, msgid_plural
, n
, category
);
277 #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
278 if (msg_ctxt_id
!= buf
)
281 if (!(translation
== msg_ctxt_id
|| translation
== msgid_plural
))
284 return (n
== 1 ? msgid
: msgid_plural
);
287 #endif /* _LIBGETTEXT_H */