[PATCH 3/6] Replace gettext poison implementation with pseudotranslation generation

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

 



Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
---
 Makefile                  | 45 ++++++++++++++++++++++++++-------------------
 gettext.c                 | 10 ----------
 gettext.h                 | 10 +---------
 git-sh-i18n.sh            | 14 --------------
 po/.gitignore             |  1 +
 po/README                 | 15 ++++++++-------
 t/.gitignore              |  1 +
 t/lib-gettext.sh          |  7 ++++++-
 t/t0200-gettext-basic.sh  |  1 +
 t/t0205-gettext-poison.sh | 36 ------------------------------------
 t/test-lib.sh             |  2 +-
 wrap-for-bin.sh           | 10 +++++++++-
 12 files changed, 54 insertions(+), 98 deletions(-)
 delete mode 100755 t/t0205-gettext-poison.sh

diff --git a/Makefile b/Makefile
index 485978f..89f4fc0 100644
--- a/Makefile
+++ b/Makefile
@@ -258,11 +258,6 @@ all::
 # Define HAVE_DEV_TTY if your system can open /dev/tty to interact with the
 # user.
 #
-# Define GETTEXT_POISON if you are debugging the choice of strings marked
-# 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.
 #
@@ -376,6 +371,8 @@ MSGFMT = msgfmt
 PTHREAD_LIBS = -lpthread
 PTHREAD_CFLAGS =
 GCOV = gcov
+PODEBUG = podebug
+PODEBUG_OPTS = --rewrite=unicode
 
 export TCL_PATH TCLTK_PATH
 
@@ -1594,9 +1591,6 @@ endif
 ifdef NO_SYMLINK_HEAD
 	BASIC_CFLAGS += -DNO_SYMLINK_HEAD
 endif
-ifdef GETTEXT_POISON
-	BASIC_CFLAGS += -DGETTEXT_POISON
-endif
 ifdef NO_GETTEXT
 	BASIC_CFLAGS += -DNO_GETTEXT
 	USE_GETTEXT_SCHEME ?= fallthrough
@@ -2403,19 +2397,28 @@ LOCALIZED_C := $(C_OBJ_NOTESTS:o=c) $(LIB_H) $(GENERATED_H)
 LOCALIZED_SH := $(SCRIPT_SH)
 LOCALIZED_PERL := $(SCRIPT_PERL)
 
-ifdef XGETTEXT_INCLUDE_TESTS
-LOCALIZED_C += t/t0200/test.c
-LOCALIZED_SH += t/t0200/test.sh
-LOCALIZED_PERL += t/t0200/test.perl
-endif
+LOCALIZED_C_TESTS += t/t0200/test.c $(TEST_OBJS:o=c)
+LOCALIZED_SH_TESTS += t/t0200/test.sh
+LOCALIZED_PERL_TESTS += t/t0200/test.perl
 
