Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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>
  • Loading branch information...
commit 5e9637c629702e3d41ad01d95956d1835d7338e0 1 parent bc1bbe0
Ævar Arnfjörð Bjarmason authored November 18, 2011 gitster committed December 05, 2011
7  Documentation/CodingGuidelines
@@ -81,6 +81,10 @@ For shell scripts specifically (not exhaustive):
81 81
      are ERE elements not BRE (note that \? and \+ are not even part
82 82
      of BRE -- making them accessible from BRE is a GNU extension).
83 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
+
84 88
 For C programs:
85 89
 
86 90
  - We use tabs to indent, and interpret tabs as taking up to
@@ -144,6 +148,9 @@ For C programs:
144 148
  - When we pass <string, length> pair to functions, we should try to
145 149
    pass them in that order.
146 150
 
  151
+ - Use Git's gettext wrappers to make the user interface
  152
+   translatable. See "Marking strings for translation" in po/README.
  153
+
147 154
 Writing Documentation:
148 155
 
149 156
  Every user-visible change should be reflected in the documentation.
12  INSTALL
@@ -106,6 +106,18 @@ Issues of note:
106 106
 	  history graphically, and in git-gui.  If you don't want gitk or
107 107
 	  git-gui, you can use NO_TCLTK.
108 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
+
109 121
  - Some platform specific issues are dealt with Makefile rules,
110 122
    but depending on your specific installation, you may not
111 123
    have all the libraries/tools needed, or you may have
81  Makefile
@@ -43,6 +43,22 @@ all::
43 43
 # Define EXPATDIR=/foo/bar if your expat header and library files are in
44 44
 # /foo/bar/include and /foo/bar/lib directories.
45 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
+#
46 62
 # Define HAVE_PATHS_H if you have paths.h and want to use the default PATH
47 63
 # it specifies.
48 64
 #
@@ -301,6 +317,7 @@ gitexecdir = libexec/git-core
301 317
 mergetoolsdir = $(gitexecdir)/mergetools
302 318
 sharedir = $(prefix)/share
303 319
 gitwebdir = $(sharedir)/gitweb
  320
+localedir = $(sharedir)/locale
304 321
 template_dir = share/git-core/templates
305 322
 htmldir = share/doc/git-doc
306 323
 ETC_GITCONFIG = $(sysconfdir)/gitconfig
@@ -309,7 +326,7 @@ lib = lib
309 326
 # DESTDIR=
310 327
 pathsep = :
311 328
 
312  
-export prefix bindir sharedir sysconfdir gitwebdir
  329
+export prefix bindir sharedir sysconfdir gitwebdir localedir
313 330
 
314 331
 CC = gcc
315 332
 AR = ar
@@ -322,6 +339,7 @@ RPMBUILD = rpmbuild
322 339
 TCL_PATH = tclsh
323 340
 TCLTK_PATH = wish
324 341
 XGETTEXT = xgettext
  342
+MSGFMT = msgfmt
325 343
 PTHREAD_LIBS = -lpthread
326 344
 PTHREAD_CFLAGS =
327 345
 GCOV = gcov
@@ -621,6 +639,7 @@ LIB_OBJS += entry.o
621 639
 LIB_OBJS += environment.o
622 640
 LIB_OBJS += exec_cmd.o
623 641
 LIB_OBJS += fsck.o
  642
+LIB_OBJS += gettext.o
624 643
 LIB_OBJS += graph.o
625 644
 LIB_OBJS += grep.o
626 645
 LIB_OBJS += hash.o
@@ -817,12 +836,14 @@ ifeq ($(uname_S),Linux)
817 836
 	NO_STRLCPY = YesPlease
818 837
 	NO_MKSTEMPS = YesPlease
819 838
 	HAVE_PATHS_H = YesPlease
  839
+	LIBC_CONTAINS_LIBINTL = YesPlease
820 840
 endif
