5 kx /* Convenience header for conditional use of GNU <libintl.h>.
5 kx Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2016 Free Software
5 kx Foundation, Inc.
5 kx
5 kx This program is free software: you can redistribute it and/or modify
5 kx it under the terms of the GNU General Public License as published by
5 kx the Free Software Foundation; either version 3 of the License, or
5 kx (at your option) any later version.
5 kx
5 kx This program is distributed in the hope that it will be useful,
5 kx but WITHOUT ANY WARRANTY; without even the implied warranty of
5 kx MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5 kx GNU General Public License for more details.
5 kx
5 kx You should have received a copy of the GNU General Public License
5 kx along with this program. If not, see <http://www.gnu.org/licenses/>. */
5 kx
5 kx #ifndef _LIBGETTEXT_H
5 kx #define _LIBGETTEXT_H 1
5 kx
5 kx /* NLS can be disabled through the configure --disable-nls option. */
5 kx #if ENABLE_NLS
5 kx
5 kx /* Get declarations of GNU message catalog functions. */
5 kx # include <libintl.h>
5 kx
5 kx /* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by
5 kx the gettext() and ngettext() macros. This is an alternative to calling
5 kx textdomain(), and is useful for libraries. */
5 kx # ifdef DEFAULT_TEXT_DOMAIN
5 kx # undef gettext
5 kx # define gettext(Msgid) \
5 kx dgettext (DEFAULT_TEXT_DOMAIN, Msgid)
5 kx # undef ngettext
5 kx # define ngettext(Msgid1, Msgid2, N) \
5 kx dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N)
5 kx # endif
5 kx
5 kx #else
5 kx
5 kx /* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
5 kx chokes if dcgettext is defined as a macro. So include it now, to make
5 kx later inclusions of <locale.h> a NOP. We don't include <libintl.h>
5 kx as well because people using "gettext.h" will not include <libintl.h>,
5 kx and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
5 kx is OK. */
5 kx #if defined(__sun)
5 kx # include <locale.h>
5 kx #endif
5 kx
5 kx /* Many header files from the libstdc++ coming with g++ 3.3 or newer include
5 kx <libintl.h>, which chokes if dcgettext is defined as a macro. So include
5 kx it now, to make later inclusions of <libintl.h> a NOP. */
5 kx #if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3)
5 kx # include <cstdlib>
5 kx # if (__GLIBC__ >= 2 && !defined __UCLIBC__) || _GLIBCXX_HAVE_LIBINTL_H
5 kx # include <libintl.h>
5 kx # endif
5 kx #endif
5 kx
5 kx /* Disabled NLS.
5 kx The casts to 'const char *' serve the purpose of producing warnings
5 kx for invalid uses of the value returned from these functions.
5 kx On pre-ANSI systems without 'const', the config.h file is supposed to
5 kx contain "#define const". */
5 kx # undef gettext
5 kx # define gettext(Msgid) ((const char *) (Msgid))
5 kx # undef dgettext
5 kx # define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid))
5 kx # undef dcgettext
5 kx # define dcgettext(Domainname, Msgid, Category) \
5 kx ((void) (Category), dgettext (Domainname, Msgid))
5 kx # undef ngettext
5 kx # define ngettext(Msgid1, Msgid2, N) \
5 kx ((N) == 1 \
5 kx ? ((void) (Msgid2), (const char *) (Msgid1)) \
5 kx : ((void) (Msgid1), (const char *) (Msgid2)))
5 kx # undef dngettext
5 kx # define dngettext(Domainname, Msgid1, Msgid2, N) \
5 kx ((void) (Domainname), ngettext (Msgid1, Msgid2, N))
5 kx # undef dcngettext
5 kx # define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
5 kx ((void) (Category), dngettext (Domainname, Msgid1, Msgid2, N))
5 kx # undef textdomain
5 kx # define textdomain(Domainname) ((const char *) (Domainname))
5 kx # undef bindtextdomain
5 kx # define bindtextdomain(Domainname, Dirname) \
5 kx ((void) (Domainname), (const char *) (Dirname))
5 kx # undef bind_textdomain_codeset
5 kx # define bind_textdomain_codeset(Domainname, Codeset) \
5 kx ((void) (Domainname), (const char *) (Codeset))
5 kx
5 kx #endif
5 kx
5 kx /* Prefer gnulib's setlocale override over libintl's setlocale override. */
5 kx #ifdef GNULIB_defined_setlocale
5 kx # undef setlocale
5 kx # define setlocale rpl_setlocale
5 kx #endif
5 kx
5 kx /* A pseudo function call that serves as a marker for the automated
5 kx extraction of messages, but does not call gettext(). The run-time
5 kx translation is done at a different place in the code.
5 kx The argument, String, should be a literal string. Concatenated strings
5 kx and other string expressions won't work.
5 kx The macro's expansion is not parenthesized, so that it is suitable as
5 kx initializer for static 'char[]' or 'const char[]' variables. */
5 kx #define gettext_noop(String) String
5 kx
5 kx /* The separator between msgctxt and msgid in a .mo file. */
5 kx #define GETTEXT_CONTEXT_GLUE "\004"
5 kx
5 kx /* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a
5 kx MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be
5 kx short and rarely need to change.
5 kx The letter 'p' stands for 'particular' or 'special'. */
5 kx #ifdef DEFAULT_TEXT_DOMAIN
5 kx # define pgettext(Msgctxt, Msgid) \
5 kx pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
5 kx #else
5 kx # define pgettext(Msgctxt, Msgid) \
5 kx pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
5 kx #endif
5 kx #define dpgettext(Domainname, Msgctxt, Msgid) \
5 kx pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
5 kx #define dcpgettext(Domainname, Msgctxt, Msgid, Category) \
5 kx pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category)
5 kx #ifdef DEFAULT_TEXT_DOMAIN
5 kx # define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
5 kx npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
5 kx #else
5 kx # define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
5 kx npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
5 kx #endif
5 kx #define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
5 kx npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
5 kx #define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \
5 kx npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category)
5 kx
5 kx #ifdef __GNUC__
5 kx __inline
5 kx #else
5 kx #ifdef __cplusplus
5 kx inline
5 kx #endif
5 kx #endif
5 kx static const char *
5 kx pgettext_aux (const char *domain,
5 kx const char *msg_ctxt_id, const char *msgid,
5 kx int category)
5 kx {
5 kx const char *translation = dcgettext (domain, msg_ctxt_id, category);
5 kx if (translation == msg_ctxt_id)
5 kx return msgid;
5 kx else
5 kx return translation;
5 kx }
5 kx
5 kx #ifdef __GNUC__
5 kx __inline
5 kx #else
5 kx #ifdef __cplusplus
5 kx inline
5 kx #endif
5 kx #endif
5 kx static const char *
5 kx npgettext_aux (const char *domain,
5 kx const char *msg_ctxt_id, const char *msgid,
5 kx const char *msgid_plural, unsigned long int n,
5 kx int category)
5 kx {
5 kx const char *translation =
5 kx dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
5 kx if (translation == msg_ctxt_id || translation == msgid_plural)
5 kx return (n == 1 ? msgid : msgid_plural);
5 kx else
5 kx return translation;
5 kx }
5 kx
5 kx /* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID
5 kx can be arbitrary expressions. But for string literals these macros are
5 kx less efficient than those above. */
5 kx
5 kx #include <string.h>
5 kx
5 kx #if (((__GNUC__ >= 3 || __GNUG__ >= 2) && !defined __STRICT_ANSI__) \
5 kx /* || __STDC_VERSION__ >= 199901L */ )
5 kx # define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 1
5 kx #else
5 kx # define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 0
5 kx #endif
5 kx
5 kx #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
5 kx #include <stdlib.h>
5 kx #endif
5 kx
5 kx #define pgettext_expr(Msgctxt, Msgid) \
5 kx dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES)
5 kx #define dpgettext_expr(Domainname, Msgctxt, Msgid) \
5 kx dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
5 kx
5 kx #ifdef __GNUC__
5 kx __inline
5 kx #else
5 kx #ifdef __cplusplus
5 kx inline
5 kx #endif
5 kx #endif
5 kx static const char *
5 kx dcpgettext_expr (const char *domain,
5 kx const char *msgctxt, const char *msgid,
5 kx int category)
5 kx {
5 kx size_t msgctxt_len = strlen (msgctxt) + 1;
5 kx size_t msgid_len = strlen (msgid) + 1;
5 kx const char *translation;
5 kx #if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
5 kx char msg_ctxt_id[msgctxt_len + msgid_len];
5 kx #else
5 kx char buf[1024];
5 kx char *msg_ctxt_id =
5 kx (msgctxt_len + msgid_len <= sizeof (buf)
5 kx ? buf
5 kx : (char *) malloc (msgctxt_len + msgid_len));
5 kx if (msg_ctxt_id != NULL)
5 kx #endif
5 kx {
5 kx int found_translation;
5 kx memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
5 kx msg_ctxt_id[msgctxt_len - 1] = '\004';
5 kx memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
5 kx translation = dcgettext (domain, msg_ctxt_id, category);
5 kx found_translation = (translation != msg_ctxt_id);
5 kx #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
5 kx if (msg_ctxt_id != buf)
5 kx free (msg_ctxt_id);
5 kx #endif
5 kx if (found_translation)
5 kx return translation;
5 kx }
5 kx return msgid;
5 kx }
5 kx
5 kx #define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \
5 kx dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
5 kx #define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
5 kx dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
5 kx
5 kx #ifdef __GNUC__
5 kx __inline
5 kx #else
5 kx #ifdef __cplusplus
5 kx inline
5 kx #endif
5 kx #endif
5 kx static const char *
5 kx dcnpgettext_expr (const char *domain,
5 kx const char *msgctxt, const char *msgid,
5 kx const char *msgid_plural, unsigned long int n,
5 kx int category)
5 kx {
5 kx size_t msgctxt_len = strlen (msgctxt) + 1;
5 kx size_t msgid_len = strlen (msgid) + 1;
5 kx const char *translation;
5 kx #if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
5 kx char msg_ctxt_id[msgctxt_len + msgid_len];
5 kx #else
5 kx char buf[1024];
5 kx char *msg_ctxt_id =
5 kx (msgctxt_len + msgid_len <= sizeof (buf)
5 kx ? buf
5 kx : (char *) malloc (msgctxt_len + msgid_len));
5 kx if (msg_ctxt_id != NULL)
5 kx #endif
5 kx {
5 kx int found_translation;
5 kx memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
5 kx msg_ctxt_id[msgctxt_len - 1] = '\004';
5 kx memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
5 kx translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
5 kx found_translation = !(translation == msg_ctxt_id || translation == msgid_plural);
5 kx #if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
5 kx if (msg_ctxt_id != buf)
5 kx free (msg_ctxt_id);
5 kx #endif
5 kx if (found_translation)
5 kx return translation;
5 kx }
5 kx return (n == 1 ? msgid : msgid_plural);
5 kx }
5 kx
5 kx #endif /* _LIBGETTEXT_H */