git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 09/20] gettext: add GETTEXT_POISON support for shell scripts

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Sep 7, 2010, 16:47 UTC
Message-ID
<1283878065-19349-6-git-send-email-avarab@gmail.com>
In-Reply-To
<1283877955-19105-1-git-send-email-avarab@gmail.com>

Expand the existing GETTEXT_POISON=YesPlease support to support shell scripts. Analogous the existing C support this is needed to test that changes to the output of the shell scripts don't break the plumbing output.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 git-sh-i18n.sh               |   73 ++++++++++++++++++++++++++----------------
 t/t0201-gettext-fallbacks.sh |   12 +++---
 t/test-lib.sh                |    8 ++++-
 3 files changed, 58 insertions(+), 35 deletions(-)
diff --git a/git-sh-i18n.sh b/git-sh-i18n.sh
index 698a000..b8b645a 100644
--- a/git-sh-i18n.sh
+++ b/git-sh-i18n.sh
@@ -28,44 +28,61 @@ else
 fi
 export TEXTDOMAINDIR
 
-if test -z "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS" && type gettext.sh >/dev/null 2>&1
+if test -z "$GIT_INTERNAL_GETTEXT_GETTEXT_POISON"
 then
-	# This is GNU libintl's gettext.sh, we don't need to do anything
-	# else than setting up the environment and loading gettext.sh
-	GIT_INTERNAL_GETTEXT_SH_SCHEME=gnu
-	export GIT_INTERNAL_GETTEXT_SH_SCHEME
+	if test -z "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS" && type gettext.sh >/dev/null 2>&1
+	then
+		# This is GNU libintl's gettext.sh, we don't need to do anything
+		# else than setting up the environment and loading gettext.sh
+		GIT_INTERNAL_GETTEXT_SH_SCHEME=gnu
+		export GIT_INTERNAL_GETTEXT_SH_SCHEME
 
-	# Try to use libintl's gettext.sh, or fall back to English if we
-	# can't.
-	. gettext.sh
-elif test -z "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS" && test "$(gettext -h 2>&1)" = "-h"
-then
-	# We don't have gettext.sh, but there's a gettext binary in our
-	# path. This is probably Solaris or something like it which has a
-	# gettext implementation that isn't GNU libintl.
-	GIT_INTERNAL_GETTEXT_SH_SCHEME=solaris
-	export GIT_INTERNAL_GETTEXT_SH_SCHEME
+		# Try to use libintl's gettext.sh, or fall back to English if we
+		# can't.
+		. gettext.sh
+	elif test -z "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS" && test "$(gettext -h 2>&1)" = "-h"
+	then
+		# We don't have gettext.sh, but there's a gettext binary in our
+		# path. This is probably Solaris or something like it which has a
+		# gettext implementation that isn't GNU libintl.
+		GIT_INTERNAL_GETTEXT_SH_SCHEME=solaris
+		export GIT_INTERNAL_GETTEXT_SH_SCHEME
 
-	# Solaris has a gettext(1) but no eval_gettext(1)
-	eval_gettext () {
-		gettext_out=$(gettext "$1")
-		gettext_eval="printf '%s' \"$gettext_out\""
-		printf "%s" "`eval \"$gettext_eval\"`"
-	}
+		# Solaris has a gettext(1) but no eval_gettext(1)
+		eval_gettext () {
+			gettext_out=$(gettext "$1")
+			gettext_eval="printf '%s' \"$gettext_out\""
+			printf "%s" "`eval \"$gettext_eval\"`"
+		}
+	else
+		# Since gettext.sh isn't available we'll have to define our own
+		# dummy pass-through functions.
+
+		# Tell our tests that we don't have the real gettext.sh
+		GIT_INTERNAL_GETTEXT_SH_SCHEME=fallthrough
+		export GIT_INTERNAL_GETTEXT_SH_SCHEME
+
+		gettext () {
+			printf "%s" "$1"
+		}
+
+		eval_gettext () {
+			gettext_eval="printf '%s' \"$1\""
+			printf "%s" "`eval \"$gettext_eval\"`"
+		}
+	fi
 else
-	# Since gettext.sh isn't available we'll have to define our own
-	# dummy pass-through functions.
+	# Emit garbage under GETTEXT_POISON=YesPlease. Unlike the C tests
+	# this relies on an environment variable
 
-	# Tell our tests that we don't have the real gettext.sh
-	GIT_INTERNAL_GETTEXT_SH_SCHEME=fallthrough
+	GIT_INTERNAL_GETTEXT_SH_SCHEME=poison
 	export GIT_INTERNAL_GETTEXT_SH_SCHEME
 
 	gettext () {
-		printf "%s" "$1"
+		printf "%s" "# GETTEXT POISON #"
 	}
 
 	eval_gettext () {
-		gettext_eval="printf '%s' \"$1\""
-		printf "%s" "`eval \"$gettext_eval\"`"
+		printf "%s" "# GETTEXT POISON #"
 	}
 fi
