Merge branch 'dt/remote-helper-doc-re-lock-option'
[git/git.git] / git-sh-i18n.sh
1 # This shell library is Git's interface to gettext.sh. See po/README
2 # for usage instructions.
3 #
4 # Copyright (c) 2010 Ævar Arnfjörð Bjarmason
5 #
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
17
18 # First decide what scheme to use...
19 GIT_INTERNAL_GETTEXT_SH_SCHEME=fallthrough
20 if test -n "$GIT_TEST_GETTEXT_POISON" &&
21 git env--helper --type=bool --default=0 --exit-code \
22 GIT_TEST_GETTEXT_POISON
23 then
24 GIT_INTERNAL_GETTEXT_SH_SCHEME=poison
25 elif test -n "@@USE_GETTEXT_SCHEME@@"
26 then
27 GIT_INTERNAL_GETTEXT_SH_SCHEME="@@USE_GETTEXT_SCHEME@@"
28 elif test -n "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS"
29 then
30 : no probing necessary
31 elif type gettext.sh >/dev/null 2>&1
32 then
33 # GNU libintl's gettext.sh
34 GIT_INTERNAL_GETTEXT_SH_SCHEME=gnu
35 elif test "$(gettext -h 2>&1)" = "-h"
36 then
37 # gettext binary exists but no gettext.sh. likely to be a gettext
38 # binary on a Solaris or something that is not GNU libintl and
39 # lack eval_gettext.
40 GIT_INTERNAL_GETTEXT_SH_SCHEME=gettext_without_eval_gettext
41 fi
42 export GIT_INTERNAL_GETTEXT_SH_SCHEME
43
44 # ... and then follow that decision.
45 case "$GIT_INTERNAL_GETTEXT_SH_SCHEME" in
46 gnu)
47 # Use libintl's gettext.sh, or fall back to English if we can't.
48 . gettext.sh
49 ;;
50 gettext_without_eval_gettext)
51 # Solaris has a gettext(1) but no eval_gettext(1)
52 eval_gettext () {
53 gettext "$1" | (
54 export PATH $(git sh-i18n--envsubst --variables "$1");
55 git sh-i18n--envsubst "$1"
56 )
57 }
58
59 eval_ngettext () {
60 ngettext "$1" "$2" "$3" | (
61 export PATH $(git sh-i18n--envsubst --variables "$2");
62 git sh-i18n--envsubst "$2"
63 )
64 }
65 ;;
66 poison)
67 # Emit garbage so that tests that incorrectly rely on translatable
68 # strings will fail.
69 gettext () {
70 printf "%s" "# GETTEXT POISON #"
71 }
72
73 eval_gettext () {
74 printf "%s" "# GETTEXT POISON #"
75 }
76
77 eval_ngettext () {
78 printf "%s" "# GETTEXT POISON #"
79 }
80 ;;
81 *)
82 gettext () {
83 printf "%s" "$1"
84 }
85
86 eval_gettext () {
87 printf "%s" "$1" | (
88 export PATH $(git sh-i18n--envsubst --variables "$1");
89 git sh-i18n--envsubst "$1"
90 )
91 }
92
93 eval_ngettext () {
94 (test "$3" = 1 && printf "%s" "$1" || printf "%s" "$2") | (
95 export PATH $(git sh-i18n--envsubst --variables "$2");
96 git sh-i18n--envsubst "$2"
97 )
98 }
99 ;;
100 esac
101
102 # Git-specific wrapper functions
103 gettextln () {
104 gettext "$1"
105 echo
106 }
107
108 eval_gettextln () {
109 eval_gettext "$1"
110 echo
111 }