Subject: [PATCH 2/3] tests: add GETTEXT_POISON to simulate unfriendly translator

From: Jonathan Nieder <[email-masked]>
Date: Sun, 20 Feb 2011 22:03:13 -0600

From: Ævar Arnfjörð Bjarmason <[email-masked]>

Add a new GETTEXT_POISON Makefile parameter.  When it is set, every
invocation of _(s) will return a nonsense string instead of 's' or an
actual translation of 's'.  By setting this parameter, we can make
sure that none of the strings marked for translation are functionally
important.

When tests are checking specific (US English) output from Git, they
should add a C_LOCALE_OUTPUT prerequisite.  Running through tests in
this way can help to find messages that should not be translated
because they are part of the git plumbing.

The poison string is "# GETTEXT POISON #", so it is still a valid
comment that is safe to put at the end of the message shown by 'git
commit --amend' and so on.  That simplifies life until git can learn
to add the "# " comment markers itself instead of relying on
translators to remember them.

Signed-off-by: Ævar Arnfjörð Bjarmason <[email-masked]>
Signed-off-by: Jonathan Nieder <[email-masked]>
---
 Makefile      |    7 +++++++
 gettext.h     |    8 +++++++-
 t/test-lib.sh |    3 +++
 3 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/Makefile b/Makefile
index c153f45..c348bb7 100644
--- a/Makefile
+++ b/Makefile
@@ -216,6 +216,9 @@ all::
 #
 # Define NO_REGEX if you have no or inferior regex support in your C library.
 #
+# Define GETTEXT_POISON if you are debugging the choice of strings marked
+# for translation.  This will turn all strings that use gettext into gibberish.
+#
 # Define JSMIN to point to JavaScript minifier that functions as
 # a filter to have gitweb.js minified.
 #
@@ -1370,6 +1373,9 @@ endif
 ifdef NO_SYMLINK_HEAD
 	BASIC_CFLAGS += -DNO_SYMLINK_HEAD
 endif
+ifdef GETTEXT_POISON
+	BASIC_CFLAGS += -DGETTEXT_POISON
+endif
 ifdef NO_STRCASESTR
 	COMPAT_CFLAGS += -DNO_STRCASESTR
 	COMPAT_OBJS += compat/strcasestr.o
@@ -2089,6 +2095,7 @@ endif
 ifdef GIT_TEST_CMP_USE_COPIED_CONTEXT
 	@echo GIT_TEST_CMP_USE_COPIED_CONTEXT=YesPlease >>$@
 endif
+	@echo GETTEXT_POISON=\''$(subst ','\'',$(subst ','\'',$(GETTEXT_POISON)))'\' >>$@
 
 ### Detect Tck/Tk interpreter path changes
 ifndef NO_TCLTK
diff --git a/gettext.h b/gettext.h
index dc44825..6daa57c 100644
--- a/gettext.h
+++ b/gettext.h
@@ -15,9 +15,15 @@
 
 #define FORMAT_PRESERVING(n) __attribute__((format_arg(n)))
 
+#ifdef GETTEXT_POISON
+#define use_poison() 1
+#else
+#define use_poison() 0
+#endif
+
 static inline FORMAT_PRESERVING(1) const char *_(const char *msgid)
 {
-	return msgid;
+	return use_poison() ? "# GETTEXT POISON #" : msgid;
 }
 
 /* Mark msgid for translation but do not translate it. */
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 0fdc541..0840e4a 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1079,6 +1079,9 @@ esac
 test -z "$NO_PERL" && test_set_prereq PERL
 test -z "$NO_PYTHON" && test_set_prereq PYTHON
 
+# Can we rely on git's output in the C locale?
+test -z "$GETTEXT_POISON" && test_set_prereq C_LOCALE_OUTPUT
+
 # test whether the filesystem supports symbolic links
 ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
 rm -f y
-- 
1.7.4.1