diff --git a/t/t0201-gettext-fallbacks.sh b/t/t0201-gettext-fallbacks.sh
index 47ce4f6..7a85d9b 100755
--- a/t/t0201-gettext-fallbacks.sh
+++ b/t/t0201-gettext-fallbacks.sh
@@ -10,19 +10,19 @@ export GIT_INTERNAL_GETTEXT_TEST_FALLBACKS
 
 . ./lib-gettext.sh
 
-test_expect_success "sanity: \$GIT_INTERNAL_GETTEXT_SH_SCHEME is set (to $GIT_INTERNAL_GETTEXT_SH_SCHEME)" '
+test_expect_success NO_GETTEXT_POISON "sanity: \$GIT_INTERNAL_GETTEXT_SH_SCHEME is set (to $GIT_INTERNAL_GETTEXT_SH_SCHEME)" '
     test -n "$GIT_INTERNAL_GETTEXT_SH_SCHEME"
 '
 
-test_expect_success 'sanity: $GIT_INTERNAL_GETTEXT_TEST_FALLBACKS is set' '
+test_expect_success NO_GETTEXT_POISON 'sanity: $GIT_INTERNAL_GETTEXT_TEST_FALLBACKS is set' '
     test -n "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS"
 '
 
-test_expect_success 'sanity: $GIT_INTERNAL_GETTEXT_SH_SCHEME" is fallthrough' '
+test_expect_success NO_GETTEXT_POISON 'sanity: $GIT_INTERNAL_GETTEXT_SH_SCHEME" is fallthrough' '
     test "$GIT_INTERNAL_GETTEXT_SH_SCHEME" = "fallthrough"
 '
 
-test_expect_success 'gettext: our gettext() fallback has pass-through semantics' '
+test_expect_success NO_GETTEXT_POISON 'gettext: our gettext() fallback has pass-through semantics' '
     printf "test" >expect &&
     gettext "test" >actual &&
     test_cmp expect actual &&
@@ -31,7 +31,7 @@ test_expect_success 'gettext: our gettext() fallback has pass-through semantics'
     test_cmp expect actual
 '
 
-test_expect_success 'eval_gettext: our eval_gettext() fallback has pass-through semantics' '
+test_expect_success NO_GETTEXT_POISON 'eval_gettext: our eval_gettext() fallback has pass-through semantics' '
     printf "test" >expect &&
     eval_gettext "test" >actual &&
     test_cmp expect actual &&
@@ -40,7 +40,7 @@ test_expect_success 'eval_gettext: our eval_gettext() fallback has pass-through
     test_cmp expect actual
 '
 
-test_expect_success 'eval_gettext: our eval_gettext() fallback can interpolate variables' '
+test_expect_success NO_GETTEXT_POISON 'eval_gettext: our eval_gettext() fallback can interpolate variables' '
     printf "test YesPlease" >expect &&
     eval_gettext "test \$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS" >actual &&
     test_cmp expect actual
diff --git a/t/test-lib.sh b/t/test-lib.sh
index b297ef6..5a9f989 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -963,7 +963,13 @@ esac
 test -z "$NO_PERL" && test_set_prereq PERL
 test -z "$NO_PYTHON" && test_set_prereq PYTHON
 test -z "$NO_GETTEXT" && test_set_prereq GETTEXT
-test -z "$GETTEXT_POISON" && test_set_prereq NO_GETTEXT_POISON
+if test -z "$GETTEXT_POISON"
+then
+	test_set_prereq NO_GETTEXT_POISON
+else
+	GIT_INTERNAL_GETTEXT_GETTEXT_POISON=YesPlease
+	export GIT_INTERNAL_GETTEXT_GETTEXT_POISON
+fi
 
 # test whether the filesystem supports symbolic links
 ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
