1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-07 16:16:28 +02:00
git/git-sh-i18n.sh
Jeff King 3738031581 git-sh-i18n: check GETTEXT_POISON before USE_GETTEXT_SCHEME
Running "make NO_GETTEXT=1 GETTEXT_POISON=1" currently fails
t0205.

While it might seem nonsensical at first glance to both
poison and disable gettext, it's useful to be able to do a
poison test-run on a system that doesn't have gettext at
all. And it works fine for C programs; the problem is only
with the shell code.

The issue is that we check the baked-in USE_GETTEXT_SCHEME
value before GETTEXT_POISON. And when NO_GETTEXT is set, the
Makefile sets USE_GETTEXT_SCHEME to "fallthrough".

So one fix would be to have the Makefile just set
USE_GETTEXT_SCHEME to "poison" if GETTEXT_POISON is set.
But there are two problems with that:

  1. USE_GETTEXT_SCHEME is actually a user-facing knob, so
     conceivably somebody could override it with:

       make USE_GETTEXT_SCHEME=gnu GETTEXT_POISON=1

     which would do the wrong thing (though that's much less
     likely than them having the variable set in their
     config.mak and just overriding GETTEXT_POISON on the
     command-line for a one-off test).

  2. We don't actually bake GETTEXT_POISON in to the shell
     library like we do for the C code. It checks
     $GIT_GETTEXT_POISON at runtime, which is set up by the
     test suite. So it makes sense to put the fix in the
     runtime code, too, which would cover something like:

       GIT_GETTEXT_POISON=foo git foo

     It's not likely that people use the poison code outside
     of running the test suite, but it's easy enough to make
     this case work.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-02-08 10:09:45 -08:00

110 lines
2.3 KiB
Bash

# This shell library is Git's interface to gettext.sh. See po/README
# for usage instructions.
#
# Copyright (c) 2010 Ævar Arnfjörð Bjarmason
#
# Export the TEXTDOMAIN* data that we need for Git
TEXTDOMAIN=git
export TEXTDOMAIN
if test -z "$GIT_TEXTDOMAINDIR"
then
TEXTDOMAINDIR="@@LOCALEDIR@@"
else
TEXTDOMAINDIR="$GIT_TEXTDOMAINDIR"
fi
export TEXTDOMAINDIR
# First decide what scheme to use...
GIT_INTERNAL_GETTEXT_SH_SCHEME=fallthrough
if test -n "$GIT_GETTEXT_POISON"
then
GIT_INTERNAL_GETTEXT_SH_SCHEME=poison
elif test -n "@@USE_GETTEXT_SCHEME@@"
then
GIT_INTERNAL_GETTEXT_SH_SCHEME="@@USE_GETTEXT_SCHEME@@"
elif test -n "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS"
then
: no probing necessary
elif type gettext.sh >/dev/null 2>&1
then
# GNU libintl's gettext.sh
GIT_INTERNAL_GETTEXT_SH_SCHEME=gnu
elif test "$(gettext -h 2>&1)" = "-h"
then
# gettext binary exists but no gettext.sh. likely to be a gettext
# binary on a Solaris or something that is not GNU libintl and
# lack eval_gettext.
GIT_INTERNAL_GETTEXT_SH_SCHEME=gettext_without_eval_gettext
fi
export GIT_INTERNAL_GETTEXT_SH_SCHEME
# ... and then follow that decision.
case "$GIT_INTERNAL_GETTEXT_SH_SCHEME" in
gnu)
# Use libintl's gettext.sh, or fall back to English if we can't.
. gettext.sh
;;
gettext_without_eval_gettext)
# Solaris has a gettext(1) but no eval_gettext(1)
eval_gettext () {
gettext "$1" | (
export PATH $(git sh-i18n--envsubst --variables "$1");
git sh-i18n--envsubst "$1"
)
}
eval_ngettext () {
ngettext "$1" "$2" "$3" | (
export PATH $(git sh-i18n--envsubst --variables "$2");
git sh-i18n--envsubst "$2"
)
}
;;
poison)
# Emit garbage so that tests that incorrectly rely on translatable
# strings will fail.
gettext () {
printf "%s" "# GETTEXT POISON #"
}
eval_gettext () {
printf "%s" "# GETTEXT POISON #"
}
eval_ngettext () {
printf "%s" "# GETTEXT POISON #"
}
;;
*)
gettext () {
printf "%s" "$1"
}
eval_gettext () {
printf "%s" "$1" | (
export PATH $(git sh-i18n--envsubst --variables "$1");
git sh-i18n--envsubst "$1"
)
}
eval_ngettext () {
(test "$3" = 1 && printf "%s" "$1" || printf "%s" "$2") | (
export PATH $(git sh-i18n--envsubst --variables "$2");
git sh-i18n--envsubst "$2"
)
}
;;
esac
# Git-specific wrapper functions
gettextln () {
gettext "$1"
echo
}
eval_gettextln () {
eval_gettext "$1"
echo
}