[PATCH 0/6] Gettext poison rework

DORMANTno replies

9 messages, 2 authors, 2016-06-15 · open the first message on its own page

[PATCH 0/6] Gettext poison rework

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 22:54:34

Still WIP but I'm getting closer. I dropped test-poisongen and started
to use podebug [2] instead. Less code in git. podebug does not preserve
shell variables yet. I'll follow that up at upstream [1].

With this series, if you have translation toolkit installed, you could
do

    make pseudo-locale L=<your language code>
    make GETTEXT_POISON=$LANG test

podebug supports a few way of rewriting translations. Currently
"unicode" is used but you can change it via PODEBUG_OPTS

t9001 is not happy with $LANG != C though. May need to add some
prereq there.

[1] http://bugs.locamotion.org/show_bug.cgi?id=2450
[2] http://translate.sourceforge.net/wiki/toolkit/podebug

Nguyễn Thái Ngọc Duy (6):
  Makefile: do not mark strings for l10n from test programs
  Makefile: recreate git.pot if *.sh or *.perl changes
  Replace gettext poison implementation with pseudotranslation
    generation
  Initialize gettext for test programs that may use it
  Support logging unmarked strings
  test-parse-options: mark parseopt help strings for pseudotranslation

 .gitignore                |  1 +
 Makefile                  | 48 +++++++++++++++++++++---------------
 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 +-
 test-date.c               |  1 +
 test-delta.c              |  1 +
 test-dump-cache-tree.c    |  5 +++-
 test-index-version.c      |  1 +
 test-match-trees.c        |  1 +
 test-mergesort.c          |  1 +
 test-parse-options.c      | 63 ++++++++++++++++++++++++-----------------------
 test-path-utils.c         |  1 +
 test-revision-walking.c   |  1 +
 test-scrap-cache-tree.c   |  4 ++-
 test-sha1.c               |  1 +
 test-subprocess.c         |  1 +
 wrap-for-bin.sh           | 16 +++++++++++-
 25 files changed, 111 insertions(+), 132 deletions(-)
 delete mode 100755 t/t0205-gettext-poison.sh

-- 
1.7.12.rc2

[PATCH 1/6] Makefile: do not mark strings for l10n from test programs

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 22:54:34

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index 6b0c961..ddeb04d 100644
--- a/Makefile
+++ b/Makefile
@@ -2398,7 +2398,8 @@ XGETTEXT_FLAGS_C = $(XGETTEXT_FLAGS) --language=C \
 XGETTEXT_FLAGS_SH = $(XGETTEXT_FLAGS) --language=Shell \
 	--keyword=gettextln --keyword=eval_gettextln
 XGETTEXT_FLAGS_PERL = $(XGETTEXT_FLAGS) --keyword=__ --language=Perl
-LOCALIZED_C := $(C_OBJ:o=c) $(LIB_H) $(GENERATED_H)
+C_OBJ_NOTESTS:= $(filter-out test-%,$(C_OBJ))
+LOCALIZED_C := $(C_OBJ_NOTESTS:o=c) $(LIB_H) $(GENERATED_H)
 LOCALIZED_SH := $(SCRIPT_SH)
 LOCALIZED_PERL := $(SCRIPT_PERL)
 
-- 
1.7.12.rc2

[PATCH 2/6] Makefile: recreate git.pot if *.sh or *.perl changes

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 22:54:34

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index ddeb04d..485978f 100644
--- a/Makefile
+++ b/Makefile
@@ -2409,7 +2409,7 @@ LOCALIZED_SH += t/t0200/test.sh
 LOCALIZED_PERL += t/t0200/test.perl
 endif
 
-po/git.pot: $(LOCALIZED_C)
+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)
-- 
1.7.12.rc2

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

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 22:54:34

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 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

[PATCH 4/6] Initialize gettext for test programs that may use it

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 22:54:34

