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