]> git.ipfire.org Git - thirdparty/git.git/blame - gettext.h
Merge branch 'js/commit-graph-chunk-table-fix'
[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
6cdccfce
ÆAB
31extern int use_gettext_poison(void);
32
5e9637c6
ÆAB
33#ifndef NO_GETTEXT
34extern void git_setup_gettext(void);
754395d3 35extern int gettext_width(const char *s);
5e9637c6
ÆAB
36#else
37static inline void git_setup_gettext(void)
38{
6cdccfce 39 use_gettext_poison(); /* getenv() reentrancy paranoia */
5e9637c6 40}
754395d3
NTND
41static inline int gettext_width(const char *s)
42{
43 return strlen(s);
44}
5e9637c6
ÆAB
45#endif
46
65784830
ÆAB
47static inline FORMAT_PRESERVING(1) const char *_(const char *msgid)
48{
0c3a433f
TR
49 if (!*msgid)
50 return "";
5e9637c6 51 return use_gettext_poison() ? "# GETTEXT POISON #" : gettext(msgid);
65784830
ÆAB
52}
53
0c9ea33b
JN
54static inline FORMAT_PRESERVING(1) FORMAT_PRESERVING(2)
55const char *Q_(const char *msgid, const char *plu, unsigned long n)
56{
57 if (use_gettext_poison())
58 return "# GETTEXT POISON #";
5e9637c6 59 return ngettext(msgid, plu, n);
0c9ea33b
JN
60}
61
65784830 62/* Mark msgid for translation but do not translate it. */
290c8e7a 63#if !USE_PARENS_AROUND_GETTEXT_N
642f85fa 64#define N_(msgid) msgid
290c8e7a
KM
65#else
66/*
67 * Strictly speaking, this will lead to invalid C when
68 * used this way:
69 * static const char s[] = N_("FOO");
70 * which will expand to
71 * static const char s[] = ("FOO");
72 * and in valid C, the initializer on the right hand side must
73 * be without the parentheses. But many compilers do accept it
74 * as a language extension and it will allow us to catch mistakes
75 * like:
76 * static const char *msgs[] = {
77 * N_("one")
78 * N_("two"),
79 * N_("three"),
80 * NULL
81 * };
82 * (notice the missing comma on one of the lines) by forcing
83 * a compilation error, because parenthesised ("one") ("two")
84 * will not get silently turned into ("onetwo").
85 */
86#define N_(msgid) (msgid)
87#endif
65784830 88
93f7d910 89const char *get_preferred_languages(void);
e8c16726 90extern int is_utf8_locale(void);
93f7d910 91
65784830 92#endif