Gettext poison was a macro and _() always returned
"# GETTEXT POISON #". Now that we use real gettext(),
it has to be initialized or it won't work.

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 test-date.c             | 1 +
 test-delta.c            | 1 +
 test-dump-cache-tree.c  | 5 ++++-
 test-index-version.c    | 1 +
 test-match-trees.c      | 1 +
 test-mergesort.c        | 1 +
 test-parse-options.c    | 1 +
 test-path-utils.c       | 1 +
 test-revision-walking.c | 1 +
 test-scrap-cache-tree.c | 4 +++-
 test-sha1.c             | 1 +
 test-subprocess.c       | 1 +
 12 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/test-date.c b/test-date.c
index 10afaab..3881d33 100644
--- a/test-date.c
+++ b/test-date.c
@@ -48,6 +48,7 @@ int main(int argc, char **argv)
 	struct timeval now;
 	const char *x;
 
+	git_setup_gettext();
 	x = getenv("TEST_DATE_NOW");
 	if (x) {
 		now.tv_sec = atoi(x);
diff --git a/test-delta.c b/test-delta.c
index af40a3c..ac86cae 100644
--- a/test-delta.c
+++ b/test-delta.c
@@ -22,6 +22,7 @@ int main(int argc, char *argv[])
 	void *from_buf, *data_buf, *out_buf;
 	unsigned long from_size, data_size, out_size;
 
+	git_setup_gettext();
 	if (argc != 5 || (strcmp(argv[1], "-d") && strcmp(argv[1], "-p"))) {
 		fprintf(stderr, "Usage: %s\n", usage_str);
 		return 1;
diff --git a/test-dump-cache-tree.c b/test-dump-cache-tree.c
index a6ffdf3..2023475 100644
--- a/test-dump-cache-tree.c
+++ b/test-dump-cache-tree.c
@@ -56,7 +56,10 @@ static int dump_cache_tree(struct cache_tree *it,
 
 int main(int ac, char **av)
 {
-	struct cache_tree *another = cache_tree();
+	struct cache_tree *another;
+
+	git_setup_gettext();
+	another = cache_tree();
 	if (read_cache() < 0)
 		die("unable to read index file");
 	cache_tree_update(another, active_cache, active_nr, WRITE_TREE_DRY_RUN);
diff --git a/test-index-version.c b/test-index-version.c
index bfaad9e..703f4bd 100644
--- a/test-index-version.c
+++ b/test-index-version.c
@@ -5,6 +5,7 @@ int main(int argc, const char **argv)
 	struct cache_header hdr;
 	int version;
 
+	git_setup_gettext();
 	memset(&hdr,0,sizeof(hdr));
 	if (read(0, &hdr, sizeof(hdr)) != sizeof(hdr))
 		return 0;
diff --git a/test-match-trees.c b/test-match-trees.c
index a3c4688..5299292 100644
--- a/test-match-trees.c
+++ b/test-match-trees.c
@@ -6,6 +6,7 @@ int main(int ac, char **av)
 	unsigned char hash1[20], hash2[20], shifted[20];
 	struct tree *one, *two;
 
+	git_setup_gettext();
 	if (get_sha1(av[1], hash1))
 		die("cannot parse %s as an object name", av[1]);
 	if (get_sha1(av[2], hash2))
diff --git a/test-mergesort.c b/test-mergesort.c
index 3f388b4..2289cb1 100644
--- a/test-mergesort.c
+++ b/test-mergesort.c
@@ -27,6 +27,7 @@ int main(int argc, const char **argv)
 	struct line *line, *p = NULL, *lines = NULL;
 	struct strbuf sb = STRBUF_INIT;
 
+	git_setup_gettext();
 	for (;;) {
 		if (strbuf_getwholeline(&sb, stdin, '\n'))
 			break;
diff --git a/test-parse-options.c b/test-parse-options.c
index 3c9510a..4a94327 100644
--- a/test-parse-options.c
+++ b/test-parse-options.c
@@ -81,6 +81,7 @@ int main(int argc, const char **argv)
 	};
 	int i;
 
+	git_setup_gettext();
 	argc = parse_options(argc, argv, prefix, options, usage, 0);
 
 	printf("boolean: %d\n", boolean);
diff --git a/test-path-utils.c b/test-path-utils.c
index 3bc20e9..f3b4cee 100644
--- a/test-path-utils.c
+++ b/test-path-utils.c
@@ -2,6 +2,7 @@
 
 int main(int argc, char **argv)
 {
+	git_setup_gettext();
 	if (argc == 3 && !strcmp(argv[1], "normalize_path_copy")) {
 		char *buf = xmalloc(PATH_MAX + 1);
 		int rv = normalize_path_copy(buf, argv[2]);
diff --git a/test-revision-walking.c b/test-revision-walking.c
index 3ade02c..5f476c0 100644
--- a/test-revision-walking.c
+++ b/test-revision-walking.c
@@ -47,6 +47,7 @@ static int run_revision_walk(void)
 
 int main(int argc, char **argv)
 {
+	git_setup_gettext();
 	if (argc < 2)
 		return 1;
 
diff --git a/test-scrap-cache-tree.c b/test-scrap-cache-tree.c
index 4728013..67234e1 100644
--- a/test-scrap-cache-tree.c
+++ b/test-scrap-cache-tree.c
@@ -6,7 +6,9 @@ static struct lock_file index_lock;
 
 int main(int ac, char **av)
 {
-	int fd = hold_locked_index(&index_lock, 1);
+	int fd;
+	git_setup_gettext();
+	fd = hold_locked_index(&index_lock, 1);
 	if (read_cache() < 0)
 		die("unable to read index file");
 	active_cache_tree = NULL;
diff --git a/test-sha1.c b/test-sha1.c
index 80daba9..9a02ce8 100644
--- a/test-sha1.c
+++ b/test-sha1.c
@@ -7,6 +7,7 @@ int main(int ac, char **av)
 	unsigned bufsz = 8192;
 	char *buffer;
 
+	git_setup_gettext();
 	if (ac == 2)
 		bufsz = strtoul(av[1], NULL, 10) * 1024 * 1024;
 
diff --git a/test-subprocess.c b/test-subprocess.c
index f2d4c0d..9cf8e29 100644
--- a/test-subprocess.c
+++ b/test-subprocess.c
@@ -6,6 +6,7 @@ int main(int argc, const char **argv)
 	struct child_process cp;
 	int nogit = 0;
 
+	git_setup_gettext();
 	setup_git_directory_gently(&nogit);
 	if (nogit)
 		die("No git repo found");
-- 
1.7.12.rc2

[PATCH 5/6] Support logging unmarked strings

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 22:54:34

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 Hard coding path obviously won't fly..

 .gitignore      | 1 +
 wrap-for-bin.sh | 6 ++++++
 2 files changed, 7 insertions(+)
diff --git a/.gitignore b/.gitignore
index bb5c91e..f2d0fe5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -195,6 +195,7 @@
 /test-sigchain
 /test-subprocess
 /test-svn-fe
+/untranslated.log
 /common-cmds.h
 *.tar.gz
 *.dsc
diff --git a/wrap-for-bin.sh b/wrap-for-bin.sh
index a2d9aef..4dbae80 100644
--- a/wrap-for-bin.sh
+++ b/wrap-for-bin.sh
@@ -17,6 +17,12 @@ fi
 GITPERLLIB='@@BUILD_DIR@@/perl/blib/lib'
 if test -n "$GIT_GETTEXT_POISON"
 then
+	if test -x /usr/lib/preloadable_libintl.so
+	then
+		GETTEXT_LOG_UNTRANSLATED=@@BUILD_DIR@@/untranslated.log
+		LD_PRELOAD="/usr/lib/preloadable_libintl.so $LD_PRELOAD"
+		export LD_PRELOAD GETTEXT_LOG_UNTRANSLATED
+	fi
 	GIT_TEXTDOMAINDIR='@@BUILD_DIR@@/po/build/pseudo-locale'
 	LANG=$GIT_GETTEXT_POISON
 	unset LC_ALL
-- 
1.7.12.rc2

[PATCH 6/6] test-parse-options: mark parseopt help strings for pseudotranslation

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 22:54:34

This reduces the number of false positives in untranslated.log when we
check for unmarked strings.

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 test-parse-options.c | 62 ++++++++++++++++++++++++++--------------------------
 1 file changed, 31 insertions(+), 31 deletions(-)
diff --git a/test-parse-options.c b/test-parse-options.c
index 4a94327..09ddf74 100644
--- a/test-parse-options.c
+++ b/test-parse-options.c
@@ -33,50 +33,50 @@ int main(int argc, const char **argv)
 {
 	const char *prefix = "prefix/";
 	const char *usage[] = {
-		"test-parse-options <options>",
+		N_("test-parse-options <options>"),
 		NULL
 	};
 	struct option options[] = {
-		OPT_BOOL(0, "yes", &boolean, "get a boolean"),
-		OPT_BOOL('D', "no-doubt", &boolean, "begins with 'no-'"),
+		OPT_BOOL(0, "yes", &boolean, N_("get a boolean")),
+		OPT_BOOL('D', "no-doubt", &boolean, N_("begins with 'no-'")),
 		{ OPTION_SET_INT, 'B', "no-fear", &boolean, NULL,
-		  "be brave", PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1 },
-		OPT_COUNTUP('b', "boolean", &boolean, "increment by one"),
+		  N_("be brave"), PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1 },
+		OPT_COUNTUP('b', "boolean", &boolean, N_("increment by one")),
 		OPT_BIT('4', "or4", &boolean,
-			"bitwise-or boolean with ...0100", 4),
-		OPT_NEGBIT(0, "neg-or4", &boolean, "same as --no-or4", 4),
+			N_("bitwise-or boolean with ...0100"), 4),
+		OPT_NEGBIT(0, "neg-or4", &boolean, N_("same as --no-or4"), 4),
 		OPT_GROUP(""),
-		OPT_INTEGER('i', "integer", &integer, "get a integer"),
-		OPT_INTEGER('j', NULL, &integer, "get a integer, too"),
-		OPT_SET_INT(0, "set23", &integer, "set integer to 23", 23),
-		OPT_DATE('t', NULL, &timestamp, "get timestamp of <time>"),
-		OPT_CALLBACK('L', "length", &integer, "str",
-			"get length of <str>", length_callback),
-		OPT_FILENAME('F', "file", &file, "set file to <file>"),
-		OPT_GROUP("String options"),
-		OPT_STRING('s', "string", &string, "string", "get a string"),
-		OPT_STRING(0, "string2", &string, "str", "get another string"),
-		OPT_STRING(0, "st", &string, "st", "get another string (pervert ordering)"),
-		OPT_STRING('o', NULL, &string, "str", "get another string"),
+		OPT_INTEGER('i', "integer", &integer, N_("get a integer")),
+		OPT_INTEGER('j', NULL, &integer, N_("get a integer, too")),
+		OPT_SET_INT(0, "set23", &integer, N_("set integer to 23"), 23),
+		OPT_DATE('t', NULL, &timestamp, N_("get timestamp of <time>")),
+		OPT_CALLBACK('L', "length", &integer, N_("str"),
+			N_("get length of <str>"), length_callback),
+		OPT_FILENAME('F', "file", &file, N_("set file to <file>")),
+		OPT_GROUP(N_("String options")),
+		OPT_STRING('s', "string", &string, N_("string"), N_("get a string")),
+		OPT_STRING(0, "string2", &string, N_("str"), N_("get another string")),
+		OPT_STRING(0, "st", &string, N_("st"), N_("get another string (pervert ordering)")),
+		OPT_STRING('o', NULL, &string, N_("str"), N_("get another string")),
 		OPT_NOOP_NOARG(0, "obsolete"),
 		OPT_SET_PTR(0, "default-string", &string,
-			"set string to default", (unsigned long)"default"),
-		OPT_STRING_LIST(0, "list", &list, "str", "add str to list"),
-		OPT_GROUP("Magic arguments"),
-		OPT_ARGUMENT("quux", "means --quux"),
-		OPT_NUMBER_CALLBACK(&integer, "set integer to NUM",
+			N_("set string to default"), (unsigned long)"default"),
+		OPT_STRING_LIST(0, "list", &list, N_("str"), N_("add str to list")),
+		OPT_GROUP(N_("Magic arguments")),
+		OPT_ARGUMENT("quux", N_("means --quux")),
+		OPT_NUMBER_CALLBACK(&integer, N_("set integer to NUM"),
 			number_callback),
-		{ OPTION_COUNTUP, '+', NULL, &boolean, NULL, "same as -b",
+		{ OPTION_COUNTUP, '+', NULL, &boolean, NULL, N_("same as -b"),
 		  PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_NODASH },
 		{ OPTION_COUNTUP, 0, "ambiguous", &ambiguous, NULL,
-		  "positive ambiguity", PARSE_OPT_NOARG | PARSE_OPT_NONEG },
+		  N_("positive ambiguity"), PARSE_OPT_NOARG | PARSE_OPT_NONEG },
 		{ OPTION_COUNTUP, 0, "no-ambiguous", &ambiguous, NULL,
-		  "negative ambiguity", PARSE_OPT_NOARG | PARSE_OPT_NONEG },
-		OPT_GROUP("Standard options"),
+		  N_("negative ambiguity"), PARSE_OPT_NOARG | PARSE_OPT_NONEG },
+		OPT_GROUP(N_("Standard options")),
 		OPT__ABBREV(&abbrev),
-		OPT__VERBOSE(&verbose, "be verbose"),
-		OPT__DRY_RUN(&dry_run, "dry run"),
-		OPT__QUIET(&quiet, "be quiet"),
+		OPT__VERBOSE(&verbose, N_("be verbose")),
+		OPT__DRY_RUN(&dry_run, N_("dry run")),
+		OPT__QUIET(&quiet, N_("be quiet")),
 		OPT_END(),
 	};
 	int i;
-- 
1.7.12.rc2

Re: [PATCH 0/6] Gettext poison rework

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2016-06-15 22:54:34

On Fri, Aug 24, 2012 at 7:43 AM, Nguyễn Thái Ngọc Duy [off-list ref] wrote:
Still WIP but I'm getting closer. I dropped test-poisongen and started
to use podebug [2] instead. Less code in git. podebug does not preserve
shell variables yet. I'll follow that up at upstream [1].

With this series, if you have translation toolkit installed, you could
do

    make pseudo-locale L=<your language code>
    make GETTEXT_POISON=$LANG test

podebug supports a few way of rewriting translations. Currently
"unicode" is used but you can change it via PODEBUG_OPTS

t9001 is not happy with $LANG != C though. May need to add some
prereq there.

[1] http://bugs.locamotion.org/show_bug.cgi?id=2450
[2] http://translate.sourceforge.net/wiki/toolkit/podebug
The reason I didn't do something like this to begin with is that
gettext/glibc doesn't have support for fake locales, so you'd have to
appropriate a real one for tests. It's good to see you poking the
gettext mailing list about adding support far thot.

But something like podebug gets around that quite nicely, so we can
still have the testing the poison stuff was intended for, without the
complexity of supporting it throughout all our i18n code.

Re: [PATCH 0/6] Gettext poison rework

From: Nguyen Thai Ngoc Duy <hidden>
Date: 2016-06-15 22:54:34

On Fri, Aug 24, 2012 at 3:51 PM, Ævar Arnfjörð Bjarmason
[off-list ref] wrote:
quoted
[1] http://bugs.locamotion.org/show_bug.cgi?id=2450
[2] http://translate.sourceforge.net/wiki/toolkit/podebug
The reason I didn't do something like this to begin with is that
gettext/glibc doesn't have support for fake locales, so you'd have to
appropriate a real one for tests. It's good to see you poking the
gettext mailing list about adding support far thot.
I don't see glibc getting fake locale support any time soon even if
it's more open than before. I can try to make gettext support pseudo
translations, though not sure if I can make it.
But something like podebug gets around that quite nicely, so we can
still have the testing the poison stuff was intended for, without the
complexity of supporting it throughout all our i18n code.
But yes, even if gettext does not have native support, relying on
podebug should be ok. Whatever changes we need, other projects might
too. It's better to do it outside of git.
-- 
Duy1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help