Merge branch 'rs/commit-graph-use-list-count'
[git/git.git] / git-sh-i18n.sh
CommitLineData
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
8TEXTDOMAIN=git
9export TEXTDOMAIN
10if test -z "$GIT_TEXTDOMAINDIR"
11then
12 TEXTDOMAINDIR="@@LOCALEDIR@@"
13else
14 TEXTDOMAINDIR="$GIT_TEXTDOMAINDIR"
15fi
16export TEXTDOMAINDIR
e00cf070 17
42f16113
JH
18# First decide what scheme to use...
19GIT_INTERNAL_GETTEXT_SH_SCHEME=fallthrough
1ff750b1
ÆAB
20if test -n "$GIT_TEST_GETTEXT_POISON" &&
21 git env--helper --type=bool --default=0 --exit-code \
22 GIT_TEST_GETTEXT_POISON
37380315
JK
23then
24 GIT_INTERNAL_GETTEXT_SH_SCHEME=poison
25elif test -n "@@USE_GETTEXT_SCHEME@@"
ad17ea73
AR
26then
27 GIT_INTERNAL_GETTEXT_SH_SCHEME="@@USE_GETTEXT_SCHEME@@"
ac06116d 28elif test -n "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS"
42f16113
JH
29then
30 : no probing necessary
42f16113
JH
31elif type gettext.sh >/dev/null 2>&1
32then
33 # GNU libintl's gettext.sh
34 GIT_INTERNAL_GETTEXT_SH_SCHEME=gnu
35elif test "$(gettext -h 2>&1)" = "-h"
36then
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
41fi
42export GIT_INTERNAL_GETTEXT_SH_SCHEME
5e9637c6 43
42f16113
JH
44# ... and then follow that decision.
45case "$GIT_INTERNAL_GETTEXT_SH_SCHEME" in
46gnu)
47 # Use libintl's gettext.sh, or fall back to English if we can't.
48 . gettext.sh
49 ;;
50gettext_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 }
b8fc9e43
VA
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 }
42f16113
JH
65 ;;
66poison)
67 # Emit garbage so that tests that incorrectly rely on translatable
68 # strings will fail.
64a42951
ÆAB
69 gettext () {
70 printf "%s" "# GETTEXT POISON #"
71 }
72
73 eval_gettext () {
74 printf "%s" "# GETTEXT POISON #"
75 }
b8fc9e43
VA
76
77 eval_ngettext () {
78 printf "%s" "# GETTEXT POISON #"
79 }
42f16113
JH
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 }
b8fc9e43
VA
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 }
42f16113
JH
99 ;;
100esac
e00cf070 101
5e9637c6
ÆAB
102# Git-specific wrapper functions
103gettextln () {
104 gettext "$1"
105 echo
106}
107
108eval_gettextln () {
109 eval_gettext "$1"
110 echo
111}