gettext.h 2.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/*
 * Copyright (c) 2010-2011 Ævar Arnfjörð Bjarmason
 *
 * This is a skeleton no-op implementation of gettext for Git.
 * You can replace it with something that uses libintl.h and wraps
 * gettext() to try out the translations.
 */

#ifndef GETTEXT_H
#define GETTEXT_H

12 13
#if defined(_) || defined(Q_)
#error "namespace conflict: '_' or 'Q_' is pre-defined?"
14 15
#endif

16 17 18 19 20 21 22 23 24 25 26 27 28
#ifndef NO_GETTEXT
#	include <libintl.h>
#else
#	ifdef gettext
#		undef gettext
#	endif
#	define gettext(s) (s)
#	ifdef ngettext
#		undef ngettext
#	endif
#	define ngettext(s, p, n) ((n == 1) ? (s) : (p))
#endif

29 30
#define FORMAT_PRESERVING(n) __attribute__((format_arg(n)))

31 32
#ifndef NO_GETTEXT
extern void git_setup_gettext(void);
33
extern int gettext_width(const char *s);
34 35 36 37
#else
static inline void git_setup_gettext(void)
{
}
38 39 40 41
static inline int gettext_width(const char *s)
{
	return strlen(s);
}
42 43
#endif

44
#ifdef GETTEXT_POISON
45
extern int use_gettext_poison(void);
46 47 48 49
#else
#define use_gettext_poison() 0
#endif

50 51
static inline FORMAT_PRESERVING(1) const char *_(const char *msgid)
{
52 53
	if (!*msgid)
		return "";
54
	return use_gettext_poison() ? "# GETTEXT POISON #" : gettext(msgid);
55 56
}

57 58 59 60 61
static inline FORMAT_PRESERVING(1) FORMAT_PRESERVING(2)
const char *Q_(const char *msgid, const char *plu, unsigned long n)
{
	if (use_gettext_poison())
		return "# GETTEXT POISON #";
62
	return ngettext(msgid, plu, n);
63 64
}

65
/* Mark msgid for translation but do not translate it. */
66
#if !USE_PARENS_AROUND_GETTEXT_N
67
#define N_(msgid) msgid
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
#else
/*
 * Strictly speaking, this will lead to invalid C when
 * used this way:
 *	static const char s[] = N_("FOO");
 * which will expand to
 *	static const char s[] = ("FOO");
 * and in valid C, the initializer on the right hand side must
 * be without the parentheses.  But many compilers do accept it
 * as a language extension and it will allow us to catch mistakes
 * like:
 *	static const char *msgs[] = {
 *		N_("one")
 *		N_("two"),
 *		N_("three"),
 *		NULL
 *	};
 * (notice the missing comma on one of the lines) by forcing
 * a compilation error, because parenthesised ("one") ("two")
 * will not get silently turned into ("onetwo").
 */
#define N_(msgid) (msgid)
#endif
91

92
const char *get_preferred_languages(void);
Duy Nguyen's avatar
Duy Nguyen committed
93
extern int is_utf8_locale(void);
94

95
#endif