]> git.ipfire.org Git - thirdparty/git.git/blame - gettext.h
tests: remove support for GIT_TEST_GETTEXT_POISON
[thirdparty/git.git] / gettext.h
CommitLineData
65784830
ÆAB
1/*
2 * Copyright (c) 2010-2011 Ævar Arnfjörð Bjarmason
3 *
4 * This is a skeleton no-op implementation of gettext for Git.
5 * You can replace it with something that uses libintl.h and wraps
6 * gettext() to try out the translations.
7 */
8
9#ifndef GETTEXT_H
10#define GETTEXT_H
11
0c9ea33b
JN
12#if defined(_) || defined(Q_)
13#error "namespace conflict: '_' or 'Q_' is pre-defined?"
65784830
ÆAB
14#endif
15
5e9637c6
ÆAB
16#ifndef NO_GETTEXT
17# include <libintl.h>
18#else
19# ifdef gettext
20# undef gettext
21# endif
22# define gettext(s) (s)
23# ifdef ngettext
24# undef ngettext
25# endif
26# define ngettext(s, p, n) ((n == 1) ? (s) : (p))
27#endif
28
65784830
ÆAB
29#define FORMAT_PRESERVING(n) __attribute__((format_arg(n)))
30
5e9637c6 31#ifndef NO_GETTEXT
55454427
DL
32void git_setup_gettext(void);
33int gettext_width(const char *s);
5e9637c6
ÆAB
34#else
35static inline void git_setup_gettext(void)
36{
37}
754395d3
NTND
38static inline int gettext_width(const char *s)
39{
40 return strlen(s);
41}
5e9637c6
ÆAB
42#endif
43
65784830
ÆAB
44static inline FORMAT_PRESERVING(1) const char *_(const char *msgid)
45{
0c3a433f
TR
46 if (!*msgid)
47 return "";
d162b25f 48 return gettext(msgid);
65784830
ÆAB
49}
50
0c9ea33b
JN
51static inline FORMAT_PRESERVING(1) FORMAT_PRESERVING(2)
52const char *Q_(const char *msgid, const char *plu, unsigned long n)
53{
5e9637c6 54 return ngettext(msgid, plu, n);
0c9ea33b
JN
55}
56
65784830 57/* Mark msgid for translation but do not translate it. */
290c8e7a 58#if !USE_PARENS_AROUND_GETTEXT_N
642f85fa 59#define N_(msgid) msgid
290c8e7a
KM
60#else
61/*
62 * Strictly speaking, this will lead to invalid C when
63 * used this way:
64 * static const char s[] = N_("FOO");
65 * which will expand to
66 * static const char s[] = ("FOO");
67 * and in valid C, the initializer on the right hand side must
68 * be without the parentheses. But many compilers do accept it
69 * as a language extension and it will allow us to catch mistakes
70 * like:
71 * static const char *msgs[] = {
72 * N_("one")
73 * N_("two"),
74 * N_("three"),
75 * NULL
76 * };
77 * (notice the missing comma on one of the lines) by forcing
78 * a compilation error, because parenthesised ("one") ("two")
79 * will not get silently turned into ("onetwo").
80 */
81#define N_(msgid) (msgid)
82#endif
65784830 83
93f7d910 84const char *get_preferred_languages(void);
55454427 85int is_utf8_locale(void);
93f7d910 86
65784830 87#endif