Skip to content

Commit 42f1611

Browse files
committed
git-sh-i18n: restructure the logic to compute gettext.sh scheme
Instead of having a single long and complex chain of commands to decide what to do and carry out the decision, split the code so that we first decide which scheme to use, and in the second section define what exactly is done by the chosen scheme. It makes the code much easier to follow and update. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2dccad3 commit 42f1611

File tree

1 file changed

+50
-53
lines changed

1 file changed

+50
-53
lines changed

git-sh-i18n.sh

Lines changed: 50 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -16,69 +16,66 @@ else
1616
fi
1717
export TEXTDOMAINDIR
1818

19-
if test -z "$GIT_GETTEXT_POISON"
19+
# First decide what scheme to use...
20+
GIT_INTERNAL_GETTEXT_SH_SCHEME=fallthrough
21+
if test -n "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS"
22+
then
23+
: no probing necessary
24+
elif test -n "$GIT_GETTEXT_POISON"
2025
then
21-
if test -z "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS" && type gettext.sh >/dev/null 2>&1
22-
then
23-
# This is GNU libintl's gettext.sh, we don't need to do anything
24-
# else than setting up the environment and loading gettext.sh
25-
GIT_INTERNAL_GETTEXT_SH_SCHEME=gnu
26-
export GIT_INTERNAL_GETTEXT_SH_SCHEME
27-
28-
# Try to use libintl's gettext.sh, or fall back to English if we
29-
# can't.
30-
. gettext.sh
31-
32-
elif test -z "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS" && test "$(gettext -h 2>&1)" = "-h"
33-
then
34-
# We don't have gettext.sh, but there's a gettext binary in our
35-
# path. This is probably Solaris or something like it which has a
36-
# gettext implementation that isn't GNU libintl.
37-
GIT_INTERNAL_GETTEXT_SH_SCHEME=solaris
38-
export GIT_INTERNAL_GETTEXT_SH_SCHEME
39-
40-
# Solaris has a gettext(1) but no eval_gettext(1)
41-
eval_gettext () {
42-
gettext "$1" | (
43-
export PATH $(git sh-i18n--envsubst --variables "$1");
44-
git sh-i18n--envsubst "$1"
45-
)
46-
}
47-
48-
else
49-
# Since gettext.sh isn't available we'll have to define our own
50-
# dummy pass-through functions.
51-
52-
# Tell our tests that we don't have the real gettext.sh
53-
GIT_INTERNAL_GETTEXT_SH_SCHEME=fallthrough
54-
export GIT_INTERNAL_GETTEXT_SH_SCHEME
55-
56-
gettext () {
57-
printf "%s" "$1"
58-
}
59-
60-
eval_gettext () {
61-
printf "%s" "$1" | (
62-
export PATH $(git sh-i18n--envsubst --variables "$1");
63-
git sh-i18n--envsubst "$1"
64-
)
65-
}
66-
fi
67-
else
68-
# Emit garbage under GETTEXT_POISON=YesPlease. Unlike the C tests
69-
# this relies on an environment variable
70-
7126
GIT_INTERNAL_GETTEXT_SH_SCHEME=poison
72-
export GIT_INTERNAL_GETTEXT_SH_SCHEME
27+
elif type gettext.sh >/dev/null 2>&1
28+
then
29+
# GNU libintl's gettext.sh
30+
GIT_INTERNAL_GETTEXT_SH_SCHEME=gnu
31+
elif test "$(gettext -h 2>&1)" = "-h"
32+
then
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
37+
fi
38+
export GIT_INTERNAL_GETTEXT_SH_SCHEME
7339

40+
# ... and then follow that decision.
41+
case "$GIT_INTERNAL_GETTEXT_SH_SCHEME" in
42+
gnu)
43+
# Use libintl's gettext.sh, or fall back to English if we can't.
44+
. gettext.sh
45+
;;
46+
gettext_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+
;;
55+
poison)
56+
# Emit garbage so that tests that incorrectly rely on translatable
57+
# strings will fail.
7458
gettext () {
7559
printf "%s" "# GETTEXT POISON #"
7660
}
7761

7862
eval_gettext () {
7963
printf "%s" "# GETTEXT POISON #"
8064
}
81-
fi
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+
;;
78+
esac
8279

8380
# Git-specific wrapper functions
8481
gettextln () {

0 commit comments

Comments
 (0)