-po/git.pot: $(LOCALIZED_C) $(LOCALIZED_SH) $(LOCALIZED_PERL)
-	$(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ $(XGETTEXT_FLAGS_C) $(LOCALIZED_C)
-	$(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ --join-existing $(XGETTEXT_FLAGS_SH) \
+po/git.pot+: $(LOCALIZED_C) $(LOCALIZED_SH) $(LOCALIZED_PERL)
+	$(QUIET_XGETTEXT)$(XGETTEXT) -o$@ $(XGETTEXT_FLAGS_C) $(LOCALIZED_C)
+	$(QUIET_XGETTEXT)$(XGETTEXT) -o$@ --join-existing $(XGETTEXT_FLAGS_SH) \
 		$(LOCALIZED_SH)
-	$(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ --join-existing $(XGETTEXT_FLAGS_PERL) \
+	$(QUIET_XGETTEXT)$(XGETTEXT) -o$@ --join-existing $(XGETTEXT_FLAGS_PERL) \
 		$(LOCALIZED_PERL)
-	mv $@+ $@
+
+po/git.pot: po/git.pot+
+	mv $< $@
+
+t/test.po: po/git.pot+ $(LOCALIZED_C_TESTS) $(LOCALIZED_SH_TESTS) $(LOCALIZED_PERL_TESTS)
+	cp $< $@t
+	$(QUIET_XGETTEXT)$(XGETTEXT) -o$@t --join-existing $(XGETTEXT_FLAGS_C) $(LOCALIZED_C_TESTS)
+	$(QUIET_XGETTEXT)$(XGETTEXT) -o$@t --join-existing $(XGETTEXT_FLAGS_SH) \
+		$(LOCALIZED_SH_TESTS)
+	$(QUIET_XGETTEXT)$(XGETTEXT) -o$@t --join-existing $(XGETTEXT_FLAGS_PERL) \
+		$(LOCALIZED_PERL_TESTS)
+	$(PODEBUG) $(PODEBUG_OPTS) $@t -o $@
 
 pot: po/git.pot
 
@@ -2429,6 +2432,11 @@ endif
 po/build/locale/%/LC_MESSAGES/git.mo: po/%.po
 	$(QUIET_MSGFMT)mkdir -p $(dir $@) && $(MSGFMT) -o $@ $<
 
+po/build/pseudo-locale/$(L)/LC_MESSAGES/git.mo: t/test.po
+	$(QUIET_MSGFMT)mkdir -p $(dir $@) && $(MSGFMT) -o $@ $<
+
+pseudo-locale: po/build/pseudo-locale/$(L)/LC_MESSAGES/git.mo
+
 FIND_SOURCE_FILES = ( git ls-files '*.[hcS]' 2>/dev/null || \
 			$(FIND) . \( -name .git -type d -prune \) \
 				-o \( -name '*.[hcS]' -type f -print \) )
@@ -2498,7 +2506,6 @@ ifdef GIT_TEST_CMP_USE_COPIED_CONTEXT
 	@echo GIT_TEST_CMP_USE_COPIED_CONTEXT=YesPlease >>$@
 endif
 	@echo NO_GETTEXT=\''$(subst ','\'',$(subst ','\'',$(NO_GETTEXT)))'\' >>$@
-	@echo GETTEXT_POISON=\''$(subst ','\'',$(subst ','\'',$(GETTEXT_POISON)))'\' >>$@
 ifdef GIT_PERF_REPEAT_COUNT
 	@echo GIT_PERF_REPEAT_COUNT=\''$(subst ','\'',$(subst ','\'',$(GIT_PERF_REPEAT_COUNT)))'\' >>$@
 endif
diff --git a/gettext.c b/gettext.c
index f75bca7..6aa822c 100644
--- a/gettext.c
+++ b/gettext.c
@@ -16,16 +16,6 @@
 #	endif
 #endif
 
-#ifdef GETTEXT_POISON
-int use_gettext_poison(void)
-{
-	static int poison_requested = -1;
-	if (poison_requested == -1)
-		poison_requested = getenv("GIT_GETTEXT_POISON") ? 1 : 0;
-	return poison_requested;
-}
-#endif
-
 #ifndef NO_GETTEXT
 static void init_gettext_charset(const char *domain)
 {
diff --git a/gettext.h b/gettext.h
index 57ba8bb..634d8fb 100644
--- a/gettext.h
+++ b/gettext.h
@@ -36,22 +36,14 @@ static inline void git_setup_gettext(void)
 }
 #endif
 
-#ifdef GETTEXT_POISON
-extern int use_gettext_poison(void);
-#else
-#define use_gettext_poison() 0
-#endif
-
 static inline FORMAT_PRESERVING(1) const char *_(const char *msgid)
 {
-	return use_gettext_poison() ? "# GETTEXT POISON #" : gettext(msgid);
+	return gettext(msgid);
 }
 
 static inline FORMAT_PRESERVING(1) FORMAT_PRESERVING(2)
 const char *Q_(const char *msgid, const char *plu, unsigned long n)
 {
-	if (use_gettext_poison())
-		return "# GETTEXT POISON #";
 	return ngettext(msgid, plu, n);
 }
 
diff --git a/git-sh-i18n.sh b/git-sh-i18n.sh
index 6a27f68..d446ba5 100644
--- a/git-sh-i18n.sh
+++ b/git-sh-i18n.sh
@@ -24,9 +24,6 @@ then
 elif test -n "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS"
 then
 	: no probing necessary
-elif test -n "$GIT_GETTEXT_POISON"
-then
-	GIT_INTERNAL_GETTEXT_SH_SCHEME=poison
 elif type gettext.sh >/dev/null 2>&1
 then
 	# GNU libintl's gettext.sh
@@ -55,17 +52,6 @@ gettext_without_eval_gettext)
 		)
 	}
 	;;