821 841
 ifeq ($(uname_S),GNU/kFreeBSD)
822 842
 	NO_STRLCPY = YesPlease
823 843
 	NO_MKSTEMPS = YesPlease
824 844
 	HAVE_PATHS_H = YesPlease
825 845
 	DIR_HAS_BSD_GROUP_SEMANTICS = YesPlease
  846
+	LIBC_CONTAINS_LIBINTL = YesPlease
826 847
 endif
827 848
 ifeq ($(uname_S),UnixWare)
828 849
 	CC = cc
@@ -889,6 +910,7 @@ ifeq ($(uname_S),SunOS)
889 910
 	NO_MKSTEMPS = YesPlease
890 911
 	NO_REGEX = YesPlease
891 912
 	NO_FNMATCH_CASEFOLD = YesPlease
  913
+	NO_MSGFMT_EXTENDED_OPTIONS = YesPlease
892 914
 	ifeq ($(uname_R),5.6)
893 915
 		SOCKLEN_T = int
894 916
 		NO_HSTRERROR = YesPlease
@@ -1012,6 +1034,7 @@ ifeq ($(uname_S),GNU)
1012 1034
 	NO_STRLCPY=YesPlease
1013 1035
 	NO_MKSTEMPS = YesPlease
1014 1036
 	HAVE_PATHS_H = YesPlease
  1037
+	LIBC_CONTAINS_LIBINTL = YesPlease
1015 1038
 endif
1016 1039
 ifeq ($(uname_S),IRIX)
1017 1040
 	NO_SETENV = YesPlease
@@ -1228,6 +1251,7 @@ ifneq (,$(wildcard ../THIS_IS_MSYSGIT))
1228 1251
 	EXTLIBS += /mingw/lib/libz.a
1229 1252
 	NO_R_TO_GCC_LINKER = YesPlease
1230 1253
 	INTERNAL_QSORT = YesPlease
  1254
+	HAVE_LIBCHARSET_H = YesPlease
1231 1255
 else
1232 1256
 	NO_CURL = YesPlease
1233 1257
 endif
@@ -1405,6 +1429,11 @@ endif
1405 1429
 ifdef NEEDS_LIBGEN
1406 1430
 	EXTLIBS += -lgen
1407 1431
 endif
  1432
+ifndef NO_GETTEXT
  1433
+ifndef LIBC_CONTAINS_LIBINTL
  1434
+	EXTLIBS += -lintl
  1435
+endif
  1436
+endif
1408 1437
 ifdef NEEDS_SOCKET
1409 1438
 	EXTLIBS += -lsocket
1410 1439
 endif
@@ -1447,9 +1476,11 @@ ifdef NO_SYMLINK_HEAD
1447 1476
 	BASIC_CFLAGS += -DNO_SYMLINK_HEAD
1448 1477
 endif
1449 1478
 ifdef GETTEXT_POISON
1450  
-	LIB_OBJS += gettext.o
1451 1479
 	BASIC_CFLAGS += -DGETTEXT_POISON
1452 1480
 endif
  1481
+ifdef NO_GETTEXT
  1482
+	BASIC_CFLAGS += -DNO_GETTEXT
  1483
+endif
1453 1484
 ifdef NO_STRCASESTR
1454 1485
 	COMPAT_CFLAGS += -DNO_STRCASESTR
1455 1486
 	COMPAT_OBJS += compat/strcasestr.o
@@ -1612,6 +1643,10 @@ ifdef HAVE_PATHS_H
1612 1643
 	BASIC_CFLAGS += -DHAVE_PATHS_H
1613 1644
 endif
1614 1645
 
  1646
+ifdef HAVE_LIBCHARSET_H
  1647
+	BASIC_CFLAGS += -DHAVE_LIBCHARSET_H
  1648
+endif
  1649
+
1615 1650
 ifdef DIR_HAS_BSD_GROUP_SEMANTICS
