Skip to content

Commit 1e23907

Browse files
committed
Merge branch 'ab/i18n-basic'
* ab/i18n-basic: i18n: "make distclean" should clean up after "make pot" i18n: Makefile: "pot" target to extract messages marked for translation i18n: add stub Q_() wrapper for ngettext i18n: do not poison translations unless GIT_GETTEXT_POISON envvar is set i18n: add GETTEXT_POISON to simulate unfriendly translator i18n: add no-op _() and N_() wrappers commit, status: use status_printf{,_ln,_more} helpers commit: refer to commit template as s->fp wt-status: add helpers for printing wt-status lines Conflicts: builtin/commit.c
2 parents 32b31ab + 92a684b commit 1e23907

File tree

6 files changed

+93
-0
lines changed

6 files changed

+93
-0
lines changed

Makefile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ 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. 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.
223+
#
219224
# Define JSMIN to point to JavaScript minifier that functions as
220225
# a filter to have gitweb.js minified.
221226
#
@@ -316,6 +321,7 @@ INSTALL = install
316321
RPMBUILD = rpmbuild
317322
TCL_PATH = tclsh
318323
TCLTK_PATH = wish
324+
XGETTEXT = xgettext
319325
PTHREAD_LIBS = -lpthread
320326
PTHREAD_CFLAGS =
321327
GCOV = gcov
@@ -515,6 +521,7 @@ LIB_H += diff.h
515521
LIB_H += dir.h
516522
LIB_H += exec_cmd.h
517523
LIB_H += fsck.h
524+
LIB_H += gettext.h
518525
LIB_H += git-compat-util.h
519526
LIB_H += graph.h
520527
LIB_H += grep.h
@@ -1370,6 +1377,10 @@ endif
13701377
ifdef NO_SYMLINK_HEAD
13711378
BASIC_CFLAGS += -DNO_SYMLINK_HEAD
13721379
endif
1380+
ifdef GETTEXT_POISON
1381+
LIB_OBJS += gettext.o
1382+
BASIC_CFLAGS += -DGETTEXT_POISON
1383+
endif
13731384
ifdef NO_STRCASESTR
13741385
COMPAT_CFLAGS += -DNO_STRCASESTR
13751386
COMPAT_OBJS += compat/strcasestr.o
@@ -1581,6 +1592,7 @@ ifndef V
15811592
QUIET_BUILT_IN = @echo ' ' BUILTIN $@;
15821593
QUIET_GEN = @echo ' ' GEN $@;
15831594
QUIET_LNCP = @echo ' ' LN/CP $@;
1595+
QUIET_XGETTEXT = @echo ' ' XGETTEXT $@;
15841596
QUIET_GCOV = @echo ' ' GCOV $@;
15851597
QUIET_SUBDIR0 = +@subdir=
15861598
QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \
@@ -2048,6 +2060,20 @@ info:
20482060
pdf:
20492061
$(MAKE) -C Documentation pdf
20502062

2063+
XGETTEXT_FLAGS = \
2064+
--force-po \
2065+
--add-comments \
2066+
--msgid-bugs-address="Git Mailing List <[email protected]>" \
2067+
--from-code=UTF-8
2068+
XGETTEXT_FLAGS_C = $(XGETTEXT_FLAGS) --keyword=_ --keyword=N_ --language=C
2069+
LOCALIZED_C := $(C_OBJ:o=c)
2070+
2071+
po/git.pot: $(LOCALIZED_C)
2072+
$(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ $(XGETTEXT_FLAGS_C) $(LOCALIZED_C) && \
2073+
mv $@+ $@
2074+
2075+
pot: po/git.pot
2076+
20512077
$(ETAGS_TARGET): FORCE
20522078
$(RM) $(ETAGS_TARGET)
20532079
$(FIND) . -name '*.[hcS]' -print | xargs etags -a -o $(ETAGS_TARGET)
@@ -2089,6 +2115,7 @@ endif
20892115
ifdef GIT_TEST_CMP_USE_COPIED_CONTEXT
20902116
@echo GIT_TEST_CMP_USE_COPIED_CONTEXT=YesPlease >>$@
20912117
endif
2118+
@echo GETTEXT_POISON=\''$(subst ','\'',$(subst ','\'',$(GETTEXT_POISON)))'\' >>$@
20922119

20932120
### Detect Tck/Tk interpreter path changes
20942121
ifndef NO_TCLTK
@@ -2314,6 +2341,7 @@ dist-doc:
23142341

23152342
distclean: clean
23162343
$(RM) configure
2344+
$(RM) po/git.pot
23172345

23182346
clean:
23192347
$(RM) *.o block-sha1/*.o ppc/*.o compat/*.o compat/*/*.o xdiff/*.o vcs-svn/*.o \

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "strbuf.h"
66
#include "hash.h"
77
#include "advice.h"
8+
#include "gettext.h"
89

910
#include SHA1_HEADER
1011
#ifndef git_SHA_CTX

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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2010-2011 Ævar Arnfjörð Bjarmason
3+
*
4+
* This is a skeleton no-op implementation of gettext for Git.
5+
* You can replace it with something that uses libintl.h and wraps
6+
* gettext() to try out the translations.
7+
*/
8+
9+
#ifndef GETTEXT_H
10+
#define GETTEXT_H
11+
12+
#if defined(_) || defined(Q_)
13+
#error "namespace conflict: '_' or 'Q_' is pre-defined?"
14+
#endif
15+
16+
#define FORMAT_PRESERVING(n) __attribute__((format_arg(n)))
17+
18+
#ifdef GETTEXT_POISON
19+
extern int use_gettext_poison(void);
20+
#else
21+
#define use_gettext_poison() 0
22+
#endif
23+
24+
static inline FORMAT_PRESERVING(1) const char *_(const char *msgid)
25+
{
26+
return use_gettext_poison() ? "# GETTEXT POISON #" : msgid;
27+
}
28+
29+
static inline FORMAT_PRESERVING(1) FORMAT_PRESERVING(2)
30+
const char *Q_(const char *msgid, const char *plu, unsigned long n)
31+
{
32+
if (use_gettext_poison())
33+
return "# GETTEXT POISON #";
34+
return n == 1 ? msgid : plu;
35+
}
36+
37+
/* Mark msgid for translation but do not translate it. */
38+
#define N_(msgid) (msgid)
39+
40+
#endif

po/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/git.pot

t/test-lib.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,15 @@ 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+
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
1090+
10821091
# test whether the filesystem supports symbolic links
10831092
ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
10841093
rm -f y

0 commit comments

Comments
 (0)