Git 2.33.8
[alt-git.git] / gettext.h
blob5b42e458e5b9807857344bb92d45ecda6ddaa520
1 /*
2 * Copyright (c) 2010-2011 Ævar Arnfjörð Bjarmason
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 */
9 #ifndef GETTEXT_H
10 #define GETTEXT_H
12 #if defined(_) || defined(Q_)
13 #error "namespace conflict: '_' or 'Q_' is pre-defined?"
14 #endif
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
29 #define FORMAT_PRESERVING(n) __attribute__((format_arg(n)))
31 #ifndef NO_GETTEXT
32 extern int git_gettext_enabled;
33 void git_setup_gettext(void);
34 int gettext_width(const char *s);
35 #else
36 #define git_gettext_enabled (0)
37 static inline void git_setup_gettext(void)
40 static inline int gettext_width(const char *s)
42 return strlen(s);
44 #endif
46 static inline FORMAT_PRESERVING(1) const char *_(const char *msgid)
48 if (!*msgid)
49 return "";
50 if (!git_gettext_enabled)
51 return msgid;
52 return gettext(msgid);
55 static inline FORMAT_PRESERVING(1) FORMAT_PRESERVING(2)
56 const char *Q_(const char *msgid, const char *plu, unsigned long n)
58 if (!git_gettext_enabled)
59 return n == 1 ? msgid : plu;
60 return ngettext(msgid, plu, n);
63 /* Mark msgid for translation but do not translate it. */
64 #if !USE_PARENS_AROUND_GETTEXT_N
65 #define N_(msgid) msgid
66 #else
68 * Strictly speaking, this will lead to invalid C when
69 * used this way:
70 * static const char s[] = N_("FOO");
71 * which will expand to
72 * static const char s[] = ("FOO");
73 * and in valid C, the initializer on the right hand side must
74 * be without the parentheses. But many compilers do accept it
75 * as a language extension and it will allow us to catch mistakes
76 * like:
77 * static const char *msgs[] = {
78 * N_("one")
79 * N_("two"),
80 * N_("three"),
81 * NULL
82 * };
83 * (notice the missing comma on one of the lines) by forcing
84 * a compilation error, because parenthesised ("one") ("two")
85 * will not get silently turned into ("onetwo").
87 #define N_(msgid) (msgid)
88 #endif
90 const char *get_preferred_languages(void);
91 int is_utf8_locale(void);
93 #endif