1616 1651
 	COMPAT_CFLAGS += -DDIR_HAS_BSD_GROUP_SEMANTICS
1617 1652
 endif
@@ -1632,6 +1667,10 @@ ifdef GIT_TEST_CMP_USE_COPIED_CONTEXT
1632 1667
 	export GIT_TEST_CMP_USE_COPIED_CONTEXT
1633 1668
 endif
1634 1669
 
  1670
+ifndef NO_MSGFMT_EXTENDED_OPTIONS
  1671
+	MSGFMT += --check --statistics
  1672
+endif
  1673
+
1635 1674
 ifeq ($(TCLTK_PATH),)
1636 1675
 NO_TCLTK=NoThanks
1637 1676
 endif
@@ -1662,6 +1701,7 @@ ifndef V
1662 1701
 	QUIET_GEN      = @echo '   ' GEN $@;
1663 1702
 	QUIET_LNCP     = @echo '   ' LN/CP $@;
1664 1703
 	QUIET_XGETTEXT = @echo '   ' XGETTEXT $@;
  1704
+	QUIET_MSGFMT   = @echo '   ' MSGFMT $@;
1665 1705
 	QUIET_GCOV     = @echo '   ' GCOV $@;
1666 1706
 	QUIET_SP       = @echo '   ' SP $<;
1667 1707
 	QUIET_SUBDIR0  = +@subdir=
@@ -1688,6 +1728,7 @@ bindir_SQ = $(subst ','\'',$(bindir))
1688 1728
 bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
1689 1729
 mandir_SQ = $(subst ','\'',$(mandir))
1690 1730
 infodir_SQ = $(subst ','\'',$(infodir))
  1731
+localedir_SQ = $(subst ','\'',$(localedir))
1691 1732
 gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
1692 1733
 template_dir_SQ = $(subst ','\'',$(template_dir))
1693 1734
 htmldir_SQ = $(subst ','\'',$(htmldir))
@@ -1743,7 +1784,7 @@ ifndef NO_TCLTK
1743 1784
 	$(QUIET_SUBDIR0)gitk-git $(QUIET_SUBDIR1) all
1744 1785
 endif
1745 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
1747 1788
 endif
1748 1789
 ifndef NO_PYTHON
1749 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)|' \
1793 1834
     -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
1794 1835
     -e 's|@@DIFF@@|$(DIFF_SQ)|' \
1795 1836
     -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
  1837
+    -e 's|@@LOCALEDIR@@|$(localedir_SQ)|g' \
1796 1838
     -e 's/@@NO_CURL@@/$(NO_CURL)/g' \
1797 1839
     -e $(BROKEN_PATH_FIX) \
1798 1840
     $@.sh >$@+
@@ -2045,6 +2087,9 @@ config.sp config.s config.o: EXTRA_CPPFLAGS = \
2045 2087
 attr.sp attr.s attr.o: EXTRA_CPPFLAGS = \
2046 2088
 	-DETC_GITATTRIBUTES='"$(ETC_GITATTRIBUTES_SQ)"'
2047 2089
 
  2090
+gettext.sp gettext.s gettext.o: EXTRA_CPPFLAGS = \
  2091
+	-DGIT_LOCALE_PATH='"$(localedir_SQ)"'
  2092
+
2048 2093
 http.sp http.s http.o: EXTRA_CPPFLAGS = \
2049 2094
 	-DGIT_HTTP_USER_AGENT='"git/$(GIT_VERSION)"'
2050 2095
 
@@ -2118,17 +2163,37 @@ XGETTEXT_FLAGS = \
2118 2163
 XGETTEXT_FLAGS_C = $(XGETTEXT_FLAGS) --language=C \
2119 2164
 	--keyword=_ --keyword=N_ --keyword="Q_:1,2"
2120 2165
 XGETTEXT_FLAGS_SH = $(XGETTEXT_FLAGS) --language=Shell
  2166
