[PATCH v4 03/73] gettext: do not poison translations unless GIT_GETTEXT_POISON envvar is set

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Jonathan Nieder <jrnieder@xxxxxxxxx>

Tweak the GETTEXT_POISON facility so it is activated at run time
instead of compile time.  If the GIT_GETTEXT_POISON environment
variable is set, _(msg) will result in gibberish as before; but if the
GIT_GETTEXT_POISON variable is not set, it will return the message for
human-readable output.  So the behavior of mistranslated and
untranslated git can be compared without rebuilding git in between.

For simplicity we always set the GIT_GETTEXT_POISON variable in tests.

This does not affect builds without the GETTEXT_POISON compile-time
option set, so non-i18n git will not be slowed down.

Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
---
 Makefile      |    5 ++++-
 gettext.c     |   14 ++++++++++++++
 gettext.h     |    2 +-
 t/test-lib.sh |    8 +++++++-
 4 files changed, 26 insertions(+), 3 deletions(-)
 create mode 100644 gettext.c

diff --git a/Makefile b/Makefile
index c348bb7..4e9d935 100644
--- a/Makefile
+++ b/Makefile
@@ -217,7 +217,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.
+# for translation.  In a GETTEXT_POISON build, you can turn all strings marked
+# for translation into gibberish by setting the GIT_GETTEXT_POISON variable
+# (to any value) in your environment.
 #
 # Define JSMIN to point to JavaScript minifier that functions as
 # a filter to have gitweb.js minified.
@@ -1374,6 +1376,7 @@ ifdef NO_SYMLINK_HEAD
 	BASIC_CFLAGS += -DNO_SYMLINK_HEAD
 endif
 ifdef GETTEXT_POISON
+	LIB_OBJS += gettext.o
 	BASIC_CFLAGS += -DGETTEXT_POISON
 endif
 ifdef NO_STRCASESTR
diff --git a/gettext.c b/gettext.c
new file mode 100644
index 0000000..9688c8b
--- /dev/null
+++ b/gettext.c
@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2010 Ãvar ArnfjÃrà Bjarmason
+ */
+
+#include "git-compat-util.h"
+#include "gettext.h"
+
+int use_poison(void)
+{
+	static int poison_requested = -1;
+	if (poison_requested == -1)
+		poison_requested = getenv("GIT_GETTEXT_POISON") ? 1 : 0;
+	return poison_requested;
+}
diff --git a/gettext.h b/gettext.h
index 3d7cf44..ee7d41d 100644
--- a/gettext.h
+++ b/gettext.h
@@ -16,7 +16,7 @@
 #define FORMAT_PRESERVING(n) __attribute__((format_arg(n)))
 
 #ifdef GETTEXT_POISON
-#define use_poison() 1
+extern int use_poison(void);
 #else
 #define use_poison() 0
 #endif
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 0840e4a..f4c1e04 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1080,7 +1080,13 @@ 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
+if test -n "$GETTEXT_POISON"
+then
+	GIT_GETTEXT_POISON=YesPlease
+	export GIT_GETTEXT_POISON
+else
+	test_set_prereq C_LOCALE_OUTPUT
+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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]