i18n: add infrastructure for translating Git with gettext

Change the skeleton implementation of i18n in Git to one that can show localized strings to users for our C, Shell and Perl programs using either GNU libintl or the Solaris gettext implementation. This new internationalization support is enabled by default. If gettext isn't available, or if Git is compiled with NO_GETTEXT=YesPlease, Git falls back on its current behavior of showing interface messages in English. When using the autoconf script we'll auto-detect if the gettext libraries are installed and act appropriately. This change is somewhat large because as well as adding a C, Shell and Perl i18n interface we're adding a lot of tests for them, and for those tests to work we need a skeleton PO file to actually test translations. A minimal Icelandic translation is included for this purpose. Icelandic includes multi-byte characters which makes it easy to test various edge cases, and it's a language I happen to understand. The rest of the commit message goes into detail about various sub-parts of this commit. = Installation Gettext .mo files will be installed and looked for in the standard $(prefix)/share/locale path. GIT_TEXTDOMAINDIR can also be set to override that, but that's only intended to be used to test Git itself. = Perl Perl code that's to be localized should use the new Git::I18n module. It imports a __ function into the caller's package by default. Instead of using the high level Locale::TextDomain interface I've opted to use the low-level (equivalent to the C interface) Locale::Messages module, which Locale::TextDomain itself uses. Locale::TextDomain does a lot of redundant work we don't need, and some of it would potentially introduce bugs. It tries to set the $TEXTDOMAIN based on package of the caller, and has its own hardcoded paths where it'll search for messages. I found it easier just to completely avoid it rather than try to circumvent its behavior. In any case, this is an issue wholly internal Git::I18N. Its guts can be changed later if that's deemed necessary. See <AANLkTilYD_NyIZMyj9dHtVk-ylVBfvyxpCC7982LWnVd@mail.gmail.com> for a further elaboration on this topic. = Shell Shell code that's to be localized should use the git-sh-i18n library. It's basically just a wrapper for the system's gettext.sh. If gettext.sh isn't available we'll fall back on gettext(1) if it's available. The latter is available without the former on Solaris, which has its own non-GNU gettext implementation. We also need to emulate eval_gettext() there. If neither are present we'll use a dumb printf(1) fall-through wrapper. = About libcharset.h and langinfo.h We use libcharset to query the character set of the current locale if it's available. I.e. we'll use it instead of nl_langinfo if HAVE_LIBCHARSET_H is set. The GNU gettext manual recommends using langinfo.h's nl_langinfo(CODESET) to acquire the current character set, but on systems that have libcharset.h's locale_charset() using the latter is either saner, or the only option on those systems. GNU and Solaris have a nl_langinfo(CODESET), FreeBSD can use either, but MinGW and some others need to use libcharset.h's locale_charset() instead. =Credits This patch is based on work by Jeff Epler <jepler@unpythonic.net> who did the initial Makefile / C work, and a lot of comments from the Git mailing list, including Jonathan Nieder, Jakub Narebski, Johannes Sixt, Erik Faye-Lund, Peter Krefting, Junio C Hamano, Thomas Rast and others. [jc: squashed a small Makefile fix from Ramsay] Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Nov 18, 2011 at 00:14 UTC 5e9637c629702e3d41ad01d95956d1835d7338e0
37 files changed +1291 -39
Documentation/CodingGuidelines
+7
@@ -81,6 +81,10 @@ For shell scripts specifically (not exhaustive):
81 are ERE elements not BRE (note that \? and \+ are not even part
82 of BRE -- making them accessible from BRE is a GNU extension).
83
84 + - Use Git's gettext wrappers in git-sh-i18n to make the user
85 + interface translatable. See "Marking strings for translation" in
86 + po/README.
87 +
88 For C programs:
89
90 - We use tabs to indent, and interpret tabs as taking up to
@@ -144,6 +148,9 @@ For C programs:
148 - When we pass <string, length> pair to functions, we should try to
149 pass them in that order.
150
151 + - Use Git's gettext wrappers to make the user interface
152 + translatable. See "Marking strings for translation" in po/README.
153 +
154 Writing Documentation:
155
156 Every user-visible change should be reflected in the documentation.
INSTALL
+12
@@ -106,6 +106,18 @@ Issues of note:
106 history graphically, and in git-gui. If you don't want gitk or
107 git-gui, you can use NO_TCLTK.
108
109 + - A gettext library is used by default for localizing Git. The
110 + primary target is GNU libintl, but the Solaris gettext
111 + implementation also works.
112 +
113 + We need a gettext.h on the system for C code, gettext.sh (or
114 + Solaris gettext(1)) for shell scripts, and libintl-perl for Perl
115 + programs.
116 +
117 + Set NO_GETTEXT to disable localization support and make Git only
118 + use English. Under autoconf the configure script will do this
119 + automatically if it can't find libintl on the system.
120 +
121 - Some platform specific issues are dealt with Makefile rules,
122 but depending on your specific installation, you may not
123 have all the libraries/tools needed, or you may have
Makefile
+77 -4
@@ -43,6 +43,22 @@ all::
43 # Define EXPATDIR=/foo/bar if your expat header and library files are in
44 # /foo/bar/include and /foo/bar/lib directories.
45 #
46 +# Define NO_GETTEXT if you don't want Git output to be translated.
47 +# A translated Git requires GNU libintl or another gettext implementation,
48 +# plus libintl-perl at runtime.
49 +#
50 +# Define HAVE_LIBCHARSET_H if you haven't set NO_GETTEXT and you can't
51 +# trust the langinfo.h's nl_langinfo(CODESET) function to return the
52 +# current character set. GNU and Solaris have a nl_langinfo(CODESET),
53 +# FreeBSD can use either, but MinGW and some others need to use
54 +# libcharset.h's locale_charset() instead.
55 +#
56 +# Define LIBC_CONTAINS_LIBINTL if your gettext implementation doesn't
57 +# need -lintl when linking.
58 +#
59 +# Define NO_MSGFMT_EXTENDED_OPTIONS if your implementation of msgfmt
60 +# doesn't support GNU extensions like --check and --statistics
61 +#
62 # Define HAVE_PATHS_H if you have paths.h and want to use the default PATH
63 # it specifies.
64 #
@@ -301,6 +317,7 @@ gitexecdir = libexec/git-core
317 mergetoolsdir = $(gitexecdir)/mergetools
318 sharedir = $(prefix)/share
319 gitwebdir = $(sharedir)/gitweb
320 +localedir = $(sharedir)/locale
321 template_dir = share/git-core/templates
322 htmldir = share/doc/git-doc
323 ETC_GITCONFIG = $(sysconfdir)/gitconfig
@@ -309,7 +326,7 @@ lib = lib
326 # DESTDIR=
327 pathsep = :
328
312 -export prefix bindir sharedir sysconfdir gitwebdir
329 +export prefix bindir sharedir sysconfdir gitwebdir localedir
330
331 CC = gcc
332 AR = ar
@@ -322,6 +339,7 @@ RPMBUILD = rpmbuild
339 TCL_PATH = tclsh
340 TCLTK_PATH = wish
341 XGETTEXT = xgettext
342 +MSGFMT = msgfmt
343 PTHREAD_LIBS = -lpthread
344 PTHREAD_CFLAGS =
345 GCOV = gcov
@@ -621,6 +639,7 @@ LIB_OBJS += entry.o
639 LIB_OBJS += environment.o
640 LIB_OBJS += exec_cmd.o
641 LIB_OBJS += fsck.o
642 +LIB_OBJS += gettext.o
643 LIB_OBJS += graph.o
644 LIB_OBJS += grep.o
645 LIB_OBJS += hash.o
@@ -817,12 +836,14 @@ ifeq ($(uname_S),Linux)
836 NO_STRLCPY = YesPlease
837 NO_MKSTEMPS = YesPlease
838 HAVE_PATHS_H = YesPlease
839 + LIBC_CONTAINS_LIBINTL = YesPlease
840 endif
841 ifeq ($(uname_S),GNU/kFreeBSD)
842 NO_STRLCPY = YesPlease
843 NO_MKSTEMPS = YesPlease
844 HAVE_PATHS_H = YesPlease
845 DIR_HAS_BSD_GROUP_SEMANTICS = YesPlease
846 + LIBC_CONTAINS_LIBINTL = YesPlease
847 endif
848 ifeq ($(uname_S),UnixWare)
849 CC = cc
@@ -889,6 +910,7 @@ ifeq ($(uname_S),SunOS)
910 NO_MKSTEMPS = YesPlease
911 NO_REGEX = YesPlease
912 NO_FNMATCH_CASEFOLD = YesPlease
913 + NO_MSGFMT_EXTENDED_OPTIONS = YesPlease
914 ifeq ($(uname_R),5.6)
915 SOCKLEN_T = int
916 NO_HSTRERROR = YesPlease
@@ -1012,6 +1034,7 @@ ifeq ($(uname_S),GNU)
1034 NO_STRLCPY=YesPlease
1035 NO_MKSTEMPS = YesPlease
1036 HAVE_PATHS_H = YesPlease
1037 + LIBC_CONTAINS_LIBINTL = YesPlease
1038 endif
1039 ifeq ($(uname_S),IRIX)
1040 NO_SETENV = YesPlease
@@ -1228,6 +1251,7 @@ ifneq (,$(wildcard ../THIS_IS_MSYSGIT))
1251 EXTLIBS += /mingw/lib/libz.a
1252 NO_R_TO_GCC_LINKER = YesPlease
1253 INTERNAL_QSORT = YesPlease
1254 + HAVE_LIBCHARSET_H = YesPlease
1255 else
1256 NO_CURL = YesPlease
1257 endif
@@ -1405,6 +1429,11 @@ endif
1429 ifdef NEEDS_LIBGEN
1430 EXTLIBS += -lgen
1431 endif
1432 +ifndef NO_GETTEXT
1433 +ifndef LIBC_CONTAINS_LIBINTL
1434 + EXTLIBS += -lintl
1435 +endif
1436 +endif
1437 ifdef NEEDS_SOCKET
1438 EXTLIBS += -lsocket
1439 endif
@@ -1447,9 +1476,11 @@ ifdef NO_SYMLINK_HEAD
1476 BASIC_CFLAGS += -DNO_SYMLINK_HEAD
1477 endif
1478 ifdef GETTEXT_POISON
1450 - LIB_OBJS += gettext.o
1479 BASIC_CFLAGS += -DGETTEXT_POISON
1480 endif
1481 +ifdef NO_GETTEXT
1482 + BASIC_CFLAGS += -DNO_GETTEXT
1483 +endif
1484 ifdef NO_STRCASESTR
1485 COMPAT_CFLAGS += -DNO_STRCASESTR
1486 COMPAT_OBJS += compat/strcasestr.o
@@ -1612,6 +1643,10 @@ ifdef HAVE_PATHS_H
1643 BASIC_CFLAGS += -DHAVE_PATHS_H
1644 endif
1645
1646 +ifdef HAVE_LIBCHARSET_H
1647 + BASIC_CFLAGS += -DHAVE_LIBCHARSET_H
1648 +endif
1649 +
1650 ifdef DIR_HAS_BSD_GROUP_SEMANTICS
1651 COMPAT_CFLAGS += -DDIR_HAS_BSD_GROUP_SEMANTICS
1652 endif
@@ -1632,6 +1667,10 @@ ifdef GIT_TEST_CMP_USE_COPIED_CONTEXT
1667 export GIT_TEST_CMP_USE_COPIED_CONTEXT
1668 endif
1669
1670 +ifndef NO_MSGFMT_EXTENDED_OPTIONS
1671 + MSGFMT += --check --statistics
1672 +endif
1673 +
1674 ifeq ($(TCLTK_PATH),)
1675 NO_TCLTK=NoThanks
1676 endif
@@ -1662,6 +1701,7 @@ ifndef V
1701 QUIET_GEN = @echo ' ' GEN $@;
1702 QUIET_LNCP = @echo ' ' LN/CP $@;
1703 QUIET_XGETTEXT = @echo ' ' XGETTEXT $@;
1704 + QUIET_MSGFMT = @echo ' ' MSGFMT $@;
1705 QUIET_GCOV = @echo ' ' GCOV $@;
1706 QUIET_SP = @echo ' ' SP $<;
1707 QUIET_SUBDIR0 = +@subdir=
@@ -1688,6 +1728,7 @@ bindir_SQ = $(subst ','\'',$(bindir))
1728 bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
1729 mandir_SQ = $(subst ','\'',$(mandir))
1730 infodir_SQ = $(subst ','\'',$(infodir))
1731 +localedir_SQ = $(subst ','\'',$(localedir))
1732 gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
1733 template_dir_SQ = $(subst ','\'',$(template_dir))
1734 htmldir_SQ = $(subst ','\'',$(htmldir))
@@ -1743,7 +1784,7 @@ ifndef NO_TCLTK
1784 $(QUIET_SUBDIR0)gitk-git $(QUIET_SUBDIR1) all
1785 endif
1786 ifndef NO_PERL
1746 - $(QUIET_SUBDIR0)perl $(QUIET_SUBDIR1) PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' all
1787 + $(QUIET_SUBDIR0)perl $(QUIET_SUBDIR1) PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' localedir='$(localedir_SQ)' all
1788 endif
1789 ifndef NO_PYTHON
1790 $(QUIET_SUBDIR0)git_remote_helpers $(QUIET_SUBDIR1) PYTHON_PATH='$(PYTHON_PATH_SQ)' prefix='$(prefix_SQ)' all
@@ -1793,6 +1834,7 @@ sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
1834 -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
1835 -e 's|@@DIFF@@|$(DIFF_SQ)|' \
1836 -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
1837 + -e 's|@@LOCALEDIR@@|$(localedir_SQ)|g' \
1838 -e 's/@@NO_CURL@@/$(NO_CURL)/g' \
1839 -e $(BROKEN_PATH_FIX) \
1840 $@.sh >$@+
@@ -2045,6 +2087,9 @@ config.sp config.s config.o: EXTRA_CPPFLAGS = \
2087 attr.sp attr.s attr.o: EXTRA_CPPFLAGS = \
2088 -DETC_GITATTRIBUTES='"$(ETC_GITATTRIBUTES_SQ)"'
2089
2090 +gettext.sp gettext.s gettext.o: EXTRA_CPPFLAGS = \
2091 + -DGIT_LOCALE_PATH='"$(localedir_SQ)"'
2092 +
2093 http.sp http.s http.o: EXTRA_CPPFLAGS = \
2094 -DGIT_HTTP_USER_AGENT='"git/$(GIT_VERSION)"'
2095
@@ -2118,17 +2163,37 @@ XGETTEXT_FLAGS = \
2163 XGETTEXT_FLAGS_C = $(XGETTEXT_FLAGS) --language=C \
2164 --keyword=_ --keyword=N_ --keyword="Q_:1,2"
2165 XGETTEXT_FLAGS_SH = $(XGETTEXT_FLAGS) --language=Shell
2166 +XGETTEXT_FLAGS_PERL = $(XGETTEXT_FLAGS) --keyword=__ --language=Perl
2167 LOCALIZED_C := $(C_OBJ:o=c)
2168 LOCALIZED_SH := $(SCRIPT_SH)
2169 +LOCALIZED_PERL := $(SCRIPT_PERL)
2170 +
2171 +ifdef XGETTEXT_INCLUDE_TESTS
2172 +LOCALIZED_C += t/t0200/test.c
2173 +LOCALIZED_SH += t/t0200/test.sh
2174 +LOCALIZED_PERL += t/t0200/test.perl
2175 +endif
2176
2177 po/git.pot: $(LOCALIZED_C)
2178 $(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ $(XGETTEXT_FLAGS_C) $(LOCALIZED_C)
2179 $(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ --join-existing $(XGETTEXT_FLAGS_SH) \
2180 $(LOCALIZED_SH)
2181 + $(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ --join-existing $(XGETTEXT_FLAGS_PERL) \
2182 + $(LOCALIZED_PERL)
2183 mv $@+ $@
2184
2185 pot: po/git.pot
2186
2187 +POFILES := $(wildcard po/*.po)
2188 +MOFILES := $(patsubst po/%.po,po/build/locale/%/LC_MESSAGES/git.mo,$(POFILES))
2189 +
2190 +ifndef NO_GETTEXT
2191 +all:: $(MOFILES)
2192 +endif
2193 +
2194 +po/build/locale/%/LC_MESSAGES/git.mo: po/%.po
2195 + $(QUIET_MSGFMT)mkdir -p $(dir $@) && $(MSGFMT) -o $@ $<
2196 +
2197 FIND_SOURCE_FILES = ( git ls-files '*.[hcS]' 2>/dev/null || \
2198 $(FIND) . \( -name .git -type d -prune \) \
2199 -o \( -name '*.[hcS]' -type f -print \) )
@@ -2147,7 +2212,8 @@ cscope:
2212
2213 ### Detect prefix changes
2214 TRACK_CFLAGS = $(CC):$(subst ','\'',$(ALL_CFLAGS)):\
2150 - $(bindir_SQ):$(gitexecdir_SQ):$(template_dir_SQ):$(prefix_SQ)
2215 + $(bindir_SQ):$(gitexecdir_SQ):$(template_dir_SQ):$(prefix_SQ):\
2216 + $(localedir_SQ)
2217
2218 GIT-CFLAGS: FORCE
2219 @FLAGS='$(TRACK_CFLAGS)'; \
@@ -2184,6 +2250,7 @@ endif
2250 ifdef GIT_TEST_CMP_USE_COPIED_CONTEXT
2251 @echo GIT_TEST_CMP_USE_COPIED_CONTEXT=YesPlease >>$@
2252 endif
2253 + @echo NO_GETTEXT=\''$(subst ','\'',$(subst ','\'',$(NO_GETTEXT)))'\' >>$@
2254 @echo GETTEXT_POISON=\''$(subst ','\'',$(subst ','\'',$(GETTEXT_POISON)))'\' >>$@
2255
2256 ### Detect Tck/Tk interpreter path changes
@@ -2299,6 +2366,11 @@ install: all
2366 $(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
2367 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mergetools_instdir_SQ)'
2368 $(INSTALL) -m 644 mergetools/* '$(DESTDIR_SQ)$(mergetools_instdir_SQ)'
2369 +ifndef NO_GETTEXT
2370 + $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(localedir_SQ)'
2371 + (cd po/build/locale && $(TAR) cf - .) | \
2372 + (cd '$(DESTDIR_SQ)$(localedir_SQ)' && umask 022 && $(TAR) xof -)
2373 +endif
2374 ifndef NO_PERL
2375 $(MAKE) -C perl prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install
2376 $(MAKE) -C gitweb install
@@ -2435,6 +2507,7 @@ clean:
2507 $(RM) $(TEST_PROGRAMS)
2508 $(RM) -r bin-wrappers
2509 $(RM) -r $(dep_dirs)
2510 + $(RM) -r po/build/
2511 $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo common-cmds.h $(ETAGS_TARGET) tags cscope*
2512 $(RM) -r autom4te.cache
2513 $(RM) config.log config.mak.autogen config.mak.append config.status config.cache
config.mak.in
+3
@@ -35,6 +35,9 @@ NO_CURL=@NO_CURL@
35 NO_EXPAT=@NO_EXPAT@
36 NO_LIBGEN_H=@NO_LIBGEN_H@
37 HAVE_PATHS_H=@HAVE_PATHS_H@
38 +HAVE_LIBCHARSET_H=@HAVE_LIBCHARSET_H@
39 +NO_GETTEXT=@NO_GETTEXT@
40 +LIBC_CONTAINS_LIBINTL=@LIBC_CONTAINS_LIBINTL@
41 NEEDS_LIBICONV=@NEEDS_LIBICONV@
42 NEEDS_SOCKET=@NEEDS_SOCKET@
43 NEEDS_RESOLV=@NEEDS_RESOLV@
configure.ac
+19
@@ -636,6 +636,12 @@ AC_CHECK_LIB([c], [basename],
636 AC_SUBST(NEEDS_LIBGEN)
637 test -n "$NEEDS_LIBGEN" && LIBS="$LIBS -lgen"
638
639 +AC_CHECK_LIB([c], [gettext],
640 +[LIBC_CONTAINS_LIBINTL=YesPlease],
641 +[LIBC_CONTAINS_LIBINTL=])
642 +AC_SUBST(LIBC_CONTAINS_LIBINTL)
643 +test -n "$LIBC_CONTAINS_LIBINTL" || LIBS="$LIBS -lintl"
644 +
645 ## Checks for header files.
646 AC_MSG_NOTICE([CHECKS for header files])
647 #
@@ -818,6 +824,19 @@ AC_CHECK_HEADER([paths.h],
824 [HAVE_PATHS_H=])
825 AC_SUBST(HAVE_PATHS_H)
826 #
827 +# Define NO_GETTEXT if you don't want Git output to be translated.
828 +# A translated Git requires GNU libintl or another gettext implementation
829 +AC_CHECK_HEADER([libintl.h],
830 +[NO_GETTEXT=],
831 +[NO_GETTEXT=YesPlease])
832 +AC_SUBST(NO_GETTEXT)
833 +#
834 +# Define HAVE_LIBCHARSET_H if have libcharset.h
835 +AC_CHECK_HEADER([libcharset.h],
836 +[HAVE_LIBCHARSET_H=YesPlease],
837 +[HAVE_LIBCHARSET_H=])
838 +AC_SUBST(HAVE_LIBCHARSET_H)
839 +#
840 # Define NO_STRCASESTR if you don't have strcasestr.
841 GIT_CHECK_FUNC(strcasestr,
842 [NO_STRCASESTR=],
daemon.c
+2
@@ -1099,6 +1099,8 @@ int main(int argc, char **argv)
1099 struct credentials *cred = NULL;
1100 int i;
1101
1102 + git_setup_gettext();
1103 +
1104 git_extract_argv0_path(argv[0]);
1105
1106 for (i = 1; i < argc; i++) {
fast-import.c
+2
@@ -3292,6 +3292,8 @@ int main(int argc, const char **argv)
3292
3293 git_extract_argv0_path(argv[0]);
3294
3295 + git_setup_gettext();
3296 +
3297 if (argc == 2 && !strcmp(argv[1], "-h"))
3298 usage(fast_import_usage);
3299
gettext.c
+117
@@ -5,6 +5,18 @@
5 #include "git-compat-util.h"
6 #include "gettext.h"
7
8 +#ifndef NO_GETTEXT
9 +# include <locale.h>
10 +# include <libintl.h>
11 +# ifdef HAVE_LIBCHARSET_H
12 +# include <libcharset.h>
13 +# else
14 +# include <langinfo.h>
15 +# define locale_charset() nl_langinfo(CODESET)
16 +# endif
17 +#endif
18 +
19 +#ifdef GETTEXT_POISON
20 int use_gettext_poison(void)
21 {
22 static int poison_requested = -1;
@@ -12,3 +24,108 @@ int use_gettext_poison(void)
24 poison_requested = getenv("GIT_GETTEXT_POISON") ? 1 : 0;
25 return poison_requested;
26 }
27 +#endif
28 +
29 +#ifndef NO_GETTEXT
30 +static void init_gettext_charset(const char *domain)
31 +{
32 + const char *charset;
33 +
34 + /*
35 + This trick arranges for messages to be emitted in the user's
36 + requested encoding, but avoids setting LC_CTYPE from the
37 + environment for the whole program.
38 +
39 + This primarily done to avoid a bug in vsnprintf in the GNU C
40 + Library [1]. which triggered a "your vsnprintf is broken" error
41 + on Git's own repository when inspecting v0.99.6~1 under a UTF-8
42 + locale.
43 +
44 + That commit contains a ISO-8859-1 encoded author name, which
45 + the locale aware vsnprintf(3) won't interpolate in the format
46 + argument, due to mismatch between the data encoding and the
47 + locale.
48 +
49 + Even if it wasn't for that bug we wouldn't want to use LC_CTYPE at
50 + this point, because it'd require auditing all the code that uses C
51 + functions whose semantics are modified by LC_CTYPE.
52 +
53 + But only setting LC_MESSAGES as we do creates a problem, since
54 + we declare the encoding of our PO files[2] the gettext
55 + implementation will try to recode it to the user's locale, but
56 + without LC_CTYPE it'll emit something like this on 'git init'
57 + under the Icelandic locale:
58 +
59 + Bj? til t?ma Git lind ? /hlagh/.git/
60 +
61 + Gettext knows about the encoding of our PO file, but we haven't
62 + told it about the user's encoding, so all the non-US-ASCII
63 + characters get encoded to question marks.
64 +
65 + But we're in luck! We can set LC_CTYPE from the environment
66 + only while we call nl_langinfo and
67 + bind_textdomain_codeset. That suffices to tell gettext what
68 + encoding it should emit in, so it'll now say:
69 +
70 + Bjó til tóma Git lind í /hlagh/.git/
71 +
72 + And the equivalent ISO-8859-1 string will be emitted under a
73 + ISO-8859-1 locale.
74 +
75 + With this change way we get the advantages of setting LC_CTYPE
76 + (talk to the user in his language/encoding), without the major
77 + drawbacks (changed semantics for C functions we rely on).
78 +
79 + However foreign functions using other message catalogs that
80 + aren't using our neat trick will still have a problem, e.g. if
81 + we have to call perror(3):
82 +
83 + #include <stdio.h>
84 + #include <locale.h>
85 + #include <errno.h>
86 +
87 + int main(void)
88 + {
89 + setlocale(LC_MESSAGES, "");
90 + setlocale(LC_CTYPE, "C");
91 + errno = ENODEV;
92 + perror("test");
93 + return 0;
94 + }
95 +
96 + Running that will give you a message with question marks:
97 +
98 + $ LANGUAGE= LANG=de_DE.utf8 ./test
99 + test: Kein passendes Ger?t gefunden
100 +
101 + In the long term we should probably see about getting that
102 + vsnprintf bug in glibc fixed, and audit our code so it won't
103 + fall apart under a non-C locale.
104 +
105 + Then we could simply set LC_CTYPE from the environment, which would
106 + make things like the external perror(3) messages work.
107 +
108 + See t/t0203-gettext-setlocale-sanity.sh's "gettext.c" tests for
109 + regression tests.
110 +
111 + 1. http://sourceware.org/bugzilla/show_bug.cgi?id=6530
112 + 2. E.g. "Content-Type: text/plain; charset=UTF-8\n" in po/is.po
113 + */
114 + setlocale(LC_CTYPE, "");
115 + charset = locale_charset();
116 + bind_textdomain_codeset(domain, charset);
117 + setlocale(LC_CTYPE, "C");
118 +}
119 +
120 +void git_setup_gettext(void)
121 +{
122 + const char *podir = getenv("GIT_TEXTDOMAINDIR");
123 +
124 + if (!podir)
125 + podir = GIT_LOCALE_PATH;
126 + bindtextdomain("git", podir);
127 + setlocale(LC_MESSAGES, "");
128 + init_gettext_charset("git");
129 + textdomain("git");
130 +}
131 +#endif
gettext.h
+23 -2
@@ -13,8 +13,29 @@
13 #error "namespace conflict: '_' or 'Q_' is pre-defined?"
14 #endif
15
16 +#ifndef NO_GETTEXT
17 +# include <libintl.h>
18 +#else
19 +# ifdef gettext
20 +# undef gettext
21 +# endif
22 +# define gettext(s) (s)
23 +# ifdef ngettext
24 +# undef ngettext
25 +# endif
26 +# define ngettext(s, p, n) ((n == 1) ? (s) : (p))
27 +#endif
28 +
29 #define FORMAT_PRESERVING(n) __attribute__((format_arg(n)))
30
31 +#ifndef NO_GETTEXT
32 +extern void git_setup_gettext(void);
33 +#else
34 +static inline void git_setup_gettext(void)
35 +{
36 +}
37 +#endif
38 +
39 #ifdef GETTEXT_POISON
40 extern int use_gettext_poison(void);
41 #else
@@ -23,7 +44,7 @@ extern int use_gettext_poison(void);
44
45 static inline FORMAT_PRESERVING(1) const char *_(const char *msgid)
46 {
26 - return use_gettext_poison() ? "# GETTEXT POISON #" : msgid;
47 + return use_gettext_poison() ? "# GETTEXT POISON #" : gettext(msgid);
48 }
49
50 static inline FORMAT_PRESERVING(1) FORMAT_PRESERVING(2)
@@ -31,7 +52,7 @@ const char *Q_(const char *msgid, const char *plu, unsigned long n)
52 {
53 if (use_gettext_poison())
54 return "# GETTEXT POISON #";
34 - return n == 1 ? msgid : plu;
55 + return ngettext(msgid, plu, n);
56 }
57
58 /* Mark msgid for translation but do not translate it. */
git-sh-i18n.sh
+72 -28
@@ -2,47 +2,91 @@
2 #
3 # Copyright (c) 2010 Ævar Arnfjörð Bjarmason
4 #
5 -# This is a skeleton no-op implementation of gettext for Git. It'll be
6 -# replaced by something that uses gettext.sh in a future patch series.
5 +# This is Git's interface to gettext.sh. See po/README for usage
6 +# instructions.
7 +
8 +# Export the TEXTDOMAIN* data that we need for Git
9 +TEXTDOMAIN=git
10 +export TEXTDOMAIN
11 +if test -z "$GIT_TEXTDOMAINDIR"
12 +then
13 + TEXTDOMAINDIR="@@LOCALEDIR@@"
14 +else
15 + TEXTDOMAINDIR="$GIT_TEXTDOMAINDIR"
16 +fi
17 +export TEXTDOMAINDIR
18
19 if test -z "$GIT_GETTEXT_POISON"
20 then
10 - gettext () {
11 - printf "%s" "$1"
12 - }
21 + if test -z "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS" && type gettext.sh >/dev/null 2>&1
22 + then
23 + # This is GNU libintl's gettext.sh, we don't need to do anything
24 + # else than setting up the environment and loading gettext.sh
25 + GIT_INTERNAL_GETTEXT_SH_SCHEME=gnu
26 + export GIT_INTERNAL_GETTEXT_SH_SCHEME
27
14 - gettextln() {
15 - printf "%s\n" "$1"
16 - }
28 + # Try to use libintl's gettext.sh, or fall back to English if we
29 + # can't.
30 + . gettext.sh
31
18 - eval_gettext () {
19 - printf "%s" "$1" | (
20 - export PATH $(git sh-i18n--envsubst --variables "$1");
21 - git sh-i18n--envsubst "$1"
22 - )
23 - }
32 + elif test -z "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS" && test "$(gettext -h 2>&1)" = "-h"
33 + then
34 + # We don't have gettext.sh, but there's a gettext binary in our
35 + # path. This is probably Solaris or something like it which has a
36 + # gettext implementation that isn't GNU libintl.
37 + GIT_INTERNAL_GETTEXT_SH_SCHEME=solaris
38 + export GIT_INTERNAL_GETTEXT_SH_SCHEME
39
25 - eval_gettextln () {
26 - printf "%s\n" "$1" | (
27 - export PATH $(git sh-i18n--envsubst --variables "$1");
28 - git sh-i18n--envsubst "$1"
29 - )
30 - }
40 + # Solaris has a gettext(1) but no eval_gettext(1)
41 + eval_gettext () {
42 + gettext "$1" | (
43 + export PATH $(git sh-i18n--envsubst --variables "$1");
44 + git sh-i18n--envsubst "$1"
45 + )
46 + }
47 +
48 + else
49 + # Since gettext.sh isn't available we'll have to define our own
50 + # dummy pass-through functions.
51 +
52 + # Tell our tests that we don't have the real gettext.sh
53 + GIT_INTERNAL_GETTEXT_SH_SCHEME=fallthrough
54 + export GIT_INTERNAL_GETTEXT_SH_SCHEME
55 +
56 + gettext () {
57 + printf "%s" "$1"
58 + }
59 +
60 + eval_gettext () {
61 + printf "%s" "$1" | (
62 + export PATH $(git sh-i18n--envsubst --variables "$1");
63 + git sh-i18n--envsubst "$1"
64 + )
65 + }
66 + fi
67 else
68 + # Emit garbage under GETTEXT_POISON=YesPlease. Unlike the C tests
69 + # this relies on an environment variable
70 +
71 + GIT_INTERNAL_GETTEXT_SH_SCHEME=poison
72 + export GIT_INTERNAL_GETTEXT_SH_SCHEME
73 +
74 gettext () {
75 printf "%s" "# GETTEXT POISON #"
76 }
77
36 - gettextln () {
37 - printf "%s\n" "# GETTEXT POISON #"
38 - }
39 -
78 eval_gettext () {
79 printf "%s" "# GETTEXT POISON #"
80 }
43 -
44 - eval_gettextln () {
45 - printf "%s\n" "# GETTEXT POISON #"
46 - }
81 fi
82
83 +# Git-specific wrapper functions
84 +gettextln () {
85 + gettext "$1"
86 + echo
87 +}
88 +
89 +eval_gettextln () {
90 + eval_gettext "$1"
91 + echo
92 +}
git.c
+2
@@ -537,6 +537,8 @@ int main(int argc, const char **argv)
537 if (!cmd)
538 cmd = "git-help";
539
540 + git_setup_gettext();
541 +
542 /*
543 * "git-xxxx" is the same as "git xxxx", but we obviously:
544 *
http-backend.c
+2
@@ -545,6 +545,8 @@ int main(int argc, char **argv)
545 char *cmd_arg = NULL;
546 int i;
547
548 + git_setup_gettext();
549 +
550 git_extract_argv0_path(argv[0]);
551 set_die_routine(die_webcgi);
552
http-fetch.c
+2
@@ -22,6 +22,8 @@ int main(int argc, const char **argv)
22 int get_verbosely = 0;
23 int get_recover = 0;
24
25 + git_setup_gettext();
26 +
27 git_extract_argv0_path(argv[0]);
28
29 while (arg < argc && argv[arg][0] == '-') {
http-push.c
+2
@@ -1748,6 +1748,8 @@ int main(int argc, char **argv)
1748 int new_refs;
1749 struct ref *ref, *local_refs;
1750
1751 + git_setup_gettext();
1752 +
1753 git_extract_argv0_path(argv[0]);
1754
1755 repo = xcalloc(sizeof(*repo), 1);
imap-send.c
+2
@@ -1539,6 +1539,8 @@ int main(int argc, char **argv)
1539
1540 git_extract_argv0_path(argv[0]);
1541
1542 + git_setup_gettext();
1543 +
1544 if (argc != 1)
1545 usage(imap_send_usage);
1546
perl/Git/I18N.pm new
+89
@@ -0,0 +1,89 @@
1 +package Git::I18N;
2 +use 5.008;
3 +use strict;
4 +use warnings;
5 +use Exporter 'import';
6 +
7 +our @EXPORT = qw(__);
8 +our @EXPORT_OK = @EXPORT;
9 +
10 +sub __bootstrap_locale_messages {
11 + our $TEXTDOMAIN = 'git';
12 + our $TEXTDOMAINDIR = $ENV{GIT_TEXTDOMAINDIR} || '++LOCALEDIR++';
13 +
14 + require POSIX;
15 + POSIX->import(qw(setlocale));
16 + # Non-core prerequisite module
17 + require Locale::Messages;
18 + Locale::Messages->import(qw(:locale_h :libintl_h));
19 +
20 + setlocale(LC_MESSAGES(), '');
21 + setlocale(LC_CTYPE(), '');
22 + textdomain($TEXTDOMAIN);
23 + bindtextdomain($TEXTDOMAIN => $TEXTDOMAINDIR);
24 +
25 + return;
26 +}
27 +
28 +BEGIN
29 +{
30 + # Used by our test script to see if it should test fallbacks or
31 + # not.
32 + our $__HAS_LIBRARY = 1;
33 +
34 + local $@;
35 + eval {
36 + __bootstrap_locale_messages();
37 + *__ = \&Locale::Messages::gettext;
38 + 1;
39 + } or do {
40 + # Tell test.pl that we couldn't load the gettext library.
41 + $Git::I18N::__HAS_LIBRARY = 0;
42 +
43 + # Just a fall-through no-op
44 + *__ = sub ($) { $_[0] };
45 + };
46 +}
47 +
48 +1;
49 +
50 +__END__
51 +
52 +=head1 NAME
53 +
54 +Git::I18N - Perl interface to Git's Gettext localizations
55 +
56 +=head1 SYNOPSIS
57 +
58 + use Git::I18N;
59 +
60 + print __("Welcome to Git!\n");
61 +
62 + printf __("The following error occured: %s\n"), $error;
63 +
64 +=head1 DESCRIPTION
65 +
66 +Git's internal Perl interface to gettext via L<Locale::Messages>. If
67 +L<Locale::Messages> can't be loaded (it's not a core module) we
68 +provide stub passthrough fallbacks.
69 +
70 +This is a distilled interface to gettext, see C<info '(gettext)Perl'>
71 +for the full interface. This module implements only a small part of
72 +it.
73 +
74 +=head1 FUNCTIONS
75 +
76 +=head2 __($)
77 +
78 +L<Locale::Messages>'s gettext function if all goes well, otherwise our
79 +passthrough fallback function.
80 +
81 +=head1 AUTHOR
82 +
83 +E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avarab@gmail.com>
84 +
85 +=head1 COPYRIGHT
86 +
87 +Copyright 2010 E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avarab@gmail.com>
88 +
89 +=cut
perl/Makefile
+2 -1
@@ -5,6 +5,7 @@ makfile:=perl.mak
5
6 PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
7 prefix_SQ = $(subst ','\'',$(prefix))
8 +localedir_SQ = $(subst ','\'',$(localedir))
9
10 ifndef V
11 QUIET = @
@@ -38,7 +39,7 @@ $(makfile): ../GIT-CFLAGS Makefile
39 echo ' echo $(instdir_SQ)' >> $@
40 else
41 $(makfile): Makefile.PL ../GIT-CFLAGS
41 - $(PERL_PATH) $< PREFIX='$(prefix_SQ)' INSTALL_BASE=''
42 + $(PERL_PATH) $< PREFIX='$(prefix_SQ)' INSTALL_BASE='' --localedir='$(localedir_SQ)'
43 endif
44
45 # this is just added comfort for calling make directly in perl dir
perl/Makefile.PL
+13 -1
@@ -1,4 +1,12 @@
1 +use strict;
2 +use warnings;
3 use ExtUtils::MakeMaker;
4 +use Getopt::Long;
5 +
6 +# Sanity: die at first unknown option
7 +Getopt::Long::Configure qw/ pass_through /;
8 +
9 +GetOptions("localedir=s" => \my $localedir);
10
11 sub MY::postamble {
12 return <<'MAKE_FRAG';
@@ -16,7 +24,10 @@ endif
24 MAKE_FRAG
25 }
26
19 -my %pm = ('Git.pm' => '$(INST_LIBDIR)/Git.pm');
27 +my %pm = (
28 + 'Git.pm' => '$(INST_LIBDIR)/Git.pm',
29 + 'Git/I18N.pm' => '$(INST_LIBDIR)/Git/I18N.pm',
30 +);
31
32 # We come with our own bundled Error.pm. It's not in the set of default
33 # Perl modules so install it if it's not available on the system yet.
@@ -33,6 +44,7 @@ WriteMakefile(
44 NAME => 'Git',
45 VERSION_FROM => 'Git.pm',
46 PM => \%pm,
47 + PM_FILTER => qq[\$(PERL) -pe "s<\\Q++LOCALEDIR++\\E><$localedir>"],
48 MAKEFILE => 'perl.mak',
49 INSTALLSITEMAN3DIR => '$(SITEPREFIX)/share/man/man3'
50 );
po/.gitignore
+1
@@ -1 +1,2 @@
1 /git.pot
2 +/build
po/README new
+229
@@ -0,0 +1,229 @@
1 +Core GIT Translations
2 +=====================
3 +
4 +This directory holds the translations for the core of Git. This
5 +document describes how to add to and maintain these translations, and
6 +how to mark source strings for translation.
7 +
8 +
9 +Generating a .pot file
10 +----------------------
11 +
12 +The po/git.pot file contains a message catalog extracted from Git's
13 +sources. You need to generate it to add new translations with
14 +msginit(1), or update existing ones with msgmerge(1).
15 +
16 +Since the file can be automatically generated it's not checked into
17 +git.git. To generate it do, at the top-level:
18 +
19 + make pot
20 +
21 +
22 +Initializing a .po file
23 +-----------------------
24 +
25 +To add a new translation first generate git.pot (see above) and then
26 +in the po/ directory do:
27 +
28 + msginit --locale=XX
29 +
30 +Where XX is your locale, e.g. "is", "de" or "pt_BR".
31 +
32 +Then edit the automatically generated copyright info in your new XX.po
33 +to be correct, e.g. for Icelandic:
34 +
35 + @@ -1,6 +1,6 @@
36 + -# Icelandic translations for PACKAGE package.
37 + -# Copyright (C) 2010 THE PACKAGE'S COPYRIGHT HOLDER
38 + -# This file is distributed under the same license as the PACKAGE package.
39 + +# Icelandic translations for Git.
40 + +# Copyright (C) 2010 Ævar Arnfjörð Bjarmason <avarab@gmail.com>
41 + +# This file is distributed under the same license as the Git package.
42 + # Ævar Arnfjörð Bjarmason <avarab@gmail.com>, 2010.
43 +
44 +And change references to PACKAGE VERSION in the PO Header Entry to
45 +just "Git":
46 +
47 + perl -pi -e 's/(?<="Project-Id-Version: )PACKAGE VERSION/Git/' XX.po
48 +
49 +
50 +Updating a .po file
51 +-------------------
52 +
53 +If there's an existing *.po file for your language but you need to
54 +update the translation you first need to generate git.pot (see above)
55 +and then in the po/ directory do:
56 +
57 + msgmerge --add-location --backup=off -U XX.po git.pot
58 +
59 +Where XX.po is the file you want to update.
60 +
61 +Testing your changes
62 +--------------------
63 +
64 +Before you submit your changes go back to the top-level and do:
65 +
66 + make
67 +
68 +On systems with GNU gettext (i.e. not Solaris) this will compile your
69 +changed PO file with `msgfmt --check`, the --check option flags many
70 +common errors, e.g. missing printf format strings, or translated
71 +messages that deviate from the originals in whether they begin/end
72 +with a newline or not.
73 +
74 +
75 +Marking strings for translation
76 +-------------------------------
77 +
78 +Before strings can be translated they first have to be marked for
79 +translation.
80 +
81 +Git uses an internationalization interface that wraps the system's
82 +gettext library, so most of the advice in your gettext documentation
83 +(on GNU systems `info gettext` in a terminal) applies.
84 +
85 +General advice:
86 +
87 + - Don't mark everything for translation, only strings which will be
88 + read by humans (the porcelain interface) should be translated.
89 +
90 + The output from Git's plumbing utilities will primarily be read by
91 + programs and would break scripts under non-C locales if it was
92 + translated. Plumbing strings should not be translated, since
93 + they're part of Git's API.
94 +
95 + - Adjust the strings so that they're easy to translate. Most of the
96 + advice in `info '(gettext)Preparing Strings'` applies here.
97 +
98 + - If something is unclear or ambiguous you can use a "TRANSLATORS"
99 + comment to tell the translators what to make of it. These will be
100 + extracted by xgettext(1) and put in the po/*.po files, e.g. from
101 + git-am.sh:
102 +
103 + # TRANSLATORS: Make sure to include [y], [n], [e], [v] and [a]
104 + # in your translation. The program will only accept English
105 + # input at this point.
106 + gettext "Apply? [y]es/[n]o/[e]dit/[v]iew patch/[a]ccept all "
107 +
108 + Or in C, from builtin/revert.c:
109 +
110 + /* TRANSLATORS: %s will be "revert" or "cherry-pick" */
111 + die(_("%s: Unable to write new index file"), action_name(opts));
112 +
113 +We provide wrappers for C, Shell and Perl programs. Here's how they're
114 +used:
115 +
116 +C:
117 +
118 + - Include builtin.h at the top, it'll pull in in gettext.h, which
119 + defines the gettext interface. Consult with the list if you need to
120 + use gettext.h directly.
121 +
122 + - The C interface is a subset of the normal GNU gettext
123 + interface. We currently export these functions:
124 +
125 + - _()
126 +
127 + Mark and translate a string. E.g.:
128 +
129 + printf(_("HEAD is now at %s"), hex);
130 +
131 + - Q_()
132 +
133 + Mark and translate a plural string. E.g.:
134 +
135 + printf(Q_("%d commit", "%d commits", number_of_commits));
136 +
137 + This is just a wrapper for the ngettext() function.
138 +
139 + - N_()
140 +
141 + A no-op pass-through macro for marking strings inside static
142 + initializations, e.g.:
143 +
144 + static const char *reset_type_names[] = {
145 + N_("mixed"), N_("soft"), N_("hard"), N_("merge"), N_("keep"), NULL
146 + };
147 +
148 + And then, later:
149 +
150 + die(_("%s reset is not allowed in a bare repository"),
151 + _(reset_type_names[reset_type]));
152 +
153 + Here _() couldn't have statically determined what the translation
154 + string will be, but since it was already marked for translation
155 + with N_() the look-up in the message catalog will succeed.
156 +
157 +Shell:
158 +
159 + - The Git gettext shell interface is just a wrapper for
160 + gettext.sh. Import it right after git-sh-setup like this:
161 +
162 + . git-sh-setup
163 + . git-sh-i18n
164 +
165 + And then use the gettext or eval_gettext functions:
166 +
167 + # For constant interface messages:
168 + gettext "A message for the user"; echo
169 +
170 + # To interpolate variables:
171 + details="oh noes"
172 + eval_gettext "An error occured: \$details"; echo
173 +
174 + In addition we have wrappers for messages that end with a trailing
175 + newline. I.e. you could write the above as:
176 +
177 + # For constant interface messages:
178 + gettextln "A message for the user"
179 +
180 + # To interpolate variables:
181 + details="oh noes"
182 + eval_gettextln "An error occured: \$details"
183 +
184 + More documentation about the interface is available in the GNU info
185 + page: `info '(gettext)sh'`. Looking at git-am.sh (the first shell
186 + command to be translated) for examples is also useful:
187 +
188 + git log --reverse -p --grep=i18n git-am.sh
189 +
190 +Perl:
191 +
192 + - The Git::I18N module provides a limited subset of the
193 + Locale::Messages functionality, e.g.:
194 +
195 + use Git::I18N;
196 + print __("Welcome to Git!\n");
197 + printf __("The following error occured: %s\n"), $error;
198 +
199 + Run `perldoc perl/Git/I18N.pm` for more info.
200 +
201 +
202 +Testing marked strings
203 +----------------------
204 +
205 +Even if you've correctly marked porcelain strings for translation
206 +something in the test suite might still depend on the US English
207 +version of the strings, e.g. to grep some error message or other
208 +output.
209 +
210 +To smoke out issues like these Git can be compiled with gettext poison
211 +support, at the top-level:
212 +
213 + make GETTEXT_POISON=YesPlease
214 +
215 +That'll give you a git which emits gibberish on every call to
216 +gettext. It's obviously not meant to be installed, but you should run
217 +the test suite with it:
218 +
219 + cd t && prove -j 9 ./t[0-9]*.sh
220 +
221 +If tests break with it you should inspect them manually and see if
222 +what you're translating is sane, i.e. that you're not translating
223 +plumbing output.
224 +
225 +If not you should replace calls to grep with test_i18ngrep, or
226 +test_cmp calls with test_i18ncmp. If that's not enough you can skip
227 +the whole test by making it depend on the C_LOCALE_OUTPUT
228 +prerequisite. See existing test files with this prerequisite for
229 +examples.
po/is.po new
+93
@@ -0,0 +1,93 @@
1 +# Icelandic translations for Git.
2 +# Copyright (C) 2010 Ævar Arnfjörð Bjarmason <avarab@gmail.com>
3 +# This file is distributed under the same license as the Git package.
4 +# Ævar Arnfjörð Bjarmason <avarab@gmail.com>, 2010.
5 +#
6 +msgid ""
7 +msgstr ""
8 +"Project-Id-Version: Git\n"
9 +"Report-Msgid-Bugs-To: Git Mailing List <git@vger.kernel.org>\n"
10 +"POT-Creation-Date: 2010-09-20 14:44+0000\n"
11 +"PO-Revision-Date: 2010-06-05 19:06 +0000\n"
12 +"Last-Translator: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n"
13 +"Language-Team: Git Mailing List <git@vger.kernel.org>\n"
14 +"Language: is\n"
15 +"MIME-Version: 1.0\n"
16 +"Content-Type: text/plain; charset=UTF-8\n"
17 +"Content-Transfer-Encoding: 8bit\n"
18 +
19 +#. TRANSLATORS: This is a test. You don't need to translate it.
20 +#: t/t0200/test.c:5
21 +msgid "See 'git help COMMAND' for more information on a specific command."
22 +msgstr "Sjá 'git help SKIPUN' til að sjá hjálp fyrir tiltekna skipun."
23 +
24 +#. TRANSLATORS: This is a test. You don't need to translate it.
25 +#: t/t0200/test.c:10
26 +msgid "TEST: A C test string"
27 +msgstr "TILRAUN: C tilraunastrengur"
28 +
29 +#. TRANSLATORS: This is a test. You don't need to translate it.
30 +#: t/t0200/test.c:13
31 +#, c-format
32 +msgid "TEST: A C test string %s"
33 +msgstr "TILRAUN: C tilraunastrengur %s"
34 +
35 +#. TRANSLATORS: This is a test. You don't need to translate it.
36 +#: t/t0200/test.c:16
37 +#, c-format
38 +msgid "TEST: Hello World!"
39 +msgstr "TILRAUN: Halló Heimur!"
40 +
41 +#. TRANSLATORS: This is a test. You don't need to translate it.
42 +#: t/t0200/test.c:19
43 +#, c-format
44 +msgid "TEST: Old English Runes"
45 +msgstr "TILRAUN: ᚻᛖ ᚳᚹᚫᚦ ᚦᚫᛏ ᚻᛖ ᛒᚢᛞᛖ ᚩᚾ ᚦᚫᛗ ᛚᚪᚾᛞᛖ ᚾᚩᚱᚦᚹᛖᚪᚱᛞᚢᛗ ᚹᛁᚦ ᚦᚪ ᚹᛖᛥᚫ"
46 +
47 +#. TRANSLATORS: This is a test. You don't need to translate it.
48 +#: t/t0200/test.c:22
49 +#, c-format
50 +msgid "TEST: ‘single’ and “double” quotes"
51 +msgstr "TILRAUN: ‚einfaldar‘ og „tvöfaldar“ gæsalappir"
52 +
53 +#. TRANSLATORS: This is a test. You don't need to translate it.
54 +#: t/t0200/test.sh:8
55 +msgid "TEST: A Shell test string"
56 +msgstr "TILRAUN: Skeljartilraunastrengur"
57 +
58 +#. TRANSLATORS: This is a test. You don't need to translate it.
59 +#: t/t0200/test.sh:11
60 +#, sh-format
61 +msgid "TEST: A Shell test $variable"
62 +msgstr "TILRAUN: Skeljartilraunastrengur með breytunni $variable"
63 +
64 +#. TRANSLATORS: This is a test. You don't need to translate it.
65 +#: t/t0200/test.perl:8
66 +msgid "TEST: A Perl test string"
67 +msgstr "TILRAUN: Perl tilraunastrengur"
68 +
69 +#. TRANSLATORS: This is a test. You don't need to translate it.
70 +#: t/t0200/test.perl:11
71 +#, perl-format
72 +msgid "TEST: A Perl test variable %s"
73 +msgstr "TILRAUN: Perl tilraunastrengur með breytunni %s"
74 +
75 +#. TRANSLATORS: The first '%s' is either "Reinitialized
76 +#. existing" or "Initialized empty", the second " shared" or
77 +#. "", and the last '%s%s' is the verbatim directory name.
78 +#: builtin/init-db.c:355
79 +#, c-format
80 +msgid "%s%s Git repository in %s%s\n"
81 +msgstr "%s%s Git lind í %s%s\n"
82 +
83 +#: builtin/init-db.c:356
84 +msgid "Reinitialized existing"
85 +msgstr "Endurgerði"
86 +
87 +#: builtin/init-db.c:356
88 +msgid "Initialized empty"
89 +msgstr "Bjó til tóma"
90 +
91 +#: builtin/init-db.c:357
92 +msgid " shared"
93 +msgstr " sameiginlega"
shell.c
+2
@@ -137,6 +137,8 @@ int main(int argc, char **argv)
137 int devnull_fd;
138 int count;
139
140 + git_setup_gettext();
141 +
142 git_extract_argv0_path(argv[0]);
143
144 /*
show-index.c
+2
@@ -11,6 +11,8 @@ int main(int argc, char **argv)
11 unsigned int version;
12 static unsigned int top_index[256];
13
14 + git_setup_gettext();
15 +
16 if (argc != 1)
17 usage(show_index_usage);
18 if (fread(top_index, 2 * 4, 1, stdin) != 1)
t/lib-gettext.sh new
+55
@@ -0,0 +1,55 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2010 Ævar Arnfjörð Bjarmason
4 +#
5 +
6 +. ./test-lib.sh
7 +
8 +GIT_TEXTDOMAINDIR="$GIT_BUILD_DIR/po/build/locale"
9 +GIT_PO_PATH="$GIT_BUILD_DIR/po"
10 +export GIT_TEXTDOMAINDIR GIT_PO_PATH
11 +
12 +. "$GIT_BUILD_DIR"/git-sh-i18n
13 +
14 +if test_have_prereq GETTEXT && ! test_have_prereq GETTEXT_POISON
15 +then
16 + # is_IS.UTF-8 on Solaris and FreeBSD, is_IS.utf8 on Debian
17 + is_IS_locale=$(locale -a | sed -n '/^is_IS\.[uU][tT][fF]-*8$/{
18 + p
19 + q
20 + }')
21 + # is_IS.ISO8859-1 on Solaris and FreeBSD, is_IS.iso88591 on Debian
22 + is_IS_iso_locale=$(locale -a | sed -n '/^is_IS\.[iI][sS][oO]8859-*1$/{
23 + p
24 + q
25 + }')
26 +
27 + # Export them as an environment variable so the t0202/test.pl Perl
28 + # test can use it too
29 + export is_IS_locale is_IS_iso_locale
30 +
31 + if test -n "$is_IS_locale" &&
32 + test $GIT_INTERNAL_GETTEXT_SH_SCHEME != "fallthrough"
33 + then
34 + # Some of the tests need the reference Icelandic locale
35 + test_set_prereq GETTEXT_LOCALE
36 +
37 + # Exporting for t0202/test.pl
38 + GETTEXT_LOCALE=1
39 + export GETTEXT_LOCALE
40 + say "# lib-gettext: Found '$is_IS_locale' as an is_IS UTF-8 locale"
41 + else
42 + say "# lib-gettext: No is_IS UTF-8 locale available"
43 + fi
44 +
45 + if test -n "$is_IS_iso_locale" &&
46 + test $GIT_INTERNAL_GETTEXT_SH_SCHEME != "fallthrough"
47 + then
48 + # Some of the tests need the reference Icelandic locale
49 + test_set_prereq GETTEXT_ISO_LOCALE
50 +
51 + say "# lib-gettext: Found '$is_IS_iso_locale' as an is_IS ISO-8859-1 locale"
52 + else
53 + say "# lib-gettext: No is_IS ISO-8859-1 locale available"
54 + fi
55 +fi
t/t0200-gettext-basic.sh new
+108
@@ -0,0 +1,108 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2010 Ævar Arnfjörð Bjarmason
4 +#
5 +
6 +test_description='Gettext support for Git'
7 +
8 +. ./lib-gettext.sh
9 +
10 +test_expect_success "sanity: \$GIT_INTERNAL_GETTEXT_SH_SCHEME is set (to $GIT_INTERNAL_GETTEXT_SH_SCHEME)" '
11 + test -n "$GIT_INTERNAL_GETTEXT_SH_SCHEME"
12 +'
13 +
14 +test_expect_success 'sanity: $TEXTDOMAIN is git' '
15 + test $TEXTDOMAIN = "git"
16 +'
17 +
18 +test_expect_success 'xgettext sanity: Perl _() strings are not extracted' '
19 + ! grep "A Perl string xgettext will not get" "$GIT_PO_PATH"/is.po
20 +'
21 +
22 +test_expect_success 'xgettext sanity: Comment extraction with --add-comments' '
23 + grep "TRANSLATORS: This is a test" "$TEST_DIRECTORY"/t0200/* | wc -l >expect &&
24 + grep "TRANSLATORS: This is a test" "$GIT_PO_PATH"/is.po | wc -l >actual &&
25 + test_cmp expect actual
26 +'
27 +
28 +test_expect_success 'xgettext sanity: Comment extraction with --add-comments stops at statements' '
29 + ! grep "This is a phony" "$GIT_PO_PATH"/is.po &&
30 + ! grep "the above comment" "$GIT_PO_PATH"/is.po
31 +'
32 +
33 +test_expect_success GETTEXT 'sanity: $TEXTDOMAINDIR exists without NO_GETTEXT=YesPlease' '
34 + test -d "$TEXTDOMAINDIR" &&
35 + test "$TEXTDOMAINDIR" = "$GIT_TEXTDOMAINDIR"
36 +'
37 +
38 +test_expect_success GETTEXT 'sanity: Icelandic locale was compiled' '
39 + test -f "$TEXTDOMAINDIR/is/LC_MESSAGES/git.mo"
40 +'
41 +
42 +# TODO: When we have more locales, generalize this to test them
43 +# all. Maybe we'll need a dir->locale map for that.
44 +test_expect_success GETTEXT_LOCALE 'sanity: gettext("") metadata is OK' '
45 + # Return value may be non-zero
46 + LANGUAGE=is LC_ALL="$is_IS_locale" gettext "" >zero-expect &&
47 + grep "Project-Id-Version: Git" zero-expect &&
48 + grep "Git Mailing List <git@vger.kernel.org>" zero-expect &&
49 + grep "Content-Type: text/plain; charset=UTF-8" zero-expect &&
50 + grep "Content-Transfer-Encoding: 8bit" zero-expect
51 +'
52 +
53 +test_expect_success GETTEXT_LOCALE 'sanity: gettext(unknown) is passed through' '
54 + printf "This is not a translation string" >expect &&
55 + gettext "This is not a translation string" >actual &&
56 + eval_gettext "This is not a translation string" >actual &&
57 + test_cmp expect actual
58 +'
59 +
60 +# xgettext from C
61 +test_expect_success GETTEXT_LOCALE 'xgettext: C extraction of _() and N_() strings' '
62 + printf "TILRAUN: C tilraunastrengur" >expect &&
63 + printf "\n" >>expect &&
64 + printf "Sjá '\''git help SKIPUN'\'' til að sjá hjálp fyrir tiltekna skipun." >>expect &&
65 + LANGUAGE=is LC_ALL="$is_IS_locale" gettext "TEST: A C test string" >actual &&
66 + printf "\n" >>actual &&
67 + LANGUAGE=is LC_ALL="$is_IS_locale" gettext "See '\''git help COMMAND'\'' for more information on a specific command." >>actual &&
68 + test_cmp expect actual
69 +'
70 +
71 +test_expect_success GETTEXT_LOCALE 'xgettext: C extraction with %s' '
72 + printf "TILRAUN: C tilraunastrengur %%s" >expect &&
73 + LANGUAGE=is LC_ALL="$is_IS_locale" gettext "TEST: A C test string %s" >actual &&
74 + test_cmp expect actual
75 +'
76 +
77 +# xgettext from Shell
78 +test_expect_success GETTEXT_LOCALE 'xgettext: Shell extraction' '
79 + printf "TILRAUN: Skeljartilraunastrengur" >expect &&
80 + LANGUAGE=is LC_ALL="$is_IS_locale" gettext "TEST: A Shell test string" >actual &&
81 + test_cmp expect actual
82 +'
83 +
84 +test_expect_success GETTEXT_LOCALE 'xgettext: Shell extraction with $variable' '
85 + printf "TILRAUN: Skeljartilraunastrengur með breytunni a var i able" >x-expect &&
86 + LANGUAGE=is LC_ALL="$is_IS_locale" variable="a var i able" eval_gettext "TEST: A Shell test \$variable" >x-actual &&
87 + test_cmp x-expect x-actual
88 +'
89 +
90 +# xgettext from Perl
91 +test_expect_success GETTEXT_LOCALE 'xgettext: Perl extraction' '
92 + printf "TILRAUN: Perl tilraunastrengur" >expect &&
93 + LANGUAGE=is LC_ALL="$is_IS_locale" gettext "TEST: A Perl test string" >actual &&
94 + test_cmp expect actual
95 +'
96 +
97 +test_expect_success GETTEXT_LOCALE 'xgettext: Perl extraction with %s' '
98 + printf "TILRAUN: Perl tilraunastrengur með breytunni %%s" >expect &&
99 + LANGUAGE=is LC_ALL="$is_IS_locale" gettext "TEST: A Perl test variable %s" >actual &&
100 + test_cmp expect actual
101 +'
102 +
103 +test_expect_success GETTEXT_LOCALE 'sanity: Some gettext("") data for real locale' '
104 + LANGUAGE=is LC_ALL="$is_IS_locale" gettext "" >real-locale &&
105 + test -s real-locale
106 +'
107 +
108 +test_done
t/t0200/test.c new
+23
@@ -0,0 +1,23 @@
1 +/* This is a phony C program that's only here to test xgettext message extraction */
2 +
3 +const char help[] =
4 + /* TRANSLATORS: This is a test. You don't need to translate it. */
5 + N_("See 'git help COMMAND' for more information on a specific command.");
6 +
7 +int main(void)
8 +{
9 + /* TRANSLATORS: This is a test. You don't need to translate it. */
10 + puts(_("TEST: A C test string"));
11 +
12 + /* TRANSLATORS: This is a test. You don't need to translate it. */
13 + printf(_("TEST: A C test string %s"), "variable");
14 +
15 + /* TRANSLATORS: This is a test. You don't need to translate it. */
16 + printf(_("TEST: Hello World!"));
17 +
18 + /* TRANSLATORS: This is a test. You don't need to translate it. */
19 + printf(_("TEST: Old English Runes"));
20 +
21 + /* TRANSLATORS: This is a test. You don't need to translate it. */
22 + printf(_("TEST: ‘single’ and “double” quotes"));
23 +}
t/t0200/test.perl new
+14
@@ -0,0 +1,14 @@
1 +# This is a phony Perl program that's only here to test xgettext
2 +# message extraction
3 +
4 +# so the above comment won't be folded into the next one by xgettext
5 +1;
6 +
7 +# TRANSLATORS: This is a test. You don't need to translate it.
8 +print __("TEST: A Perl test string");
9 +
10 +# TRANSLATORS: This is a test. You don't need to translate it.
11 +printf __("TEST: A Perl test variable %s"), "moo";
12 +
13 +# TRANSLATORS: If you see this, Git has a bug
14 +print _"TEST: A Perl string xgettext will not get";
t/t0200/test.sh new
+14
@@ -0,0 +1,14 @@
1 +# This is a phony Shell program that's only here to test xgettext
2 +# message extraction
3 +
4 +# so the above comment won't be folded into the next one by xgettext
5 +echo
6 +
7 +# TRANSLATORS: This is a test. You don't need to translate it.
8 +gettext "TEST: A Shell test string"
9 +
10 +# TRANSLATORS: This is a test. You don't need to translate it.
11 +eval_gettext "TEST: A Shell test \$variable"
12 +
13 +# TRANSLATORS: If you see this, Git has a bug
14 +_("TEST: A Shell string xgettext won't get")
t/t0201-gettext-fallbacks.sh
+18 -2
@@ -5,8 +5,24 @@
5
6 test_description='Gettext Shell fallbacks'
7
8 -. ./test-lib.sh
9 -. "$GIT_BUILD_DIR"/git-sh-i18n
8 +GIT_INTERNAL_GETTEXT_TEST_FALLBACKS=YesPlease
9 +export GIT_INTERNAL_GETTEXT_TEST_FALLBACKS
10 +
11 +. ./lib-gettext.sh
12 +
13 +test_expect_success "sanity: \$GIT_INTERNAL_GETTEXT_SH_SCHEME is set (to $GIT_INTERNAL_GETTEXT_SH_SCHEME)" '
14 + test -n "$GIT_INTERNAL_GETTEXT_SH_SCHEME"
15 +'
16 +
17 +test_expect_success 'sanity: $GIT_INTERNAL_GETTEXT_TEST_FALLBACKS is set' '
18 + test -n "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS"
19 +'
20 +
21 +test_expect_success C_LOCALE_OUTPUT 'sanity: $GIT_INTERNAL_GETTEXT_SH_SCHEME" is fallthrough' '
22 + echo fallthrough >expect &&
23 + echo $GIT_INTERNAL_GETTEXT_SH_SCHEME >actual &&
24 + test_cmp expect actual
25 +'
26
27 test_expect_success 'gettext: our gettext() fallback has pass-through semantics' '
28 printf "test" >expect &&
t/t0202-gettext-perl.sh new
+27
@@ -0,0 +1,27 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2010 Ævar Arnfjörð Bjarmason
4 +#
5 +
6 +test_description='Perl gettext interface (Git::I18N)'
7 +
8 +. ./lib-gettext.sh
9 +
10 +if ! test_have_prereq PERL; then
11 + skip_all='skipping perl interface tests, perl not available'
12 + test_done
13 +fi
14 +
15 +"$PERL_PATH" -MTest::More -e 0 2>/dev/null || {
16 + skip_all="Perl Test::More unavailable, skipping test"
17 + test_done
18 +}
19 +
20 +# The external test will outputs its own plan
21 +test_external_has_tap=1
22 +
23 +test_external_without_stderr \
24 + 'Perl Git::I18N API' \
25 + "$PERL_PATH" "$TEST_DIRECTORY"/t0202/test.pl
26 +
27 +test_done
t/t0202/test.pl new
+110
@@ -0,0 +1,110 @@
1 +#!/usr/bin/perl
2 +use 5.008;
3 +use lib (split(/:/, $ENV{GITPERLLIB}));
4 +use strict;
5 +use warnings;
6 +use POSIX qw(:locale_h);
7 +use Test::More tests => 8;
8 +use Git::I18N;
9 +
10 +my $has_gettext_library = $Git::I18N::__HAS_LIBRARY;
11 +
12 +ok(1, "Testing Git::I18N with " .
13 + ($has_gettext_library
14 + ? (defined $Locale::Messages::VERSION
15 + ? "Locale::Messages version $Locale::Messages::VERSION"
16 + # Versions of Locale::Messages before 1.17 didn't have a
17 + # $VERSION variable.
18 + : "Locale::Messages version <1.17")
19 + : "NO Perl gettext library"));
20 +ok(1, "Git::I18N is located at $INC{'Git/I18N.pm'}");
21 +
22 +{
23 + my $exports = @Git::I18N::EXPORT;
24 + ok($exports, "sanity: Git::I18N has $exports export(s)");
25 +}
26 +is_deeply(\@Git::I18N::EXPORT, \@Git::I18N::EXPORT_OK, "sanity: Git::I18N exports everything by default");
27 +
28 +# prototypes
29 +{
30 + # Add prototypes here when modifying the public interface to add
31 + # more gettext wrapper functions.
32 + my %prototypes = (qw(
33 + __ $
34 + ));
35 + while (my ($sub, $proto) = each %prototypes) {
36 + is(prototype(\&{"Git::I18N::$sub"}), $proto, "sanity: $sub has a $proto prototype");
37 + }
38 +}
39 +
40 +# Test basic passthrough in the C locale
41 +{
42 + local $ENV{LANGUAGE} = 'C';
43 + local $ENV{LC_ALL} = 'C';
44 + local $ENV{LANG} = 'C';
45 +
46 + my ($got, $expect) = (('TEST: A Perl test string') x 2);
47 +
48 + is(__($got), $expect, "Passing a string through __() in the C locale works");
49 +}
50 +
51 +# Test a basic message on different locales
52 +SKIP: {
53 + unless ($ENV{GETTEXT_LOCALE}) {
54 + # Can't reliably test __() with a non-C locales because the
55 + # required locales may not be installed on the system.
56 + #
57 + # We test for these anyway as part of the shell
58 + # tests. Skipping these here will eliminate failures on odd
59 + # platforms with incomplete locale data.
60 +
61 + skip "GETTEXT_LOCALE must be set by lib-gettext.sh for exhaustive Git::I18N tests", 2;
62 + }
63 +
64 + # The is_IS UTF-8 locale passed from lib-gettext.sh
65 + my $is_IS_locale = $ENV{is_IS_locale};
66 +
67 + my $test = sub {
68 + my ($got, $expect, $msg, $locale) = @_;
69 + # Maybe this system doesn't have the locale we're trying to
70 + # test.
71 + my $locale_ok = setlocale(LC_ALL, $locale);
72 + is(__($got), $expect, "$msg a gettext library + <$locale> locale <$got> turns into <$expect>");
73 + };
74 +
75 + my $env_C = sub {
76 + $ENV{LANGUAGE} = 'C';
77 + $ENV{LC_ALL} = 'C';
78 + };
79 +
80 + my $env_is = sub {
81 + $ENV{LANGUAGE} = 'is';
82 + $ENV{LC_ALL} = $is_IS_locale;
83 + };
84 +
85 + # Translation's the same as the original
86 + my ($got, $expect) = (('TEST: A Perl test string') x 2);
87 +
88 + if ($has_gettext_library) {
89 + {
90 + local %ENV; $env_C->();
91 + $test->($got, $expect, "With", 'C');
92 + }
93 +
94 + {
95 + my ($got, $expect) = ($got, 'TILRAUN: Perl tilraunastrengur');
96 + local %ENV; $env_is->();
97 + $test->($got, $expect, "With", $is_IS_locale);
98 + }
99 + } else {
100 + {
101 + local %ENV; $env_C->();
102 + $test->($got, $expect, "Without", 'C');
103 + }
104 +
105 + {
106 + local %ENV; $env_is->();
107 + $test->($got, $expect, "Without", 'is');
108 + }
109 + }
110 +}
t/t0203-gettext-setlocale-sanity.sh new
+26
@@ -0,0 +1,26 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2010 Ævar Arnfjörð Bjarmason
4 +#
5 +
6 +test_description="The Git C functions aren't broken by setlocale(3)"
7 +
8 +. ./lib-gettext.sh
9 +
10 +test_expect_success 'git show a ISO-8859-1 commit under C locale' '
11 + . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
12 + test_commit "iso-c-commit" iso-under-c &&
13 + git show >out 2>err &&
14 + ! test -s err &&
15 + grep -q "iso-c-commit" out
16 +'
17 +
18 +test_expect_success GETTEXT_LOCALE 'git show a ISO-8859-1 commit under a UTF-8 locale' '
19 + . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
20 + test_commit "iso-utf8-commit" iso-under-utf8 &&
21 + LANGUAGE=is LC_ALL="$is_IS_locale" git show >out 2>err &&
22 + ! test -s err &&
23 + grep -q "iso-utf8-commit" out
24 +'
25 +
26 +test_done
t/t0204-gettext-reencode-sanity.sh new
+78
@@ -0,0 +1,78 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2010 Ævar Arnfjörð Bjarmason
4 +#
5 +
6 +test_description="Gettext reencoding of our *.po/*.mo files works"
7 +
8 +. ./lib-gettext.sh
9 +
10 +
11 +test_expect_success GETTEXT_LOCALE 'gettext: Emitting UTF-8 from our UTF-8 *.mo files / Icelandic' '
12 + printf "TILRAUN: Halló Heimur!" >expect &&
13 + LANGUAGE=is LC_ALL="$is_IS_locale" gettext "TEST: Hello World!" >actual &&
14 + test_cmp expect actual
15 +'
16 +
17 +test_expect_success GETTEXT_LOCALE 'gettext: Emitting UTF-8 from our UTF-8 *.mo files / Runes' '
18 + printf "TILRAUN: ᚻᛖ ᚳᚹᚫᚦ ᚦᚫᛏ ᚻᛖ ᛒᚢᛞᛖ ᚩᚾ ᚦᚫᛗ ᛚᚪᚾᛞᛖ ᚾᚩᚱᚦᚹᛖᚪᚱᛞᚢᛗ ᚹᛁᚦ ᚦᚪ ᚹᛖᛥᚫ" >expect &&
19 + LANGUAGE=is LC_ALL="$is_IS_locale" gettext "TEST: Old English Runes" >actual &&
20 + test_cmp expect actual
21 +'
22 +
23 +test_expect_success GETTEXT_ISO_LOCALE 'gettext: Emitting ISO-8859-1 from our UTF-8 *.mo files / Icelandic' '
24 + printf "TILRAUN: Halló Heimur!" | iconv -f UTF-8 -t ISO8859-1 >expect &&
25 + LANGUAGE=is LC_ALL="$is_IS_iso_locale" gettext "TEST: Hello World!" >actual &&
26 + test_cmp expect actual
27 +'
28 +
29 +test_expect_success GETTEXT_ISO_LOCALE 'gettext: Emitting ISO-8859-1 from our UTF-8 *.mo files / Runes' '
30 + LANGUAGE=is LC_ALL="$is_IS_iso_locale" gettext "TEST: Old English Runes" >runes &&
31 +
32 + if grep "^TEST: Old English Runes$" runes
33 + then
34 + say "Your system can not handle this complexity and returns the string as-is"
35 + else
36 + # Both Solaris and GNU libintl will return this stream of
37 + # question marks, so it is s probably portable enough
38 + printf "TILRAUN: ?? ???? ??? ?? ???? ?? ??? ????? ??????????? ??? ?? ????" >runes-expect &&
39 + test_cmp runes-expect runes
40 + fi
41 +'
42 +
43 +test_expect_success GETTEXT_LOCALE 'gettext: Fetching a UTF-8 msgid -> UTF-8' '
44 + printf "TILRAUN: ‚einfaldar‘ og „tvöfaldar“ gæsalappir" >expect &&
45 + LANGUAGE=is LC_ALL="$is_IS_locale" gettext "TEST: ‘single’ and “double” quotes" >actual &&
46 + test_cmp expect actual
47 +'
48 +
49 +# How these quotes get transliterated depends on the gettext implementation:
50 +#
51 +# Debian: ,einfaldar' og ,,tvöfaldar" [GNU libintl]
52 +# FreeBSD: `einfaldar` og "tvöfaldar" [GNU libintl]
53 +# Solaris: ?einfaldar? og ?tvöfaldar? [Solaris libintl]
54 +#
55 +# Just make sure the contents are transliterated, and don't use grep -q
56 +# so that these differences are emitted under --verbose for curious
57 +# eyes.
58 +test_expect_success GETTEXT_ISO_LOCALE 'gettext: Fetching a UTF-8 msgid -> ISO-8859-1' '
59 + LANGUAGE=is LC_ALL="$is_IS_iso_locale" gettext "TEST: ‘single’ and “double” quotes" >actual &&
60 + grep "einfaldar" actual &&
61 + grep "$(echo tvöfaldar | iconv -f UTF-8 -t ISO8859-1)" actual
62 +'
63 +
64 +test_expect_success GETTEXT_LOCALE 'gettext.c: git init UTF-8 -> UTF-8' '
65 + printf "Bjó til tóma Git lind" >expect &&
66 + LANGUAGE=is LC_ALL="$is_IS_locale" git init repo >actual &&
67 + test_when_finished "rm -rf repo" &&
68 + grep "^$(cat expect) " actual
69 +'
70 +
71 +test_expect_success GETTEXT_ISO_LOCALE 'gettext.c: git init UTF-8 -> ISO-8859-1' '
72 + printf "Bjó til tóma Git lind" >expect &&
73 + LANGUAGE=is LC_ALL="$is_IS_iso_locale" git init repo >actual &&
74 + test_when_finished "rm -rf repo" &&
75 + grep "^$(cat expect | iconv -f UTF-8 -t ISO8859-1) " actual
76 +'
77 +
78 +test_done
t/t0205-gettext-poison.sh new
+36
@@ -0,0 +1,36 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2010 Ævar Arnfjörð Bjarmason
4 +#
5 +
6 +test_description='Gettext Shell poison'
7 +
8 +. ./lib-gettext.sh
9 +
10 +test_expect_success GETTEXT_POISON "sanity: \$GIT_INTERNAL_GETTEXT_SH_SCHEME is set (to $GIT_INTERNAL_GETTEXT_SH_SCHEME)" '
11 + test -n "$GIT_INTERNAL_GETTEXT_SH_SCHEME"
12 +'
13 +
14 +test_expect_success GETTEXT_POISON 'sanity: $GIT_INTERNAL_GETTEXT_SH_SCHEME" is poison' '
15 + test "$GIT_INTERNAL_GETTEXT_SH_SCHEME" = "poison"
16 +'
17 +
18 +test_expect_success GETTEXT_POISON 'gettext: our gettext() fallback has poison semantics' '
19 + printf "# GETTEXT POISON #" >expect &&
20 + gettext "test" >actual &&
21 + test_cmp expect actual &&
22 + printf "# GETTEXT POISON #" >expect &&
23 + gettext "test more words" >actual &&
24 + test_cmp expect actual
25 +'
26 +
27 +test_expect_success GETTEXT_POISON 'eval_gettext: our eval_gettext() fallback has poison semantics' '
28 + printf "# GETTEXT POISON #" >expect &&
29 + eval_gettext "test" >actual &&
30 + test_cmp expect actual &&
31 + printf "# GETTEXT POISON #" >expect &&
32 + eval_gettext "test more words" >actual &&
33 + test_cmp expect actual
34 +'
35 +
36 +test_done
t/test-lib.sh
+3
@@ -44,6 +44,7 @@ export LANG LC_ALL PAGER TERM TZ
44 EDITOR=:
45 unset VISUAL
46 unset EMAIL
47 +unset LANGUAGE
48 unset $(perl -e '
49 my @env = keys %ENV;
50 my $ok = join("|", qw(
@@ -1113,12 +1114,14 @@ esac
1114 test -z "$NO_PERL" && test_set_prereq PERL
1115 test -z "$NO_PYTHON" && test_set_prereq PYTHON
1116 test -n "$USE_LIBPCRE" && test_set_prereq LIBPCRE
1117 +test -z "$NO_GETTEXT" && test_set_prereq GETTEXT
1118
1119 # Can we rely on git's output in the C locale?
1120 if test -n "$GETTEXT_POISON"
1121 then
1122 GIT_GETTEXT_POISON=YesPlease
1123 export GIT_GETTEXT_POISON
1124 + test_set_prereq GETTEXT_POISON
1125 else
1126 test_set_prereq C_LOCALE_OUTPUT
1127 fi
upload-pack.c
+2
@@ -784,6 +784,8 @@ int main(int argc, char **argv)
784 int i;
785 int strict = 0;
786
787 + git_setup_gettext();
788 +
789 packet_trace_identity("upload-pack");
790 git_extract_argv0_path(argv[0]);
791 read_replace_refs = 0;
wrap-for-bin.sh
+2 -1
@@ -15,7 +15,8 @@ else
15 export GIT_TEMPLATE_DIR
16 fi
17 GITPERLLIB='@@BUILD_DIR@@/perl/blib/lib'
18 +GIT_TEXTDOMAINDIR='@@BUILD_DIR@@/po/build/locale'
19 PATH='@@BUILD_DIR@@/bin-wrappers:'"$PATH"
19 -export GIT_EXEC_PATH GITPERLLIB PATH
20 +export GIT_EXEC_PATH GITPERLLIB PATH GIT_TEXTDOMAINDIR
21
22 exec "${GIT_EXEC_PATH}/@@PROG@@" "$@"