-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 #"
-	}
-	;;
 *)
 	gettext () {
 		printf "%s" "$1"
diff --git a/po/.gitignore b/po/.gitignore
index 796b96d..0a4b7fa 100644
--- a/po/.gitignore
+++ b/po/.gitignore
@@ -1 +1,2 @@
 /build
+/git.pot+
diff --git a/po/README b/po/README
index c1520e8..7f40b08 100644
--- a/po/README
+++ b/po/README
@@ -270,16 +270,15 @@ something in the test suite might still depend on the US English
 version of the strings, e.g. to grep some error message or other
 output.
 
-To smoke out issues like these Git can be compiled with gettext poison
-support, at the top-level:
+To smoke out issues like these, we can use a podebug [1] utility
+to generate a pseudotranslation. At top level:
 
-    make GETTEXT_POISON=YesPlease
+    # Assume locale "vi_VN.UTF-8" is supported by system
+    make pseudo-locale L=vi
+    make GETTEXT_POISON=vi_VN.UTF-8 test
 
 That'll give you a git which emits gibberish on every call to
-gettext. It's obviously not meant to be installed, but you should run
-the test suite with it:
-
-    cd t && prove -j 9 ./t[0-9]*.sh
+gettext.
 
 If tests break with it you should inspect them manually and see if
 what you're translating is sane, i.e. that you're not translating
@@ -290,3 +289,5 @@ test_cmp calls with test_i18ncmp. If that's not enough you can skip
 the whole test by making it depend on the C_LOCALE_OUTPUT
 prerequisite. See existing test files with this prerequisite for
 examples.
+
+[1] http://translate.sourceforge.net/wiki/toolkit/podebug
diff --git a/t/.gitignore b/t/.gitignore
index 4e731dc..077b7d5 100644
--- a/t/.gitignore
+++ b/t/.gitignore
@@ -1,3 +1,4 @@
 /trash directory*
 /test-results
 /.prove
+/test.po*
diff --git a/t/lib-gettext.sh b/t/lib-gettext.sh
index 0f76f6c..50b5ef9 100644
--- a/t/lib-gettext.sh
+++ b/t/lib-gettext.sh
@@ -5,7 +5,12 @@
 
 . ./test-lib.sh
 
-GIT_TEXTDOMAINDIR="$GIT_BUILD_DIR/po/build/locale"
+if test -n "$GETTEXT_POISON"
+then
+	GIT_TEXTDOMAINDIR="$GIT_BUILD_DIR/po/build/pseudo-locale"
+else
+	GIT_TEXTDOMAINDIR="$GIT_BUILD_DIR/po/build/locale"
+fi
 GIT_PO_PATH="$GIT_BUILD_DIR/po"
 export GIT_TEXTDOMAINDIR GIT_PO_PATH
 
diff --git a/t/t0200-gettext-basic.sh b/t/t0200-gettext-basic.sh
index 8853d8a..572df23 100755
--- a/t/t0200-gettext-basic.sh
+++ b/t/t0200-gettext-basic.sh
@@ -36,6 +36,7 @@ test_expect_success GETTEXT 'sanity: $TEXTDOMAINDIR exists without NO_GETTEXT=Ye
 '
 
 test_expect_success GETTEXT 'sanity: Icelandic locale was compiled' '
+    test -n "$GETTEXT_POISON" ||
     test -f "$TEXTDOMAINDIR/is/LC_MESSAGES/git.mo"
 '
 
diff --git a/t/t0205-gettext-poison.sh b/t/t0205-gettext-poison.sh
deleted file mode 100755
index 2361590..0000000
--- a/t/t0205-gettext-poison.sh
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 2010 Ævar Arnfjörð Bjarmason
-#
-
-test_description='Gettext Shell poison'
-
-. ./lib-gettext.sh
-
-test_expect_success 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 GETTEXT_POISON 'sanity: $GIT_INTERNAL_GETTEXT_SH_SCHEME" is poison' '
-    test "$GIT_INTERNAL_GETTEXT_SH_SCHEME" = "poison"
-'
-
-test_expect_success GETTEXT_POISON 'gettext: our gettext() fallback has poison semantics' '
-    printf "# GETTEXT POISON #" >expect &&
-    gettext "test" >actual &&
-    test_cmp expect actual &&
-    printf "# GETTEXT POISON #" >expect &&
-    gettext "test more words" >actual &&
-    test_cmp expect actual
-'
-
-test_expect_success GETTEXT_POISON 'eval_gettext: our eval_gettext() fallback has poison semantics' '
-    printf "# GETTEXT POISON #" >expect &&
-    eval_gettext "test" >actual &&
-    test_cmp expect actual &&
-    printf "# GETTEXT POISON #" >expect &&
-    eval_gettext "test more words" >actual &&
-    test_cmp expect actual
-'
-
-test_done
diff --git a/t/test-lib.sh b/t/test-lib.sh
index bb4f886..b18a079 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -626,7 +626,7 @@ test -z "$NO_GETTEXT" && test_set_prereq GETTEXT
 # Can we rely on git's output in the C locale?
 if test -n "$GETTEXT_POISON"
 then
-	GIT_GETTEXT_POISON=YesPlease
+	GIT_GETTEXT_POISON=$GETTEXT_POISON
 	export GIT_GETTEXT_POISON
 	test_set_prereq GETTEXT_POISON
 else
diff --git a/wrap-for-bin.sh b/wrap-for-bin.sh
index 53a8dd0..a2d9aef 100644
--- a/wrap-for-bin.sh
+++ b/wrap-for-bin.sh
@@ -15,7 +15,15 @@ else
 	export GIT_TEMPLATE_DIR
 fi
 GITPERLLIB='@@BUILD_DIR@@/perl/blib/lib'
-GIT_TEXTDOMAINDIR='@@BUILD_DIR@@/po/build/locale'
+if test -n "$GIT_GETTEXT_POISON"
+then
+	GIT_TEXTDOMAINDIR='@@BUILD_DIR@@/po/build/pseudo-locale'
+	LANG=$GIT_GETTEXT_POISON
+	unset LC_ALL
+	export LANG
+else
+	GIT_TEXTDOMAINDIR='@@BUILD_DIR@@/po/build/locale'
+fi
 PATH='@@BUILD_DIR@@/bin-wrappers:'"$PATH"
 export GIT_EXEC_PATH GITPERLLIB PATH GIT_TEXTDOMAINDIR
 
-- 
1.7.12.rc2

--
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]