Ævar Arnfjörð Bjarmason | 6578483 | 2011-02-22 23:41:20 +0000 | [diff] [blame] | 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 | |
Jonathan Nieder | 0c9ea33 | 2011-03-09 21:17:58 -0600 | [diff] [blame] | 12 | #if defined(_) || defined(Q_) |
| 13 | #error "namespace conflict: '_' or 'Q_' is pre-defined?" |
Ævar Arnfjörð Bjarmason | 6578483 | 2011-02-22 23:41:20 +0000 | [diff] [blame] | 14 | #endif |
| 15 | |
Ævar Arnfjörð Bjarmason | 5e9637c | 2011-11-18 00:14:42 +0100 | [diff] [blame] | 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 | |
Ævar Arnfjörð Bjarmason | 6578483 | 2011-02-22 23:41:20 +0000 | [diff] [blame] | 29 | #define FORMAT_PRESERVING(n) __attribute__((format_arg(n))) |
| 30 | |
Ævar Arnfjörð Bjarmason | 5e9637c | 2011-11-18 00:14:42 +0100 | [diff] [blame] | 31 | #ifndef NO_GETTEXT |
| 32 | extern void git_setup_gettext(void); |
Nguyễn Thái Ngọc Duy | 754395d | 2012-09-04 17:39:35 +0700 | [diff] [blame] | 33 | extern int gettext_width(const char *s); |
Ævar Arnfjörð Bjarmason | 5e9637c | 2011-11-18 00:14:42 +0100 | [diff] [blame] | 34 | #else |
| 35 | static inline void git_setup_gettext(void) |
| 36 | { |
| 37 | } |
Nguyễn Thái Ngọc Duy | 754395d | 2012-09-04 17:39:35 +0700 | [diff] [blame] | 38 | static inline int gettext_width(const char *s) |
| 39 | { |
| 40 | return strlen(s); |
| 41 | } |
Ævar Arnfjörð Bjarmason | 5e9637c | 2011-11-18 00:14:42 +0100 | [diff] [blame] | 42 | #endif |
| 43 | |
Ævar Arnfjörð Bjarmason | bb946bb | 2011-02-22 23:41:21 +0000 | [diff] [blame] | 44 | #ifdef GETTEXT_POISON |
Jonathan Nieder | 3095522 | 2011-02-22 23:41:22 +0000 | [diff] [blame] | 45 | extern int use_gettext_poison(void); |
Ævar Arnfjörð Bjarmason | bb946bb | 2011-02-22 23:41:21 +0000 | [diff] [blame] | 46 | #else |
| 47 | #define use_gettext_poison() 0 |
| 48 | #endif |
| 49 | |
Ævar Arnfjörð Bjarmason | 6578483 | 2011-02-22 23:41:20 +0000 | [diff] [blame] | 50 | static inline FORMAT_PRESERVING(1) const char *_(const char *msgid) |
| 51 | { |
Thomas Rast | 0c3a433 | 2012-08-20 20:24:56 +0200 | [diff] [blame] | 52 | if (!*msgid) |
| 53 | return ""; |
Ævar Arnfjörð Bjarmason | 5e9637c | 2011-11-18 00:14:42 +0100 | [diff] [blame] | 54 | return use_gettext_poison() ? "# GETTEXT POISON #" : gettext(msgid); |
Ævar Arnfjörð Bjarmason | 6578483 | 2011-02-22 23:41:20 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Jonathan Nieder | 0c9ea33 | 2011-03-09 21:17:58 -0600 | [diff] [blame] | 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 #"; |
Ævar Arnfjörð Bjarmason | 5e9637c | 2011-11-18 00:14:42 +0100 | [diff] [blame] | 62 | return ngettext(msgid, plu, n); |
Jonathan Nieder | 0c9ea33 | 2011-03-09 21:17:58 -0600 | [diff] [blame] | 63 | } |
| 64 | |
Ævar Arnfjörð Bjarmason | 6578483 | 2011-02-22 23:41:20 +0000 | [diff] [blame] | 65 | /* Mark msgid for translation but do not translate it. */ |
Ramsay Jones | 642f85f | 2011-04-07 19:41:48 +0100 | [diff] [blame] | 66 | #define N_(msgid) msgid |
Ævar Arnfjörð Bjarmason | 6578483 | 2011-02-22 23:41:20 +0000 | [diff] [blame] | 67 | |
| 68 | #endif |