Merge branch 'km/submodule-doc-use-sm-path' into maint
[git.git] / git-sh-i18n.sh
blob8eef60b43fd47a4a679c5c77ae2f9c5ab5907951
1 # This shell library is Git's interface to gettext.sh. See po/README
2 # for usage instructions.
4 # Copyright (c) 2010 Ævar Arnfjörð Bjarmason
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"
16 export TEXTDOMAINDIR
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
42 export GIT_INTERNAL_GETTEXT_SH_SCHEME
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
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"
59 eval_ngettext () {
60 ngettext "$1" "$2" "$3" | (
61 export PATH $(git sh-i18n--envsubst --variables "$2");
62 git sh-i18n--envsubst "$2"
66 poison)
67 # Emit garbage so that tests that incorrectly rely on translatable
68 # strings will fail.
69 gettext () {
70 printf "%s" "# GETTEXT POISON #"
73 eval_gettext () {
74 printf "%s" "# GETTEXT POISON #"
77 eval_ngettext () {
78 printf "%s" "# GETTEXT POISON #"
82 gettext () {
83 printf "%s" "$1"
86 eval_gettext () {
87 printf "%s" "$1" | (
88 export PATH $(git sh-i18n--envsubst --variables "$1");
89 git sh-i18n--envsubst "$1"
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"
100 esac
102 # Git-specific wrapper functions
103 gettextln () {
104 gettext "$1"
105 echo
108 eval_gettextln () {
109 eval_gettext "$1"
110 echo