-- 
1.7.2.3.313.gcd15
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 9 of 47 in “[CONTINUE] Add gettext support to Git”
  1. 00/20 [CONTINUE] Add gettext support to GitÆvar Arnfjörð Bjarmason, Sep 7, 2010
  2. 01/20 gettextize: git-clean clean.requireForce bracesÆvar Arnfjörð Bjarmason, Sep 7, 2010
  3. 02/20 gettextize: git-clone "Cloning into" message bracesÆvar Arnfjörð Bjarmason, Sep 7, 2010
  4. 04/20 Makefile: add GNU_GETTEXT, set when we expect GNU gettextÆvar Arnfjörð Bjarmason, Sep 7, 2010
  5. 05/20 Makefile: MSGFMT="msgfmt --check" under GNU_GETTEXTÆvar Arnfjörð Bjarmason, Sep 7, 2010
  6. 06/20 Revert "gettextize: git-revert mark the "me" variable for translation"Ævar Arnfjörð Bjarmason, Sep 7, 2010
  7. 07/20 gettextize: git-revert "Your local changes" messageÆvar Arnfjörð Bjarmason, Sep 7, 2010
  8. 08/20 gettextize: git-revert literal "me" messagesÆvar Arnfjörð Bjarmason, Sep 7, 2010
  9. 09/20 gettext: add GETTEXT_POISON support for shell scriptsÆvar Arnfjörð Bjarmason, Sep 7, 2010
  10. 10/20 gettext: add GETTEXT_POISON tests for shell scriptsÆvar Arnfjörð Bjarmason, Sep 7, 2010
  11. 11/20 gettextize: git-am add git-sh-i18nÆvar Arnfjörð Bjarmason, Sep 7, 2010
  12. 12/20 gettextize: git-am one-line gettext $msg; echoÆvar Arnfjörð Bjarmason, Sep 7, 2010
  13. 13/20 gettextize: git-am multi-line getttext $msg; echoÆvar Arnfjörð Bjarmason, Sep 7, 2010
  14. 14/20 gettextize: git-am eval_gettext messagesÆvar Arnfjörð Bjarmason, Sep 7, 2010
  15. 15/20 gettextize: git-am die messagesÆvar Arnfjörð Bjarmason, Sep 7, 2010
  16. 16/20 gettextize: git-am cannot_fallback messagesÆvar Arnfjörð Bjarmason, Sep 7, 2010
  17. 17/20 gettextize: git-am clean_abort messagesÆvar Arnfjörð Bjarmason, Sep 7, 2010
  18. 18/20 gettextize: git-am "Apply?" messageÆvar Arnfjörð Bjarmason, Sep 7, 2010
  19. 19/20 gettextize: git-am core say messagesÆvar Arnfjörð Bjarmason, Sep 7, 2010
  20. 20/20 gettextize: git-am printf(1) message to eval_gettextÆvar Arnfjörð Bjarmason, Sep 7, 2010
  21. Jonathan NiederSep 7, 2010
  22. Ævar Arnfjörð BjarmasonSep 7, 2010
  23. Jonathan NiederSep 7, 2010
  24. 20/20 gettextize: git-am printf(1) message to eval_gettextÆvar Arnfjörð Bjarmason, Sep 7, 2010
  25. 19/20 gettextize: git-am core say messagesÆvar Arnfjörð Bjarmason, Sep 7, 2010
  26. Junio C HamanoSep 8, 2010
  27. Ævar Arnfjörð BjarmasonSep 8, 2010
  28. Ævar Arnfjörð BjarmasonSep 10, 2010
  29. Junio C HamanoSep 10, 2010
  30. Ævar Arnfjörð BjarmasonSep 10, 2010
  31. 0/5 gettext docs: programmer docs in po/READMEÆvar Arnfjörð Bjarmason, Sep 10, 2010
  32. Ævar Arnfjörð BjarmasonSep 10, 2010
  33. 1/5 gettext docs: add a "Testing your changes" section to po/READMEÆvar Arnfjörð Bjarmason, Sep 10, 2010
  34. 2/5 gettext docs: add "Marking strings for translation" section in po/READMEÆvar Arnfjörð Bjarmason, Sep 10, 2010
  35. Junio C HamanoSep 10, 2010
  36. Ævar Arnfjörð BjarmasonSep 10, 2010
  37. 3/5 gettext docs: the gettext.h C interfaceÆvar Arnfjörð Bjarmason, Sep 10, 2010
  38. Junio C HamanoSep 10, 2010
  39. Ævar Arnfjörð BjarmasonSep 10, 2010
  40. Junio C HamanoSep 10, 2010
  41. Ævar Arnfjörð BjarmasonSep 10, 2010
  42. Junio C HamanoSep 10, 2010
  43. Ævar Arnfjörð BjarmasonSep 10, 2010
  44. 4/5 gettext docs: the git-sh-i18n.sh Shell interfaceÆvar Arnfjörð Bjarmason, Sep 10, 2010
  45. Junio C HamanoSep 10, 2010
  46. Ævar Arnfjörð BjarmasonSep 10, 2010
  47. 5/5 gettext docs: the Git::I18N Perl interfaceÆvar Arnfjörð Bjarmason, Sep 10, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.