Skip to content

Commit 3095522

Browse files
jrngitster
authored andcommitted
i18n: do not poison translations unless GIT_GETTEXT_POISON envvar is set
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bb946bb commit 3095522

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@ all::
217217
# Define NO_REGEX if you have no or inferior regex support in your C library.
218218
#
219219
# Define GETTEXT_POISON if you are debugging the choice of strings marked
220-
# for translation. This will turn all strings that use gettext into gibberish.
220+
# for translation. In a GETTEXT_POISON build, you can turn all strings marked
221+
# for translation into gibberish by setting the GIT_GETTEXT_POISON variable
222+
# (to any value) in your environment.
221223
#
222224
# Define JSMIN to point to JavaScript minifier that functions as
223225
# a filter to have gitweb.js minified.
@@ -1374,6 +1376,7 @@ ifdef NO_SYMLINK_HEAD
13741376
BASIC_CFLAGS += -DNO_SYMLINK_HEAD
13751377
endif
13761378
ifdef GETTEXT_POISON
1379+
LIB_OBJS += gettext.o
13771380
BASIC_CFLAGS += -DGETTEXT_POISON
13781381
endif
13791382
ifdef NO_STRCASESTR

gettext.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) 2010 Ævar Arnfjörð Bjarmason
3+
*/
4+
5+
#include "git-compat-util.h"
6+
#include "gettext.h"
7+
8+
int use_gettext_poison(void)
9+
{
10+
static int poison_requested = -1;
11+
if (poison_requested == -1)
12+
poison_requested = getenv("GIT_GETTEXT_POISON") ? 1 : 0;
13+
return poison_requested;
14+
}

gettext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define FORMAT_PRESERVING(n) __attribute__((format_arg(n)))
1717

1818
#ifdef GETTEXT_POISON
19-
#define use_gettext_poison() 1
19+
extern int use_gettext_poison(void);
2020
#else
2121
#define use_gettext_poison() 0
2222
#endif

t/test-lib.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,13 @@ test -z "$NO_PERL" && test_set_prereq PERL
10801080
test -z "$NO_PYTHON" && test_set_prereq PYTHON
10811081

10821082
# Can we rely on git's output in the C locale?
1083-
test -z "$GETTEXT_POISON" && test_set_prereq C_LOCALE_OUTPUT
1083+
if test -n "$GETTEXT_POISON"
1084+
then
1085+
GIT_GETTEXT_POISON=YesPlease
1086+
export GIT_GETTEXT_POISON
1087+
else
1088+
test_set_prereq C_LOCALE_OUTPUT
1089+
fi
10841090

10851091
# test whether the filesystem supports symbolic links
10861092
ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS

0 commit comments

Comments
 (0)