Skip to content

Commit bb946bb

Browse files
avargitster
authored andcommitted
i18n: add GETTEXT_POISON to simulate unfriendly translator
Add a new GETTEXT_POISON compile-time parameter to make _(msg) always return gibberish. So now you can run make GETTEXT_POISON=YesPlease to get a copy of git that functions correctly (one hopes) but produces output that is in nobody's native language at all. This is a debugging aid for people who are working on the i18n part of the system, to make sure that they are not marking plumbing messages that should never be translated with _(). As new strings get marked for translation, naturally a number of tests will be broken in this mode. Tests that depend on output from Porcelain will need to be marked with the new C_LOCALE_OUTPUT test prerequisite. Newly failing tests that do not depend on output from Porcelain would be bugs due to messages that should not have been marked for translation. Note that the string we're using ("# GETTEXT POISON #") intentionally starts the pound sign. Some of Git's tests such as t3404-rebase-interactive.sh rely on interactive editing with a fake editor, and will needlessly break if the message doesn't start with something the interactive editor considers a comment. A future patch will fix fix the underlying cause of that issue by adding "#" characters to the commit advice automatically. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6578483 commit bb946bb

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ all::
216216
#
217217
# Define NO_REGEX if you have no or inferior regex support in your C library.
218218
#
219+
# 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.
221+
#
219222
# Define JSMIN to point to JavaScript minifier that functions as
220223
# a filter to have gitweb.js minified.
221224
#
@@ -1370,6 +1373,9 @@ endif
13701373
ifdef NO_SYMLINK_HEAD
13711374
BASIC_CFLAGS += -DNO_SYMLINK_HEAD
13721375
endif
1376+
ifdef GETTEXT_POISON
1377+
BASIC_CFLAGS += -DGETTEXT_POISON
1378+
endif
13731379
ifdef NO_STRCASESTR
13741380
COMPAT_CFLAGS += -DNO_STRCASESTR
13751381
COMPAT_OBJS += compat/strcasestr.o
@@ -2089,6 +2095,7 @@ endif
20892095
ifdef GIT_TEST_CMP_USE_COPIED_CONTEXT
20902096
@echo GIT_TEST_CMP_USE_COPIED_CONTEXT=YesPlease >>$@
20912097
endif
2098+
@echo GETTEXT_POISON=\''$(subst ','\'',$(subst ','\'',$(GETTEXT_POISON)))'\' >>$@
20922099

20932100
### Detect Tck/Tk interpreter path changes
20942101
ifndef NO_TCLTK

gettext.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@
1515

1616
#define FORMAT_PRESERVING(n) __attribute__((format_arg(n)))
1717

18+
#ifdef GETTEXT_POISON
19+
#define use_gettext_poison() 1
20+
#else
21+
#define use_gettext_poison() 0
22+
#endif
23+
1824
static inline FORMAT_PRESERVING(1) const char *_(const char *msgid)
1925
{
20-
return msgid;
26+
return use_gettext_poison() ? "# GETTEXT POISON #" : msgid;
2127
}
2228

2329
/* Mark msgid for translation but do not translate it. */

t/test-lib.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,9 @@ esac
10791079
test -z "$NO_PERL" && test_set_prereq PERL
10801080
test -z "$NO_PYTHON" && test_set_prereq PYTHON
10811081

1082+
# Can we rely on git's output in the C locale?
1083+
test -z "$GETTEXT_POISON" && test_set_prereq C_LOCALE_OUTPUT
1084+
10821085
# test whether the filesystem supports symbolic links
10831086
ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
10841087
rm -f y

0 commit comments

Comments
 (0)