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