]>
Commit | Line | Data |
---|---|---|
11d62145 JN |
1 | # This shell library is Git's interface to gettext.sh. See po/README |
2 | # for usage instructions. | |
e00cf070 ÆAB |
3 | # |
4 | # Copyright (c) 2010 Ævar Arnfjörð Bjarmason | |
5 | # | |
5e9637c6 ÆAB |
6 | |
7 | # Export the TEXTDOMAIN* data that we need for Git | |
8 | TEXTDOMAIN=git | |
9 | export TEXTDOMAIN | |
10 | if test -z "$GIT_TEXTDOMAINDIR" | |
11 | then | |
12 | TEXTDOMAINDIR="@@LOCALEDIR@@" | |
13 | else | |
14 | TEXTDOMAINDIR="$GIT_TEXTDOMAINDIR" | |
15 | fi | |
16 | export TEXTDOMAINDIR | |
e00cf070 | 17 | |
42f16113 JH |
18 | # First decide what scheme to use... |
19 | GIT_INTERNAL_GETTEXT_SH_SCHEME=fallthrough | |
6cdccfce | 20 | if test -n "$GIT_TEST_GETTEXT_POISON" |
37380315 JK |
21 | then |
22 | GIT_INTERNAL_GETTEXT_SH_SCHEME=poison | |
23 | elif test -n "@@USE_GETTEXT_SCHEME@@" | |
ad17ea73 AR |
24 | then |
25 | GIT_INTERNAL_GETTEXT_SH_SCHEME="@@USE_GETTEXT_SCHEME@@" | |
ac06116d | 26 | elif test -n "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS" |
42f16113 JH |
27 | then |
28 | : no probing necessary | |
42f16113 JH |
29 | elif type gettext.sh >/dev/null 2>&1 |
30 | then | |
31 | # GNU libintl's gettext.sh | |
32 | GIT_INTERNAL_GETTEXT_SH_SCHEME=gnu | |
33 | elif test "$(gettext -h 2>&1)" = "-h" | |
34 | then | |
35 | # gettext binary exists but no gettext.sh. likely to be a gettext | |
36 | # binary on a Solaris or something that is not GNU libintl and | |
37 | # lack eval_gettext. | |
38 | GIT_INTERNAL_GETTEXT_SH_SCHEME=gettext_without_eval_gettext | |
39 | fi | |
40 | export GIT_INTERNAL_GETTEXT_SH_SCHEME | |
5e9637c6 | 41 | |
42f16113 JH |
42 | # ... and then follow that decision. |
43 | case "$GIT_INTERNAL_GETTEXT_SH_SCHEME" in | |
44 | gnu) | |
45 | # Use libintl's gettext.sh, or fall back to English if we can't. | |
46 | . gettext.sh | |
47 | ;; | |
48 | gettext_without_eval_gettext) | |
49 | # Solaris has a gettext(1) but no eval_gettext(1) | |
50 | eval_gettext () { | |
51 | gettext "$1" | ( | |
52 | export PATH $(git sh-i18n--envsubst --variables "$1"); | |
53 | git sh-i18n--envsubst "$1" | |
54 | ) | |
55 | } | |
b8fc9e43 VA |
56 | |
57 | eval_ngettext () { | |
58 | ngettext "$1" "$2" "$3" | ( | |
59 | export PATH $(git sh-i18n--envsubst --variables "$2"); | |
60 | git sh-i18n--envsubst "$2" | |
61 | ) | |
62 | } | |
42f16113 JH |
63 | ;; |
64 | poison) | |
65 | # Emit garbage so that tests that incorrectly rely on translatable | |
66 | # strings will fail. | |
64a42951 ÆAB |
67 | gettext () { |
68 | printf "%s" "# GETTEXT POISON #" | |
69 | } | |
70 | ||
71 | eval_gettext () { | |
72 | printf "%s" "# GETTEXT POISON #" | |
73 | } | |
b8fc9e43 VA |
74 | |
75 | eval_ngettext () { | |
76 | printf "%s" "# GETTEXT POISON #" | |
77 | } | |
42f16113 JH |
78 | ;; |
79 | *) | |
80 | gettext () { | |
81 | printf "%s" "$1" | |
82 | } | |
83 | ||
84 | eval_gettext () { | |
85 | printf "%s" "$1" | ( | |
86 | export PATH $(git sh-i18n--envsubst --variables "$1"); | |
87 | git sh-i18n--envsubst "$1" | |
88 | ) | |
89 | } | |
b8fc9e43 VA |
90 | |
91 | eval_ngettext () { | |
92 | (test "$3" = 1 && printf "%s" "$1" || printf "%s" "$2") | ( | |
93 | export PATH $(git sh-i18n--envsubst --variables "$2"); | |
94 | git sh-i18n--envsubst "$2" | |
95 | ) | |
96 | } | |
42f16113 JH |
97 | ;; |
98 | esac | |
e00cf070 | 99 | |
5e9637c6 ÆAB |
100 | # Git-specific wrapper functions |
101 | gettextln () { | |
102 | gettext "$1" | |
103 | echo | |
104 | } | |
105 | ||
106 | eval_gettextln () { | |
107 | eval_gettext "$1" | |
108 | echo | |
109 | } |