]>
Commit | Line | Data |
---|---|---|
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 ÆAB |
31 | #ifndef NO_GETTEXT |
32 | extern void git_setup_gettext(void); | |
754395d3 | 33 | extern int gettext_width(const char *s); |
5e9637c6 ÆAB |
34 | #else |
35 | static inline void git_setup_gettext(void) | |
36 | { | |
37 | } | |
754395d3 NTND |
38 | static inline int gettext_width(const char *s) |
39 | { | |
40 | return strlen(s); | |
41 | } | |
5e9637c6 ÆAB |
42 | #endif |
43 | ||
bb946bba | 44 | #ifdef GETTEXT_POISON |
30955229 | 45 | extern int use_gettext_poison(void); |
bb946bba ÆAB |
46 | #else |
47 | #define use_gettext_poison() 0 | |
48 | #endif | |
49 | ||
65784830 ÆAB |
50 | static inline FORMAT_PRESERVING(1) const char *_(const char *msgid) |
51 | { | |
0c3a433f TR |
52 | if (!*msgid) |
53 | return ""; | |
5e9637c6 | 54 | return use_gettext_poison() ? "# GETTEXT POISON #" : gettext(msgid); |
65784830 ÆAB |
55 | } |
56 | ||
0c9ea33b JN |
57 | static inline FORMAT_PRESERVING(1) FORMAT_PRESERVING(2) |
58 | const char *Q_(const char *msgid, const char *plu, unsigned long n) | |
59 | { | |
60 | if (use_gettext_poison()) | |
61 | return "# GETTEXT POISON #"; | |
5e9637c6 | 62 | return ngettext(msgid, plu, n); |
0c9ea33b JN |
63 | } |
64 | ||
65784830 | 65 | /* Mark msgid for translation but do not translate it. */ |
642f85fa | 66 | #define N_(msgid) msgid |
65784830 ÆAB |
67 | |
68 | #endif |