+XGETTEXT_FLAGS_PERL = $(XGETTEXT_FLAGS) --keyword=__ --language=Perl
2121 2167
 LOCALIZED_C := $(C_OBJ:o=c)
2122 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
2123 2176
 
2124 2177
 po/git.pot: $(LOCALIZED_C)
2125 2178
 	$(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ $(XGETTEXT_FLAGS_C) $(LOCALIZED_C)
2126 2179
 	$(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ --join-existing $(XGETTEXT_FLAGS_SH) \
2127 2180
 		$(LOCALIZED_SH)
  2181
+	$(QUIET_XGETTEXT)$(XGETTEXT) -o$@+ --join-existing $(XGETTEXT_FLAGS_PERL) \
  2182
+		$(LOCALIZED_PERL)
2128 2183
 	mv $@+ $@
2129 2184
 
2130 2185
 pot: po/git.pot
2131 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
+
2132 2197
 FIND_SOURCE_FILES = ( git ls-files '*.[hcS]' 2>/dev/null || \
2133 2198
 			$(FIND) . \( -name .git -type d -prune \) \
2134 2199
 				-o \( -name '*.[hcS]' -type f -print \) )
@@ -2147,7 +2212,8 @@ cscope:
2147 2212
 
2148 2213
 ### Detect prefix changes
2149 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)
2151 2217
 
2152 2218
 GIT-CFLAGS: FORCE
2153 2219
 	@FLAGS='$(TRACK_CFLAGS)'; \
@@ -2184,6 +2250,7 @@ endif
2184 2250
 ifdef GIT_TEST_CMP_USE_COPIED_CONTEXT
2185 2251
 	@echo GIT_TEST_CMP_USE_COPIED_CONTEXT=YesPlease >>$@
2186 2252
 endif
  2253
+	@echo NO_GETTEXT=\''$(subst ','\'',$(subst ','\'',$(NO_GETTEXT)))'\' >>$@
2187 2254
 	@echo GETTEXT_POISON=\''$(subst ','\'',$(subst ','\'',$(GETTEXT_POISON)))'\' >>$@
2188 2255
 
2189 2256
 ### Detect Tck/Tk interpreter path changes
@@ -2299,6 +2366,11 @@ install: all
2299 2366
 	$(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
2300 2367
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(mergetools_instdir_SQ)'
2301 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
2302 2374
 ifndef NO_PERL
2303 2375
 	$(MAKE) -C perl prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install
2304 2376
 	$(MAKE) -C gitweb install
@@ -2435,6 +2507,7 @@ clean:
2435 2507
 	$(RM) $(TEST_PROGRAMS)
2436 2508
 	$(RM) -r bin-wrappers
2437 2509
 	$(RM) -r $(dep_dirs)
  2510
+	$(RM) -r po/build/
2438 2511
 	$(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo common-cmds.h $(ETAGS_TARGET) tags cscope*
2439 2512
 	$(RM) -r autom4te.cache
2440 2513
 	$(RM) config.log config.mak.autogen config.mak.append config.status config.cache
3  config.mak.in
@@ -35,6 +35,9 @@ NO_CURL=@NO_CURL@
35 35
 NO_EXPAT=@NO_EXPAT@
36 36
 NO_LIBGEN_H=@NO_LIBGEN_H@
37 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@
38 41
 NEEDS_LIBICONV=@NEEDS_LIBICONV@
39 42
 NEEDS_SOCKET=@NEEDS_SOCKET@
40 43
 NEEDS_RESOLV=@NEEDS_RESOLV@
19  configure.ac
@@ -636,6 +636,12 @@ AC_CHECK_LIB([c], [basename],
636 636
 AC_SUBST(NEEDS_LIBGEN)
637 637
 test -n "$NEEDS_LIBGEN" && LIBS="$LIBS -lgen"
638 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
+
639 645
 ## Checks for header files.
640 646
 AC_MSG_NOTICE([CHECKS for header files])
641 647
 #
@@ -818,6 +824,19 @@ AC_CHECK_HEADER([paths.h],
818 824
 [HAVE_PATHS_H=])
819 825
 AC_SUBST(HAVE_PATHS_H)
820 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
+#
821 840
 # Define NO_STRCASESTR if you don't have strcasestr.
822 841
 GIT_CHECK_FUNC(strcasestr,
823 842
 [NO_STRCASESTR=],
2  daemon.c
@@ -1099,6 +1099,8 @@ int main(int argc, char **argv)
1099 1099
 	struct credentials *cred = NULL;
1100 1100
 	int i;
1101 1101
 
  1102
+	git_setup_gettext();
  1103
+
1102 1104
 	git_extract_argv0_path(argv[0]);
1103 1105
 
1104 1106
 	for (i = 1; i < argc; i++) {
2  fast-import.c
@@ -3292,6 +3292,8 @@ int main(int argc, const char **argv)
3292 3292
 
3293 3293
 	git_extract_argv0_path(argv[0]);
3294 3294
 
  3295
+	git_setup_gettext();
  3296
+
3295 3297
 	if (argc == 2 && !strcmp(argv[1], "-h"))
3296 3298
 		usage(fast_import_usage);
3297 3299
 
117  gettext.c
@@ -5,6 +5,18 @@
5 5
 #include "git-compat-util.h"
6 6
 #include "gettext.h"
7 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
8 20
 int use_gettext_poison(void)
9 21
 {
10 22
 	static int poison_requested = -1;
@@ -12,3 +24,108 @@ int use_gettext_poison(void)
12 24
 		poison_requested = getenv("GIT_GETTEXT_POISON") ? 1 : 0;
13 25
 	return poison_requested;
14 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
25  gettext.h
@@ -13,8 +13,29 @@
13 13
 #error "namespace conflict: '_' or 'Q_' is pre-defined?"
14 14
 #endif
15 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
+
16 29
 #define FORMAT_PRESERVING(n) __attribute__((format_arg(n)))
17 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
+
18 39
 #ifdef GETTEXT_POISON
19 40
 extern int use_gettext_poison(void);
20 41
 #else
@@ -23,7 +44,7 @@ extern int use_gettext_poison(void);
23 44
 
24 45
 static inline FORMAT_PRESERVING(1) const char *_(const char *msgid)
25 46
 {
26  
-	return use_gettext_poison() ? "# GETTEXT POISON #" : msgid;
  47
+	return use_gettext_poison() ? "# GETTEXT POISON #" : gettext(msgid);
27 48
 }
28 49
 
29 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)
31 52
 {
32 53
 	if (use_gettext_poison())
33 54
 		return "# GETTEXT POISON #";
34  
-	return n == 1 ? msgid : plu;
  55
+	return ngettext(msgid, plu, n);
35 56
 }
36 57
 
37 58
 /* Mark msgid for translation but do not translate it. */
100  git-sh-i18n.sh
@@ -2,47 +2,91 @@
2 2
 #
3 3
 # Copyright (c) 2010 Ævar Arnfjörð Bjarmason
4 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
7 18
 
8 19
 if test -z "$GIT_GETTEXT_POISON"
9 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
13 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
17 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
24 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
31 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
+
32 74
 	gettext () {
33 75
 		printf "%s" "# GETTEXT POISON #"
34 76
 	}
35 77
 
36  
-	gettextln () {
37  
-		printf "%s\n" "# GETTEXT POISON #"
38  
-	}
39  
-
40 78
 	eval_gettext () {
41 79
 		printf "%s" "# GETTEXT POISON #"
42 80
 	}
43  
-
44  
-	eval_gettextln () {
45  
-		printf "%s\n" "# GETTEXT POISON #"
46  
-	}
47 81
 fi
48 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
+}
2  git.c
@@ -537,6 +537,8 @@ int main(int argc, const char **argv)
537 537
 	if (!cmd)
538 538
 		cmd = "git-help";
539 539
 
  540
+	git_setup_gettext();
  541
+
540 542
 	/*
541 543
 	 * "git-xxxx" is the same as "git xxxx", but we obviously:
542 544
 	 *
2  http-backend.c
@@ -545,6 +545,8 @@ int main(int argc, char **argv)
545 545
 	char *cmd_arg = NULL;
546 546
 	int i;
547 547
 
  548
+	git_setup_gettext();
  549
+
548 550
 	git_extract_argv0_path(argv[0]);
549 551
 	set_die_routine(die_webcgi);
550 552
 
2  http-fetch.c
@@ -22,6 +22,8 @@ int main(int argc, const char **argv)
22 22
 	int get_verbosely = 0;
23 23
 	int get_recover = 0;
24 24
 
  25
+	git_setup_gettext();
  26
+
25 27
 	git_extract_argv0_path(argv[0]);
26 28
 
27 29
 	while (arg < argc && argv[arg][0] == '-') {
2  http-push.c
@@ -1748,6 +1748,8 @@ int main(int argc, char **argv)
1748 1748
 	int new_refs;
1749 1749
 	struct ref *ref, *local_refs;
1750 1750
 
  1751
+	git_setup_gettext();
  1752
+
1751 1753
 	git_extract_argv0_path(argv[0]);
1752 1754
 
1753 1755
 	repo = xcalloc(sizeof(*repo), 1);
2  imap-send.c
@@ -1539,6 +1539,8 @@ int main(int argc, char **argv)
1539 1539
 
1540 1540
 	git_extract_argv0_path(argv[0]);
1541 1541
 
  1542
+	git_setup_gettext();
  1543
+
1542 1544
 	if (argc != 1)
1543 1545
 		usage(imap_send_usage);
1544 1546
 
89  perl/Git/I18N.pm
... ...
@@ -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
3  perl/Makefile
@@ -5,6 +5,7 @@ makfile:=perl.mak
5 5
 
6 6
 PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
7 7
 prefix_SQ = $(subst ','\'',$(prefix))
  8
+localedir_SQ = $(subst ','\'',$(localedir))
8 9
 
9 10
 ifndef V
10 11
 	QUIET = @
@@ -38,7 +39,7 @@ $(makfile): ../GIT-CFLAGS Makefile
38 39
 	echo '	echo $(instdir_SQ)' >> $@
39 40
 else
40 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)'
42 43
 endif
43 44
 
44 45
 # this is just added comfort for calling make directly in perl dir
14  perl/Makefile.PL
... ...
@@ -1,4 +1,12 @@
  1
+use strict;
  2
+use warnings;
1 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);
2 10
 
3 11
 sub MY::postamble {
4 12
 	return <<'MAKE_FRAG';
@@ -16,7 +24,10 @@ endif
16 24
 MAKE_FRAG
17 25
 }
18 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
+);
20 31
 
21 32
 # We come with our own bundled Error.pm. It's not in the set of default
22 33
 # Perl modules so install it if it's not available on the system yet.
@@ -33,6 +44,7 @@ WriteMakefile(
33 44
 	NAME            => 'Git',
34 45
 	VERSION_FROM    => 'Git.pm',
35 46
 	PM		=> \%pm,
  47
+	PM_FILTER	=> qq[\$(PERL) -pe "s<\\Q++LOCALEDIR++\\E><$localedir>"],
36 48
 	MAKEFILE	=> 'perl.mak',
37 49
 	INSTALLSITEMAN3DIR => '$(SITEPREFIX)/share/man/man3'
38 50
 );
1  po/.gitignore
... ...
@@ -1 +1,2 @@
1 1
 /git.pot
  2
+/build
229  po/README
... ...
@@ -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.
93  po/is.po
... ...
@@ -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"
2  shell.c