Æ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 |
Johannes Schindelin | c4137be | 2023-02-22 12:40:55 +0100 | [diff] [blame] | 32 | extern int git_gettext_enabled; |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 33 | void git_setup_gettext(void); |
| 34 | int gettext_width(const char *s); |
Ævar Arnfjörð Bjarmason | 5e9637c | 2011-11-18 00:14:42 +0100 | [diff] [blame] | 35 | #else |
Johannes Schindelin | c4137be | 2023-02-22 12:40:55 +0100 | [diff] [blame] | 36 | #define git_gettext_enabled (0) |
Ævar Arnfjörð Bjarmason | 5e9637c | 2011-11-18 00:14:42 +0100 | [diff] [blame] | 37 | static inline void git_setup_gettext(void) |
| 38 | { |
| 39 | } |
Nguyễn Thái Ngọc Duy | 754395d | 2012-09-04 17:39:35 +0700 | [diff] [blame] | 40 | static inline int gettext_width(const char *s) |
| 41 | { |
| 42 | return strlen(s); |
| 43 | } |
Ævar Arnfjörð Bjarmason | 5e9637c | 2011-11-18 00:14:42 +0100 | [diff] [blame] | 44 | #endif |
| 45 | |
Ævar Arnfjörð Bjarmason | 6578483 | 2011-02-22 23:41:20 +0000 | [diff] [blame] | 46 | static inline FORMAT_PRESERVING(1) const char *_(const char *msgid) |
| 47 | { |
Thomas Rast | 0c3a433 | 2012-08-20 20:24:56 +0200 | [diff] [blame] | 48 | if (!*msgid) |
| 49 | return ""; |
Johannes Schindelin | b524e89 | 2023-03-11 17:54:13 +0100 | [diff] [blame] | 50 | if (!git_gettext_enabled) |
| 51 | return msgid; |
Ævar Arnfjörð Bjarmason | d162b25 | 2021-01-20 19:27:58 +0100 | [diff] [blame] | 52 | return gettext(msgid); |
Ævar Arnfjörð Bjarmason | 6578483 | 2011-02-22 23:41:20 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Jonathan Nieder | 0c9ea33 | 2011-03-09 21:17:58 -0600 | [diff] [blame] | 55 | static inline FORMAT_PRESERVING(1) FORMAT_PRESERVING(2) |
| 56 | const char *Q_(const char *msgid, const char *plu, unsigned long n) |
| 57 | { |
Johannes Schindelin | c4137be | 2023-02-22 12:40:55 +0100 | [diff] [blame] | 58 | if (!git_gettext_enabled) |
| 59 | return n == 1 ? msgid : plu; |
Ævar Arnfjörð Bjarmason | 5e9637c | 2011-11-18 00:14:42 +0100 | [diff] [blame] | 60 | return ngettext(msgid, plu, n); |
Jonathan Nieder | 0c9ea33 | 2011-03-09 21:17:58 -0600 | [diff] [blame] | 61 | } |
| 62 | |
Ævar Arnfjörð Bjarmason | 6578483 | 2011-02-22 23:41:20 +0000 | [diff] [blame] | 63 | /* Mark msgid for translation but do not translate it. */ |
Ramsay Jones | 642f85f | 2011-04-07 19:41:48 +0100 | [diff] [blame] | 64 | #define N_(msgid) msgid |
Ævar Arnfjörð Bjarmason | 6578483 | 2011-02-22 23:41:20 +0000 | [diff] [blame] | 65 | |
Jeff King | 93f7d91 | 2015-02-25 22:04:16 -0500 | [diff] [blame] | 66 | const char *get_preferred_languages(void); |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 67 | int is_utf8_locale(void); |
Jeff King | 93f7d91 | 2015-02-25 22:04:16 -0500 | [diff] [blame] | 68 | |
Ævar Arnfjörð Bjarmason | 6578483 | 2011-02-22 23:41:20 +0000 | [diff] [blame] | 69 | #endif |