{"thread":{"id":"24020","subject":"[PATCH/RFC v8 0/2] Gettext support for Git","startedAt":"2010-06-05T21:12:51Z","lastAt":"2010-06-05T21:35:29Z","messageCount":5,"participants":["Ævar Arnfjörð Bjarmason","Jakub Narebski"],"isPatch":true,"patchVersion":8,"patchTotal":2},"messages":[{"id":"143060","messageId":"1275772373-26718-1-git-send-email-avarab@gmail.com","threadId":"24020","inReplyTo":null,"subject":"[PATCH/RFC v8 0/2] Gettext support for Git","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-06-05T21:12:51Z","receivedAt":"2010-06-05T21:12:51Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"This is version 8 of the series to make Git optionally translatable\nwith GNU gettext.\n\nChanges since version 7:\n\n   Incorporated a bunch of suggestions and fixes from Jonathan Nieder\n   and Jakub Narebski, thanks for those. Added some changes of my own\n   too.\n\n   * Don't compile gettext.c at all when NO_GETTEXT is defined. Just\n     define a stub function in gettext.h\n\n   * Add back support (and a new test) for the no-op N_() macro. This\n     is used for marking translations for later use, e.g.:\n        \n        const char help[] =\n        \tN_(\"See 'git help COMMAND' for more information on a specific command.\");\n        \n        int main(void)\n        {\n            puts(_(help));\n\n   * Define NEEDS_LIBINTL depending on whether gettext is in the C\n     library when running the autoconf script. Tested on Debian and\n     FreeBSD.\n\n   * Add the git_setup_gettext() initialization function to all\n     $(PROGRAM_OBJS). This enables translation of git-imap-send,\n     git-daemon and others that don't use git.c's main function.\n\n   * Define git_setup_gettext as returning `extern void' instead of\n     `void' as suggested by Jonathan Nieder.\n\n   * Update is.po whose comments hadn't been updated for the t/\n     directory renaming done in an earlier patch version.\n\n   * rebase the series so that the two two patches now work\n     stand-alone. Some tests meant for the second patch had crept into\n     the first one during earlier rebases.\n\nHere's the diff --stat since v7:\n    \n     Makefile           |    4 +++-\n     config.mak.in      |    1 +\n     configure.ac       |    6 ++++++\n     daemon.c           |    3 +++\n     fast-import.c      |    3 +++\n     gettext.c          |    6 +-----\n     gettext.h          |    7 ++++++-\n     http-backend.c     |    3 +++\n     http-fetch.c       |    3 +++\n     http-push.c        |    3 +++\n     imap-send.c        |    3 +++\n     po/is.po           |   25 +++++++++++++------------\n     shell.c            |    3 +++\n     show-index.c       |    3 +++\n     t/t0200-gettext.sh |    6 +++++-\n     t/t0200/test.c     |    4 ++++\n     upload-pack.c      |    3 +++\n     17 files changed, 66 insertions(+), 20 deletions(-)\n    \nÆvar Arnfjörð Bjarmason (2):\n  Add infrastructure for translating Git with gettext\n  Add initial C, Shell and Perl gettext translations\n\n .gitignore                   |    2 +\n INSTALL                      |    8 ++\n Makefile                     |   69 ++++++++++++++++++-\n config.mak.in                |    2 +\n configure.ac                 |   12 +++\n daemon.c                     |    3 +\n fast-import.c                |    3 +\n gettext.c                    |   21 ++++++\n gettext.h                    |   18 +++++\n git-pull.sh                  |   16 +++--\n git-send-email.perl          |    3 +-\n git-sh-i18n.sh               |   47 +++++++++++++\n git.c                        |    3 +\n http-backend.c               |    3 +\n http-fetch.c                 |    3 +\n http-push.c                  |    3 +\n imap-send.c                  |    3 +\n perl/Git/I18N.pm             |   91 +++++++++++++++++++++++++\n perl/Makefile                |    3 +-\n perl/Makefile.PL             |   14 ++++-\n po/.gitignore                |    1 +\n po/is.po                     |   70 +++++++++++++++++++\n shell.c                      |    3 +\n show-index.c                 |    3 +\n t/t0200-gettext.sh           |  154 ++++++++++++++++++++++++++++++++++++++++++\n t/t0200/test.c               |   14 ++++\n t/t0200/test.perl            |   14 ++++\n t/t0200/test.sh              |   14 ++++\n t/t0201-gettext-fallbacks.sh |   42 +++++++++++\n t/t0202-gettext-perl.sh      |   20 ++++++\n t/t0202/test.pl              |  104 ++++++++++++++++++++++++++++\n t/test-lib.sh                |    2 +\n upload-pack.c                |    3 +\n wt-status.c                  |  107 +++++++++++++++--------------\n 34 files changed, 813 insertions(+), 65 deletions(-)\n create mode 100644 gettext.c\n create mode 100644 gettext.h\n create mode 100644 git-sh-i18n.sh\n create mode 100644 perl/Git/I18N.pm\n create mode 100644 po/.gitignore\n create mode 100644 po/is.po\n create mode 100755 t/t0200-gettext.sh\n create mode 100644 t/t0200/test.c\n create mode 100644 t/t0200/test.perl\n create mode 100644 t/t0200/test.sh\n create mode 100755 t/t0201-gettext-fallbacks.sh\n create mode 100755 t/t0202-gettext-perl.sh\n create mode 100644 t/t0202/test.pl\n"},{"id":"143061","messageId":"1275772373-26718-2-git-send-email-avarab@gmail.com","threadId":"24020","inReplyTo":"1275772373-26718-1-git-send-email-avarab@gmail.com","subject":"[PATCH/RFC v8 1/2] Add infrastructure for translating Git with gettext","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-06-05T21:12:52Z","receivedAt":"2010-06-05T21:12:52Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"All of the interface messages in Git core are currently hardcoded in\nEnglish. Change that by optionally enabling translation of the core C,\nShell and Perl programs via GNU gettext. If you set the appropriate\nLC_* variables Git will speak your language, provided that someone has\nsubmitted a translation.\n\nIf gettext isn't available, or if Git is compiled with\nNO_GETTEXT=YesPlease, then Git fall back on its previous behavior of\nonly speaking English.\n\nWith NO_GETTEXT=YesPlease gettext support will be #defined away for C\nprograms. For Shell and Perl programs we rely on the git message\ncatalog not being avalalable. That's a reasonable assumption since the\n*.po files won't be installed on the system during make install.\n\nThe gettext wrappers that are provided in the patch are only the bare\nminimum required to begin translation work. In particular I haven't\nadded wrappers for the gettext functions that enable plural support,\nor those that provide message context (msgctxt). Those can be added\nlater. The intent is to start with a small subset and see what we need\nlater, not to start with something that's unnecessarily large right\naway.\n\nImplementation and usage notes:\n\n * General:\n\n   Gettext .mo files will be installed and looked for in the standard\n   $(prefix)/share/locale path. GIT_TEXTDOMAINDIR can also be set to\n   override that. But this is only intended to be used to test Git\n   itself.\n\n * Perl:\n\n   Perl code that wants to be localized should use the new Git::I18n\n   module. It imports a __ function into the caller's package by\n   default.\n\n   Instead of using the high level Locale::TextDomain interface I've\n   opted to use the low-level (equivalent to the C interface)\n   Locale::Messages module, which Locale::TextDomain itself uses.\n\n   Locale::TextDomain does a lot of redundant work we don't need, and\n   some of it would potentially introduce bugs. It tries to set the\n   $TEXTDOMAIN based on package of the caller, and has its own\n   hardcoded paths where it'll search for messages.\n\n   I found it easier just to completely avoid it rather than try to\n   circumvent its behavior. In any case, this is an issue wholly\n   internal Git::I18N. Its guts can be changed later if that's deemed\n   necessary.\n\n * Shell:\n\n   Shell code that wants to be localized should use the new\n   git-sh-i18n library. It's just a wrapper for the system's\n   gettext.sh.\n\n   If gettext.sh isn't available we'll fall back on a dumb\n   printf(1)-powered fall-through wrapper.\n\n   I originally tried to detect if the system supported `echo -n' but\n   I found this to be a waste of time. My benchmarks on Linux, Solaris\n   and FreeBSD reveal that printf(1) is fast enough, especially since\n   we aren't calling gettext() from within any tight loops.\n\nThis patch is based on work by Jeff Epler <jepler@unpythonic.net> who\ndid the initial Makefile / C work, and a lot of comments from the Git\nmailing list.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n .gitignore                   |    2 +\n INSTALL                      |    8 +++\n Makefile                     |   69 ++++++++++++++++++++++-\n config.mak.in                |    2 +\n configure.ac                 |   12 ++++\n daemon.c                     |    3 +\n fast-import.c                |    3 +\n gettext.c                    |   21 +++++++\n gettext.h                    |   18 ++++++\n git-sh-i18n.sh               |   47 ++++++++++++++++\n git.c                        |    3 +\n http-backend.c               |    3 +\n http-fetch.c                 |    3 +\n http-push.c                  |    3 +\n imap-send.c                  |    3 +\n perl/Git/I18N.pm             |   91 ++++++++++++++++++++++++++++++\n perl/Makefile                |    3 +-\n perl/Makefile.PL             |   14 ++++-\n po/.gitignore                |    1 +\n po/is.po                     |   47 ++++++++++++++++\n shell.c                      |    3 +\n show-index.c                 |    3 +\n t/t0200-gettext.sh           |  126 ++++++++++++++++++++++++++++++++++++++++++\n t/t0200/test.c               |   14 +++++\n t/t0200/test.perl            |   14 +++++\n t/t0200/test.sh              |   14 +++++\n t/t0201-gettext-fallbacks.sh |   42 ++++++++++++++\n t/t0202-gettext-perl.sh      |   20 +++++++\n t/t0202/test.pl              |  104 ++++++++++++++++++++++++++++++++++\n t/test-lib.sh                |    2 +\n upload-pack.c                |    3 +\n 31 files changed, 697 insertions(+), 4 deletions(-)\n create mode 100644 gettext.c\n create mode 100644 gettext.h\n create mode 100644 git-sh-i18n.sh\n create mode 100644 perl/Git/I18N.pm\n create mode 100644 po/.gitignore\n create mode 100644 po/is.po\n create mode 100755 t/t0200-gettext.sh\n create mode 100644 t/t0200/test.c\n create mode 100644 t/t0200/test.perl\n create mode 100644 t/t0200/test.sh\n create mode 100755 t/t0201-gettext-fallbacks.sh\n create mode 100755 t/t0202-gettext-perl.sh\n create mode 100644 t/t0202/test.pl\n\ndiff --git a/.gitignore b/.gitignore\nindex 14e2b6b..6c2b193 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -125,6 +125,7 @@\n /git-rm\n /git-send-email\n /git-send-pack\n+/git-sh-i18n\n /git-sh-setup\n /git-shell\n /git-shortlog\n@@ -204,3 +205,4 @@\n *.pdb\n /Debug/\n /Release/\n+/share/\ndiff --git a/INSTALL b/INSTALL\nindex 61086ab..f30d5bd 100644\n--- a/INSTALL\n+++ b/INSTALL\n@@ -93,6 +93,14 @@ Issues of note:\n \t  history graphically, and in git-gui.  If you don't want gitk or\n \t  git-gui, you can use NO_TCLTK.\n \n+\t- The GNU \"libintl\" library is used by default for localizing\n+\t  Git. It needs a gettext.h on the system for C code, gettext.sh\n+\t  for shell scripts, and libintl-perl for Perl programs.\n+\n+\t  Set NO_GETTEXT to disable localization support and make Git only\n+\t  use English. Under autoconf the configure script will do this\n+\t  automatically if it can't find libintl on the system.\n+\n  - Some platform specific issues are dealt with Makefile rules,\n    but depending on your specific installation, you may not\n    have all the libraries/tools needed, or you may have\ndiff --git a/Makefile b/Makefile\nindex d5d6565..0ddf6e8 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -28,6 +28,15 @@ all::\n # Define NO_EXPAT if you do not have expat installed.  git-http-push is\n # not built, and you cannot push using http:// and https:// transports.\n #\n+# Define NO_GETTEXT if you don't want to build with Git with gettext\n+# support. Building it requires GNU libintl, and additionally\n+# libintl-perl at runtime.\n+#\n+# Define NEEDS_LIBINTL if you haven't set NO_GETTEXT and your system\n+# needs to be explicitly linked to -lintl. It's defined automatically\n+# on platforms where we don't expect glibc (Linux, Hurd,\n+# GNU/kFreeBSD), which includes libintl.\n+#\n # Define EXPATDIR=/foo/bar if your expat header and library files are in\n # /foo/bar/include and /foo/bar/lib directories.\n #\n@@ -272,6 +281,7 @@ mandir = share/man\n infodir = share/info\n gitexecdir = libexec/git-core\n sharedir = $(prefix)/share\n+localedir = $(sharedir)/locale\n template_dir = share/git-core/templates\n htmldir = share/doc/git-doc\n ifeq ($(prefix),/usr)\n@@ -285,7 +295,7 @@ lib = lib\n # DESTDIR=\n pathsep = :\n \n-export prefix bindir sharedir sysconfdir\n+export prefix bindir sharedir sysconfdir localedir\n \n CC = gcc\n AR = ar\n@@ -297,6 +307,8 @@ RPMBUILD = rpmbuild\n TCL_PATH = tclsh\n TCLTK_PATH = wish\n PTHREAD_LIBS = -lpthread\n+XGETTEXT = xgettext\n+MSGFMT = msgfmt\n \n export TCL_PATH TCLTK_PATH\n \n@@ -358,6 +370,7 @@ SCRIPT_SH += git-web--browse.sh\n SCRIPT_LIB += git-mergetool--lib\n SCRIPT_LIB += git-parse-remote\n SCRIPT_LIB += git-sh-setup\n+SCRIPT_LIB += git-sh-i18n\n \n SCRIPT_PERL += git-add--interactive.perl\n SCRIPT_PERL += git-difftool.perl\n@@ -523,6 +536,7 @@ LIB_H += userdiff.h\n LIB_H += utf8.h\n LIB_H += xdiff-interface.h\n LIB_H += xdiff/xdiff.h\n+LIB_H += gettext.h\n \n LIB_OBJS += abspath.o\n LIB_OBJS += advice.o\n@@ -564,6 +578,9 @@ LIB_OBJS += entry.o\n LIB_OBJS += environment.o\n LIB_OBJS += exec_cmd.o\n LIB_OBJS += fsck.o\n+ifndef NO_GETTEXT\n+LIB_OBJS += gettext.o\n+endif\n LIB_OBJS += graph.o\n LIB_OBJS += grep.o\n LIB_OBJS += hash.o\n@@ -735,6 +752,14 @@ EXTLIBS =\n # Platform specific tweaks\n #\n \n+# Platform specific defaults. Where we'd only like some feature on the\n+# minority of systems, e.g. if linking to a library isn't needed\n+# because its features are included in the GNU C library.\n+ifndef NO_GETTEXT\n+\t# Systems that use GNU gettext and glibc are the exception\n+\tNEEDS_LIBINTL = YesPlease\n+endif\n+\n # We choose to avoid \"if .. else if .. else .. endif endif\"\n # because maintaining the nesting to match is a pain.  If\n # we had \"elif\" things would have been much nicer...\n@@ -743,11 +768,13 @@ ifeq ($(uname_S),Linux)\n \tNO_STRLCPY = YesPlease\n \tNO_MKSTEMPS = YesPlease\n \tHAVE_PATHS_H = YesPlease\n+\tNEEDS_LIBINTL =\n endif\n ifeq ($(uname_S),GNU/kFreeBSD)\n \tNO_STRLCPY = YesPlease\n \tNO_MKSTEMPS = YesPlease\n \tHAVE_PATHS_H = YesPlease\n+\tNEEDS_LIBINTL =\n endif\n ifeq ($(uname_S),UnixWare)\n \tCC = cc\n@@ -917,6 +944,7 @@ ifeq ($(uname_S),GNU)\n \tNO_STRLCPY=YesPlease\n \tNO_MKSTEMPS = YesPlease\n \tHAVE_PATHS_H = YesPlease\n+\tNEEDS_LIBINTL =\n endif\n ifeq ($(uname_S),IRIX)\n \tNO_SETENV = YesPlease\n@@ -1386,6 +1414,14 @@ ifdef USE_NED_ALLOCATOR\n        COMPAT_OBJS += compat/nedmalloc/nedmalloc.o\n endif\n \n+ifdef NO_GETTEXT\n+\tCOMPAT_CFLAGS += -DNO_GETTEXT\n+endif\n+\n+ifdef NEEDS_LIBINTL\n+\tEXTLIBS += -lintl\n+endif\n+\n ifeq ($(TCLTK_PATH),)\n NO_TCLTK=NoThanks\n endif\n@@ -1415,6 +1451,7 @@ ifndef V\n \tQUIET_BUILT_IN = @echo '   ' BUILTIN $@;\n \tQUIET_GEN      = @echo '   ' GEN $@;\n \tQUIET_LNCP     = @echo '   ' LN/CP $@;\n+\tQUIET_MSGFMT   = @echo '   ' MSGFMT $@;\n \tQUIET_SUBDIR0  = +@subdir=\n \tQUIET_SUBDIR1  = ;$(NO_SUBDIR) echo '   ' SUBDIR $$subdir; \\\n \t\t\t $(MAKE) $(PRINT_DIR) -C $$subdir\n@@ -1442,7 +1479,9 @@ gitexecdir_SQ = $(subst ','\\'',$(gitexecdir))\n template_dir_SQ = $(subst ','\\'',$(template_dir))\n htmldir_SQ = $(subst ','\\'',$(htmldir))\n prefix_SQ = $(subst ','\\'',$(prefix))\n+sharedir_SQ = $(subst ','\\'',$(sharedir))\n \n+LOCALEDIR_SQ = $(subst ','\\'',$(localedir))\n SHELL_PATH_SQ = $(subst ','\\'',$(SHELL_PATH))\n PERL_PATH_SQ = $(subst ','\\'',$(PERL_PATH))\n PYTHON_PATH_SQ = $(subst ','\\'',$(PYTHON_PATH))\n@@ -1491,7 +1530,7 @@ ifndef NO_TCLTK\n \t$(QUIET_SUBDIR0)gitk-git $(QUIET_SUBDIR1) all\n endif\n ifndef NO_PERL\n-\t$(QUIET_SUBDIR0)perl $(QUIET_SUBDIR1) PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' all\n+\t$(QUIET_SUBDIR0)perl $(QUIET_SUBDIR1) PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' localedir='$(localedir_SQ)' all\n endif\n ifndef NO_PYTHON\n \t$(QUIET_SUBDIR0)git_remote_helpers $(QUIET_SUBDIR1) PYTHON_PATH='$(PYTHON_PATH_SQ)' prefix='$(prefix_SQ)' all\n@@ -1536,6 +1575,7 @@ $(RM) $@ $@+ && \\\n sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \\\n     -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \\\n     -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n+    -e 's|@@LOCALEDIR@@|$(LOCALEDIR_SQ)|g' \\\n     -e 's/@@NO_CURL@@/$(NO_CURL)/g' \\\n     -e $(BROKEN_PATH_FIX) \\\n     $@.sh >$@+\n@@ -1868,6 +1908,21 @@ cscope:\n \t$(RM) cscope*\n \t$(FIND) . -name '*.[hcS]' -print | xargs cscope -b\n \n+pot:\n+\t$(XGETTEXT) --add-comments --keyword=_ --keyword=N_ --output=po/git.pot --language=C $(C_OBJ:o=c) t/t0200/test.c\n+\t$(XGETTEXT) --add-comments --join-existing --output=po/git.pot --language=Shell $(SCRIPT_SH) t/t0200/test.sh\n+\t$(XGETTEXT) --add-comments --join-existing --keyword=__ --output=po/git.pot --language=Perl $(SCRIPT_PERL) t/t0200/test.perl\n+\n+POFILES := $(wildcard po/*.po)\n+MOFILES := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/git.mo,$(POFILES))\n+MODIRS := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/,$(POFILES))\n+ifndef NO_GETTEXT\n+all:: $(MOFILES)\n+endif\n+share/locale/%/LC_MESSAGES/git.mo: po/%.po\n+\t@mkdir -p $(dir $@)\n+\t$(QUIET_MSGFMT)$(MSGFMT) -o $@ $<\n+\n ### Detect prefix changes\n TRACK_CFLAGS = $(subst ','\\'',$(ALL_CFLAGS)):\\\n              $(bindir_SQ):$(gitexecdir_SQ):$(template_dir_SQ):$(prefix_SQ)\n@@ -1889,6 +1944,7 @@ GIT-BUILD-OPTIONS: FORCE\n \t@echo NO_CURL=\\''$(subst ','\\'',$(subst ','\\'',$(NO_CURL)))'\\' >>$@\n \t@echo NO_PERL=\\''$(subst ','\\'',$(subst ','\\'',$(NO_PERL)))'\\' >>$@\n \t@echo NO_PYTHON=\\''$(subst ','\\'',$(subst ','\\'',$(NO_PYTHON)))'\\' >>$@\n+\t@echo NO_GETTEXT=\\''$(subst ','\\'',$(subst ','\\'',$(NO_GETTEXT)))'\\' >>$@\n \n ### Detect Tck/Tk interpreter path changes\n ifndef NO_TCLTK\n@@ -1980,6 +2036,11 @@ install: all\n \t$(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'\n \t$(INSTALL) -m 644 $(SCRIPT_LIB) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'\n \t$(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)'\n+ifndef NO_GETTEXT\n+\t$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(sharedir_SQ)/locale'\n+\t(cd share && tar cf - locale) | \\\n+\t\t(cd '$(DESTDIR_SQ)$(sharedir_SQ)' && umask 022 && tar xof -)\n+endif\n \t$(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install\n ifndef NO_PERL\n \t$(MAKE) -C perl prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install\n@@ -2127,6 +2188,10 @@ ifndef NO_TCLTK\n \t$(MAKE) -C git-gui clean\n endif\n \t$(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-GUI-VARS GIT-BUILD-OPTIONS\n+ifndef NO_GETTEXT\n+\t$(RM) po/git.pot\n+\t$(RM) -r share/\n+endif\n \n .PHONY: all install clean strip\n .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell\ndiff --git a/config.mak.in b/config.mak.in\nindex 0d4b64d..c49072c 100644\n--- a/config.mak.in\n+++ b/config.mak.in\n@@ -32,9 +32,11 @@ NO_CURL=@NO_CURL@\n NO_EXPAT=@NO_EXPAT@\n NO_LIBGEN_H=@NO_LIBGEN_H@\n HAVE_PATHS_H=@HAVE_PATHS_H@\n+NO_GETTEXT=@NO_GETTEXT@\n NEEDS_LIBICONV=@NEEDS_LIBICONV@\n NEEDS_SOCKET=@NEEDS_SOCKET@\n NEEDS_RESOLV=@NEEDS_RESOLV@\n+NEEDS_LIBINTL=@NEEDS_LIBINTL@\n NEEDS_LIBGEN=@NEEDS_LIBGEN@\n NO_SYS_SELECT_H=@NO_SYS_SELECT_H@\n NO_D_INO_IN_DIRENT=@NO_D_INO_IN_DIRENT@\ndiff --git a/configure.ac b/configure.ac\nindex 71038fc..74879b4 100644\n--- a/configure.ac\n+++ b/configure.ac\n@@ -559,6 +559,12 @@ AC_CHECK_LIB([c], [basename],\n AC_SUBST(NEEDS_LIBGEN)\n test -n \"$NEEDS_LIBGEN\" && LIBS=\"$LIBS -lgen\"\n \n+AC_CHECK_LIB([c], [gettext],\n+[NEEDS_LIBINTL=],\n+[NEEDS_LIBINTL=YesPlease])\n+AC_SUBST(NEEDS_LIBINTL)\n+test -n \"$NEEDS_LIBINTL\" && LIBS=\"$LIBS -lintl\"\n+\n ## Checks for header files.\n AC_MSG_NOTICE([CHECKS for header files])\n #\n@@ -730,6 +736,12 @@ AC_CHECK_HEADER([paths.h],\n [HAVE_PATHS_H=])\n AC_SUBST(HAVE_PATHS_H)\n #\n+# Define NO_GETTEXT if you don't have libintl.h\n+AC_CHECK_HEADER([libintl.h],\n+[NO_GETTEXT=],\n+[NO_GETTEXT=YesPlease])\n+AC_SUBST(NO_GETTEXT)\n+#\n # Define NO_STRCASESTR if you don't have strcasestr.\n GIT_CHECK_FUNC(strcasestr,\n [NO_STRCASESTR=],\ndiff --git a/daemon.c b/daemon.c\nindex a90ab10..7f4691c 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -3,6 +3,7 @@\n #include \"exec_cmd.h\"\n #include \"run-command.h\"\n #include \"strbuf.h\"\n+#include \"gettext.h\"\n \n #include <syslog.h>\n \n@@ -974,6 +975,8 @@ int main(int argc, char **argv)\n \tgid_t gid = 0;\n \tint i;\n \n+\tgit_setup_gettext();\n+\n \tgit_extract_argv0_path(argv[0]);\n \n \tfor (i = 1; i < argc; i++) {\ndiff --git a/fast-import.c b/fast-import.c\nindex 129a786..6947f7a 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -156,6 +156,7 @@ Format of STDIN stream:\n #include \"csum-file.h\"\n #include \"quote.h\"\n #include \"exec_cmd.h\"\n+#include \"gettext.h\"\n \n #define PACK_ID_BITS 16\n #define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)\n@@ -2904,6 +2905,8 @@ int main(int argc, const char **argv)\n \n \tgit_extract_argv0_path(argv[0]);\n \n+\tgit_setup_gettext();\n+\n \tif (argc == 2 && !strcmp(argv[1], \"-h\"))\n \t\tusage(fast_import_usage);\n \ndiff --git a/gettext.c b/gettext.c\nnew file mode 100644\nindex 0000000..407fbc0\n--- /dev/null\n+++ b/gettext.c\n@@ -0,0 +1,21 @@\n+#include \"exec_cmd.h\"\n+#include <libintl.h>\n+#include <stdlib.h>\n+\n+extern void git_setup_gettext(void) {\n+\tchar *podir;\n+\tchar *envdir = getenv(\"GIT_TEXTDOMAINDIR\");\n+\n+\tif (envdir) {\n+\t\t(void)bindtextdomain(\"git\", envdir);\n+\t} else {\n+\t\tpodir = (char *)system_path(\"share/locale\");\n+\t\tif (!podir) return;\n+\t\t(void)bindtextdomain(\"git\", podir);\n+\t\tfree(podir);\n+\t}\n+\n+\t(void)setlocale(LC_MESSAGES, \"\");\n+\t(void)setlocale(LC_CTYPE, \"\");\n+\t(void)textdomain(\"git\");\n+}\ndiff --git a/gettext.h b/gettext.h\nnew file mode 100644\nindex 0000000..e02939a\n--- /dev/null\n+++ b/gettext.h\n@@ -0,0 +1,18 @@\n+#ifndef GETTEXT_H\n+#define GETTEXT_H\n+\n+#ifdef NO_GETTEXT\n+static inline void git_setup_gettext(void) {}\n+#else\n+extern void git_setup_gettext(void);\n+#endif\n+\n+#define N_(s) (s)\n+#ifdef NO_GETTEXT\n+#define _(s) (s)\n+#else\n+#include <libintl.h>\n+#define _(s) gettext(s)\n+#endif\n+\n+#endif\ndiff --git a/git-sh-i18n.sh b/git-sh-i18n.sh\nnew file mode 100644\nindex 0000000..d4963e9\n--- /dev/null\n+++ b/git-sh-i18n.sh\n@@ -0,0 +1,47 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2010 Ævar Arnfjörð Bjarmason\n+#\n+# This is Git's interface to gettext.sh. Use it right after\n+# git-sh-setup as:\n+#\n+#   . git-sh-setup\n+#   . git-sh-i18n\n+#\n+#   # For constant interface messages:\n+#   gettext \"A message for the user\"; echo\n+#\n+#   # To interpolate variables:\n+#   details=\"oh noes\"\n+#   eval_gettext \"An error occured: \\$details\"; echo\n+#\n+# See \"info '(gettext)sh'\" for the full manual.\n+\n+# Try to use libintl's gettext.sh, or fall back to English if we\n+# can't.\n+. gettext.sh\n+\n+if test $? -eq 0 && test -z \"$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS\"\n+then\n+\tTEXTDOMAIN=git\n+\texport TEXTDOMAIN\n+\tif [ -z \"$GIT_TEXTDOMAINDIR\" ]\n+\tthen\n+\t\tTEXTDOMAINDIR=\"@@LOCALEDIR@@\"\n+\telse\n+\t\tTEXTDOMAINDIR=\"$GIT_TEXTDOMAINDIR\"\n+\tfi\n+\texport TEXTDOMAINDIR\n+else\n+\t# Since gettext.sh isn't available we'll have to define our own\n+\t# dummy pass-through functions.\n+\n+\tgettext () {\n+\t\tprintf \"%s\" \"$1\"\n+\t}\n+\n+\teval_gettext () {\n+\t\tgettext_eval=\"printf '%s' \\\"$1\\\"\"\n+\t\tprintf \"%s\" \"`eval \\\"$gettext_eval\\\"`\"\n+\t}\n+fi\ndiff --git a/git.c b/git.c\nindex 99f0363..d749eab 100644\n--- a/git.c\n+++ b/git.c\n@@ -3,6 +3,7 @@\n #include \"cache.h\"\n #include \"quote.h\"\n #include \"run-command.h\"\n+#include \"gettext.h\"\n \n const char git_usage_string[] =\n \t\"git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]\\n\"\n@@ -490,6 +491,8 @@ int main(int argc, const char **argv)\n \tif (!cmd)\n \t\tcmd = \"git-help\";\n \n+\tgit_setup_gettext();\n+\n \t/*\n \t * \"git-xxxx\" is the same as \"git xxxx\", but we obviously:\n \t *\ndiff --git a/http-backend.c b/http-backend.c\nindex d1e83d0..b6d9bd5 100644\n--- a/http-backend.c\n+++ b/http-backend.c\n@@ -6,6 +6,7 @@\n #include \"exec_cmd.h\"\n #include \"run-command.h\"\n #include \"string-list.h\"\n+#include \"gettext.h\"\n \n static const char content_type[] = \"Content-Type\";\n static const char content_length[] = \"Content-Length\";\n@@ -605,6 +606,8 @@ int main(int argc, char **argv)\n \tchar *cmd_arg = NULL;\n \tint i;\n \n+\tgit_setup_gettext();\n+\n \tgit_extract_argv0_path(argv[0]);\n \tset_die_routine(die_webcgi);\n \ndiff --git a/http-fetch.c b/http-fetch.c\nindex 762c750..b889c36 100644\n--- a/http-fetch.c\n+++ b/http-fetch.c\n@@ -2,6 +2,7 @@\n #include \"exec_cmd.h\"\n #include \"http.h\"\n #include \"walker.h\"\n+#include \"gettext.h\"\n \n static const char http_fetch_usage[] = \"git http-fetch \"\n \"[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url\";\n@@ -24,6 +25,8 @@ int main(int argc, const char **argv)\n \tint get_verbosely = 0;\n \tint get_recover = 0;\n \n+\tgit_setup_gettext();\n+\n \tgit_extract_argv0_path(argv[0]);\n \n \twhile (arg < argc && argv[arg][0] == '-') {\ndiff --git a/http-push.c b/http-push.c\nindex 415b1ab..ba0338c 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -10,6 +10,7 @@\n #include \"remote.h\"\n #include \"list-objects.h\"\n #include \"sigchain.h\"\n+#include \"gettext.h\"\n \n #include <expat.h>\n \n@@ -1791,6 +1792,8 @@ int main(int argc, char **argv)\n \tstruct remote *remote;\n \tchar *rewritten_url = NULL;\n \n+\tgit_setup_gettext();\n+\n \tgit_extract_argv0_path(argv[0]);\n \n \trepo = xcalloc(sizeof(*repo), 1);\ndiff --git a/imap-send.c b/imap-send.c\nindex 9d0097c..4f5f269 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -25,6 +25,7 @@\n #include \"cache.h\"\n #include \"exec_cmd.h\"\n #include \"run-command.h\"\n+#include \"gettext.h\"\n #ifdef NO_OPENSSL\n typedef void *SSL;\n #else\n@@ -1535,6 +1536,8 @@ int main(int argc, char **argv)\n \n \tgit_extract_argv0_path(argv[0]);\n \n+\tgit_setup_gettext();\n+\n \tif (argc != 1)\n \t\tusage(imap_send_usage);\n \ndiff --git a/perl/Git/I18N.pm b/perl/Git/I18N.pm\nnew file mode 100644\nindex 0000000..5918d68\n--- /dev/null\n+++ b/perl/Git/I18N.pm\n@@ -0,0 +1,91 @@\n+package Git::I18N;\n+use 5.006002;\n+use strict;\n+use warnings;\n+use Exporter;\n+use base 'Exporter';\n+\n+our $VERSION = '0.01';\n+\n+our @EXPORT = qw(__);\n+our @EXPORT_OK = @EXPORT;\n+\n+sub __bootstrap_locale_messages {\n+\tour $TEXTDOMAIN = 'git';\n+\tour $TEXTDOMAINDIR = $ENV{GIT_TEXTDOMAINDIR} || '++LOCALEDIR++';\n+\n+\trequire POSIX;\n+\tPOSIX->import(qw(setlocale));\n+\t# Non-core prerequisite module\n+\trequire Locale::Messages;\n+\tLocale::Messages->import(qw(:locale_h :libintl_h));\n+\n+\tsetlocale(LC_MESSAGES(), '');\n+\tsetlocale(LC_CTYPE(), '');\n+\ttextdomain($TEXTDOMAIN);\n+\tbindtextdomain($TEXTDOMAIN => $TEXTDOMAINDIR);\n+\n+\treturn;\n+}\n+\n+BEGIN\n+{\n+\t# Used by our test script to see if it should test fallbacks or\n+\t# not.\n+\tour $__HAS_LIBRARY = 1;\n+\n+\tlocal $@;\n+\teval { __bootstrap_locale_messages() };\n+\tif ($@) {\n+\t\t# Tell test.pl that we couldn't load the gettext library.\n+\t\t$Git::I18N::__HAS_LIBRARY = 0;\n+\n+\t\t# Just a fall-through no-op\n+\t\t*__ = sub ($) { $_[0] };\n+\t} else {\n+\t\t*__ = \\&Locale::Messages::gettext;\n+\t}\n+}\n+\n+1;\n+\n+__END__\n+\n+=head1 NAME\n+\n+Git::I18N - Perl interface to Git's Gettext localizations\n+\n+=head1 SYNOPSIS\n+\n+\tuse Git::I18N;\n+\n+\tprint __(\"Welcome to Git!\\n\");\n+\n+\tprintf __(\"The following error occured: %s\\n\"), $error;\n+\n+=head1 DESCRIPTION\n+\n+Git's internal Perl interface to gettext via L<Locale::Messages>. If\n+L<Locale::Messages> can't be loaded (it's not a core module) we\n+provide stub passthrough fallbacks.\n+\n+This is a distilled interface to gettext, see C<info '(gettext)Perl'>\n+for the full interface. This module implements only a small part of\n+it.\n+\n+=head1 FUNCTIONS\n+\n+=head2 __($)\n+\n+L<Locale::Messages>'s gettext function if all goes well, otherwise our\n+passthrough fallback function.\n+\n+=head1 AUTHOR\n+\n+E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avarab@gmail.com>\n+\n+=head1 COPYRIGHT\n+\n+Copyright 2010 E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <avarab@gmail.com>\n+\n+=cut\ndiff --git a/perl/Makefile b/perl/Makefile\nindex 4ab21d6..4e624ff 100644\n--- a/perl/Makefile\n+++ b/perl/Makefile\n@@ -5,6 +5,7 @@ makfile:=perl.mak\n \n PERL_PATH_SQ = $(subst ','\\'',$(PERL_PATH))\n prefix_SQ = $(subst ','\\'',$(prefix))\n+localedir_SQ = $(subst ','\\'',$(localedir))\n \n ifndef V\n \tQUIET = @\n@@ -38,7 +39,7 @@ $(makfile): ../GIT-CFLAGS Makefile\n \techo '\techo $(instdir_SQ)' >> $@\n else\n $(makfile): Makefile.PL ../GIT-CFLAGS\n-\t$(PERL_PATH) $< PREFIX='$(prefix_SQ)'\n+\t$(PERL_PATH) $< PREFIX='$(prefix_SQ)' --localedir='$(localedir_SQ)'\n endif\n \n # this is just added comfort for calling make directly in perl dir\ndiff --git a/perl/Makefile.PL b/perl/Makefile.PL\nindex 0b9deca..456d45b 100644\n--- a/perl/Makefile.PL\n+++ b/perl/Makefile.PL\n@@ -1,4 +1,12 @@\n+use strict;\n+use warnings;\n use ExtUtils::MakeMaker;\n+use Getopt::Long;\n+\n+# Sanity: die at first unknown option\n+Getopt::Long::Configure qw/ pass_through /;\n+\n+GetOptions(\"localedir=s\" => \\my $localedir);\n \n sub MY::postamble {\n \treturn <<'MAKE_FRAG';\n@@ -16,7 +24,10 @@ endif\n MAKE_FRAG\n }\n \n-my %pm = ('Git.pm' => '$(INST_LIBDIR)/Git.pm');\n+my %pm = (\n+\t'Git.pm' => '$(INST_LIBDIR)/Git.pm',\n+\t'Git/I18N.pm' => '$(INST_LIBDIR)/Git/I18N.pm',\n+);\n \n # We come with our own bundled Error.pm. It's not in the set of default\n # Perl modules so install it if it's not available on the system yet.\n@@ -33,6 +44,7 @@ WriteMakefile(\n \tNAME            => 'Git',\n \tVERSION_FROM    => 'Git.pm',\n \tPM\t\t=> \\%pm,\n+\tPM_FILTER\t=> qq[\\$(PERL) -pe \"s<\\\\Q++LOCALEDIR++\\\\E><$localedir>\"],\n \tMAKEFILE\t=> 'perl.mak',\n \tINSTALLSITEMAN3DIR => '$(SITEPREFIX)/share/man/man3'\n );\ndiff --git a/po/.gitignore b/po/.gitignore\nnew file mode 100644\nindex 0000000..221000e\n--- /dev/null\n+++ b/po/.gitignore\n@@ -0,0 +1 @@\n+/*.pot\ndiff --git a/po/is.po b/po/is.po\nnew file mode 100644\nindex 0000000..95739f1\n--- /dev/null\n+++ b/po/is.po\n@@ -0,0 +1,47 @@\n+msgid \"\"\n+msgstr \"\"\n+\"Project-Id-Version: Git\\n\"\n+\"PO-Revision-Date: 2010-06-05 19:06 +0000\\n\"\n+\"Language-Team: Git Mailing List <git@vger.kernel.org>\\n\"\n+\"Report-Msgid-Bugs-To: Git Mailing List <git@vger.kernel.org>\\n\"\n+\"Last-Translator: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\\n\"\n+\"MIME-Version: 1.0\\n\"\n+\"Content-Type: text/plain; charset=UTF-8\\n\"\n+\"Content-Transfer-Encoding: 8bit\\n\"\n+\n+#: t/t0200/test.c:4\n+msgid \"See git help COMMAND for more information on a specific command.\"\n+msgstr \"Sjá git help SKIPUN til að sjá hjálp fyrir tiltekna skipun.\"\n+\n+#. TRANSLATORS: This is a test. You don't need to translate it.\n+#: t/t0200/test.c:9\n+msgid \"TEST: A C test string\"\n+msgstr \"TILRAUN: C tilraunastrengur\"\n+\n+#. TRANSLATORS: This is a test. You don't need to translate it.\n+#: t/t0200/test.c:12\n+#, c-format\n+msgid \"TEST: A C test string %s\"\n+msgstr \"TILRAUN: C tilraunastrengur %s\"\n+\n+#. TRANSLATORS: This is a test. You don't need to translate it.\n+#: t/t0200/test.sh:8\n+msgid \"TEST: A Shell test string\"\n+msgstr \"TILRAUN: Skeljartilraunastrengur\"\n+\n+#. TRANSLATORS: This is a test. You don't need to translate it.\n+#: t/t0200/test.sh:11\n+#, sh-format\n+msgid \"TEST: A Shell test $variable\"\n+msgstr \"TILRAUN: Skeljartilraunastrengur með breytunni $variable\"\n+\n+#. TRANSLATORS: This is a test. You don't need to translate it.\n+#: t/t0200/test.perl:8\n+msgid \"TEST: A Perl test string\"\n+msgstr \"TILRAUN: Perl tilraunastrengur\"\n+\n+#. TRANSLATORS: This is a test. You don't need to translate it.\n+#: t/t0200/test.perl:11\n+#, perl-format\n+msgid \"TEST: A Perl test variable %s\"\n+msgstr \"TILRAUN: Perl tilraunastrengur með breytunni %s\"\ndiff --git a/shell.c b/shell.c\nindex e4864e0..ba27c6b 100644\n--- a/shell.c\n+++ b/shell.c\n@@ -2,6 +2,7 @@\n #include \"quote.h\"\n #include \"exec_cmd.h\"\n #include \"strbuf.h\"\n+#include \"gettext.h\"\n \n static int do_generic_cmd(const char *me, char *arg)\n {\n@@ -51,6 +52,8 @@ int main(int argc, char **argv)\n \tstruct commands *cmd;\n \tint devnull_fd;\n \n+\tgit_setup_gettext();\n+\n \t/*\n \t * Always open file descriptors 0/1/2 to avoid clobbering files\n \t * in die().  It also avoids not messing up when the pipes are\ndiff --git a/show-index.c b/show-index.c\nindex 4c0ac13..c2f5448 100644\n--- a/show-index.c\n+++ b/show-index.c\n@@ -1,5 +1,6 @@\n #include \"cache.h\"\n #include \"pack.h\"\n+#include \"gettext.h\"\n \n static const char show_index_usage[] =\n \"git show-index < <packed archive index>\";\n@@ -11,6 +12,8 @@ int main(int argc, char **argv)\n \tunsigned int version;\n \tstatic unsigned int top_index[256];\n \n+\tgit_setup_gettext();\n+\n \tif (argc != 1)\n \t\tusage(show_index_usage);\n \tif (fread(top_index, 2 * 4, 1, stdin) != 1)\ndiff --git a/t/t0200-gettext.sh b/t/t0200-gettext.sh\nnew file mode 100755\nindex 0000000..b54e062\n--- /dev/null\n+++ b/t/t0200-gettext.sh\n@@ -0,0 +1,126 @@\n+#!/bin/sh\n+\n+test_description='Gettext support for Git'\n+\n+. ./test-lib.sh\n+\n+GIT_TEXTDOMAINDIR=\"$GIT_EXEC_PATH/share/locale\"\n+GIT_PO_PATH=\"$GIT_EXEC_PATH/po\"\n+export GIT_TEXTDOMAINDIR GIT_PO_PATH\n+\n+. \"$GIT_EXEC_PATH\"/git-sh-i18n\n+\n+test_expect_success 'sanity: $TEXTDOMAIN is git' '\n+    test $TEXTDOMAIN = \"git\"\n+'\n+\n+if test_have_prereq GETTEXT; then\n+\ttest_expect_success 'sanity: $TEXTDOMAINDIR exists without NO_GETTEXT=YesPlease' '\n+    test -d \"$TEXTDOMAINDIR\" &&\n+    test \"$TEXTDOMAINDIR\" = \"$GIT_TEXTDOMAINDIR\"\n+'\n+\n+\ttest_expect_success 'sanity: Icelandic locale was compiled' '\n+    test -f \"$TEXTDOMAINDIR/is/LC_MESSAGES/git.mo\"\n+'\n+else\n+\ttest_expect_success \"sanity: \\$TEXTDOMAINDIR doesn't exists with NO_GETTEXT=YesPlease\" '\n+    test_expect_failure test -d \"$TEXTDOMAINDIR\" &&\n+    test \"$TEXTDOMAINDIR\" = \"$GIT_TEXTDOMAINDIR\"\n+'\n+fi\n+\n+# Basic xgettext() extraction tests on po/*.po. Doesn't need gettext support\n+test_expect_success 'xgettext: Perl _() strings are not extracted' '\n+    test_expect_failure grep \"A Perl string xgettext will not get\" \"$GIT_PO_PATH\"/is.po\n+'\n+\n+test_expect_success 'xgettext: Comment extraction with --add-comments' '\n+    grep \"TRANSLATORS: This is a test\" \"$TEST_DIRECTORY\"/t0200/* | wc -l > expect &&\n+    grep \"TRANSLATORS: This is a test\" \"$GIT_PO_PATH\"/is.po  | wc -l > actual &&\n+    test_cmp expect actual\n+'\n+\n+test_expect_success 'xgettext: Comment extraction with --add-comments stops at statements' '\n+    test_expect_failure grep \"This is a phony\" \"$GIT_PO_PATH\"/is.po &&\n+    test_expect_failure grep \"the above comment\" \"$GIT_PO_PATH\"/is.po\n+'\n+\n+# We can go no further without actual gettext support\n+if ! test_have_prereq GETTEXT; then\n+\tsay \"Skipping the rest of the gettext tests, Git was compiled with NO_GETTEXT=YesPlease\"\n+\ttest_done\n+fi\n+\n+test_expect_success 'sanity: No gettext(\"\") data for fantasy locale' '\n+    LANGUAGE=is LC_ALL=tlh_TLH.UTF-8 gettext \"\" > real-locale &&\n+    test_expect_failure test -s real-locale\n+'\n+\n+test_expect_success 'sanity: Some gettext(\"\") data for real locale' '\n+    LANGUAGE=is LC_ALL=is_IS.UTF-8 gettext \"\" > fantasy-locale &&\n+    test -s fantasy-locale\n+'\n+\n+# TODO: When we have more locales, generalize this to test them\n+# all. Maybe we'll need a dir->locale map for that.\n+test_expect_success 'sanity: gettext(\"\") metadata is OK' '\n+    # Return value may be non-zero\n+    LANGUAGE=is LC_ALL=is_IS.UTF-8 gettext \"\" > zero-expect &&\n+    grep \"Project-Id-Version: Git\" zero-expect &&\n+    grep \"Git Mailing List <git@vger.kernel.org>\" zero-expect &&\n+    grep \"Content-Type: text/plain; charset=UTF-8\" zero-expect &&\n+    grep \"Content-Transfer-Encoding: 8bit\" zero-expect\n+'\n+\n+test_expect_success 'sanity: gettext(unknown) is passed through' '\n+    printf \"This is not a translation string\"  > expect &&\n+    gettext \"This is not a translation string\" > actual &&\n+    eval_gettext \"This is not a translation string\" > actual &&\n+    test_cmp expect actual\n+'\n+\n+# xgettext from C\n+test_expect_success 'xgettext: C extraction of _() and N_() strings' '\n+    printf \"TILRAUN: C tilraunastrengur\" > expect &&\n+    printf \"\\n\" >> expect &&\n+    printf \"Sjá git help SKIPUN til að sjá hjálp fyrir tiltekna skipun.\" >> expect &&\n+    LANGUAGE=is LC_ALL=is_IS.UTF-8 gettext \"TEST: A C test string\" > actual &&\n+    printf \"\\n\" >> actual &&\n+    LANGUAGE=is LC_ALL=is_IS.UTF-8 gettext \"See git help COMMAND for more information on a specific command.\" >> actual &&\n+    test_cmp expect actual\n+'\n+\n+test_expect_success 'xgettext: C extraction with %s' '\n+    printf \"TILRAUN: C tilraunastrengur %%s\" > expect &&\n+    LANGUAGE=is LC_ALL=is_IS.UTF-8 gettext \"TEST: A C test string %s\" > actual &&\n+    test_cmp expect actual\n+'\n+\n+# xgettext from Shell\n+test_expect_success 'xgettext: Shell extraction' '\n+    printf \"TILRAUN: Skeljartilraunastrengur\" > expect &&\n+    LANGUAGE=is LC_ALL=is_IS.UTF-8 gettext \"TEST: A Shell test string\" > actual &&\n+    test_cmp expect actual\n+'\n+\n+test_expect_success 'xgettext: Shell extraction with $variable' '\n+    printf \"TILRAUN: Skeljartilraunastrengur með breytunni a var i able\" > x-expect &&\n+    LANGUAGE=is LC_ALL=is_IS.UTF-8 variable=\"a var i able\" eval_gettext \"TEST: A Shell test \\$variable\" > x-actual &&\n+    test_cmp x-expect x-actual\n+'\n+\n+# xgettext from Perl\n+test_expect_success 'xgettext: Perl extraction' '\n+    printf \"TILRAUN: Perl tilraunastrengur\" > expect &&\n+    LANGUAGE=is LC_ALL=is_IS.UTF-8 gettext \"TEST: A Perl test string\" > actual &&\n+    test_cmp expect actual\n+'\n+\n+test_expect_success 'xgettext: Perl extraction with %s' '\n+    printf \"TILRAUN: Perl tilraunastrengur með breytunni %%s\" > expect &&\n+    LANGUAGE=is LC_ALL=is_IS.UTF-8 gettext \"TEST: A Perl test variable %s\" > actual &&\n+    test_cmp expect actual\n+'\n+\n+test_done\ndiff --git a/t/t0200/test.c b/t/t0200/test.c\nnew file mode 100644\nindex 0000000..db0a23d\n--- /dev/null\n+++ b/t/t0200/test.c\n@@ -0,0 +1,14 @@\n+/* This is a phony C program that's only here to test xgettext message extraction */\n+\n+const char help[] =\n+\tN_(\"See 'git help COMMAND' for more information on a specific command.\");\n+\n+int main(void)\n+{\n+\t/* TRANSLATORS: This is a test. You don't need to translate it. */\n+\tputs(_(\"TEST: A C test string\"));\n+\n+\t/* TRANSLATORS: This is a test. You don't need to translate it. */\n+\tprintf(_(\"TEST: A C test string %s\"), \"variable\");\n+}\n+\t\ndiff --git a/t/t0200/test.perl b/t/t0200/test.perl\nnew file mode 100644\nindex 0000000..36fba34\n--- /dev/null\n+++ b/t/t0200/test.perl\n@@ -0,0 +1,14 @@\n+# This is a phony Perl program that's only here to test xgettext\n+# message extraction\n+\n+# so the above comment won't be folded into the next one by xgettext\n+1;\n+\n+# TRANSLATORS: This is a test. You don't need to translate it.\n+print __(\"TEST: A Perl test string\");\n+\n+# TRANSLATORS: This is a test. You don't need to translate it.\n+printf __(\"TEST: A Perl test variable %s\"), \"moo\";\n+\n+# TRANSLATORS: If you see this, Git has a bug\n+print _\"TEST: A Perl string xgettext will not get\";\ndiff --git a/t/t0200/test.sh b/t/t0200/test.sh\nnew file mode 100644\nindex 0000000..022d607\n--- /dev/null\n+++ b/t/t0200/test.sh\n@@ -0,0 +1,14 @@\n+# This is a phony Shell program that's only here to test xgettext\n+# message extraction\n+\n+# so the above comment won't be folded into the next one by xgettext\n+echo\n+\n+# TRANSLATORS: This is a test. You don't need to translate it.\n+gettext \"TEST: A Shell test string\"\n+\n+# TRANSLATORS: This is a test. You don't need to translate it.\n+eval_gettext \"TEST: A Shell test \\$variable\"\n+\n+# TRANSLATORS: If you see this, Git has a bug\n+_(\"TEST: A Shell string xgettext won't get\")\ndiff --git a/t/t0201-gettext-fallbacks.sh b/t/t0201-gettext-fallbacks.sh\nnew file mode 100755\nindex 0000000..b4bc1df\n--- /dev/null\n+++ b/t/t0201-gettext-fallbacks.sh\n@@ -0,0 +1,42 @@\n+#!/bin/sh\n+\n+test_description='Gettext Shell fallbacks'\n+\n+. ./test-lib.sh\n+\n+GIT_TEXTDOMAINDIR=\"$GIT_EXEC_PATH/share/locale\"\n+GIT_INTERNAL_GETTEXT_TEST_FALLBACKS=YesPlease\n+\n+export GIT_TEXTDOMAINDIR GIT_INTERNAL_GETTEXT_TEST_FALLBACKS\n+\n+. \"$GIT_EXEC_PATH\"/git-sh-i18n\n+\n+test_expect_success 'sanity: $GIT_INTERNAL_GETTEXT_TEST_FALLBACKS is set' '\n+\ttest_expect_failure test -z \"$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS\"\n+'\n+\n+test_expect_success 'gettext: our gettext() fallback has pass-through semantics' '\n+    printf \"test\" > expect &&\n+    gettext \"test\" > actual &&\n+    test_cmp expect actual &&\n+    printf \"test more words\" > expect &&\n+    gettext \"test more words\" > actual &&\n+    test_cmp expect actual\n+'\n+\n+test_expect_success 'eval_gettext: our eval_gettext() fallback has pass-through semantics' '\n+    printf \"test\" > expect &&\n+    eval_gettext \"test\" > actual &&\n+    test_cmp expect actual &&\n+    printf \"test more words\" > expect &&\n+    eval_gettext \"test more words\" > actual &&\n+    test_cmp expect actual\n+'\n+\n+test_expect_success 'eval_gettext: our eval_gettext() fallback can interpolate variables' '\n+    printf \"test YesPlease\" > expect &&\n+    eval_gettext \"test \\$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS\" > actual &&\n+    test_cmp expect actual\n+'\n+\n+test_done\ndiff --git a/t/t0202-gettext-perl.sh b/t/t0202-gettext-perl.sh\nnew file mode 100755\nindex 0000000..9b075b1\n--- /dev/null\n+++ b/t/t0202-gettext-perl.sh\n@@ -0,0 +1,20 @@\n+#!/bin/sh\n+\n+test_description='Perl gettext interface (Git::I18N)'\n+. ./test-lib.sh\n+\n+if ! test_have_prereq PERL; then\n+\tsay 'skipping perl interface tests, perl not available'\n+\ttest_done\n+fi\n+\n+\"$PERL_PATH\" -MTest::More -e 0 2>/dev/null || {\n+\tsay \"Perl Test::More unavailable, skipping test\"\n+\ttest_done\n+}\n+\n+test_external_without_stderr \\\n+    'Perl Git::I18N API' \\\n+    \"$PERL_PATH\" \"$TEST_DIRECTORY\"/t0202/test.pl\n+\n+test_done\ndiff --git a/t/t0202/test.pl b/t/t0202/test.pl\nnew file mode 100644\nindex 0000000..4e9a0dc\n--- /dev/null\n+++ b/t/t0202/test.pl\n@@ -0,0 +1,104 @@\n+#!/usr/bin/perl\n+use 5.006002;\n+use lib (split(/:/, $ENV{GITPERLLIB}));\n+use warnings;\n+use strict;\n+use Test::More tests => 9;\n+use Git::I18N;\n+use POSIX qw(:locale_h);\n+\n+my $has_gettext_library = $Git::I18N::__HAS_LIBRARY;\n+\n+ok(1, \"Testing Git::I18N version $Git::I18N::VERSION with \" .\n+\t ($has_gettext_library\n+\t  ? \"Locale::Messages version $Locale::Messages::VERSION\"\n+\t  : \"NO Perl gettext library\"));\n+ok(1, \"Git::I18N is located at $INC{'Git/I18N.pm'}\");\n+\n+ok($Git::I18N::VERSION, 'sanity: Git::I18N defines a $VERSION');\n+{\n+\tmy $exports = @Git::I18N::EXPORT;\n+\tok($exports, \"sanity: Git::I18N has $exports export(s)\");\n+}\n+is_deeply(\\@Git::I18N::EXPORT, \\@Git::I18N::EXPORT_OK, \"sanity: Git::I18N exports everything by default\");\n+\n+# prototypes\n+{\n+\t# Add prototypes here when modifying the public interface to add\n+\t# more gettext wrapper functions.\n+\tmy %prototypes = (qw(\n+\t\t__\t$\n+    ));\n+\twhile (my ($sub, $proto) = each %prototypes) {\n+\t\tis(prototype(\\&{\"Git::I18N::$sub\"}), $proto, \"sanity: $sub has a $proto prototype\");\n+\t}\n+}\n+\n+# Test basic passthrough in the C locale\n+{\n+\tlocal $ENV{LANGUAGE} = 'C';\n+\tlocal $ENV{LC_ALL}   = 'C';\n+\tlocal $ENV{LANG} = 'C';\n+\n+\tmy ($got, $expect) = (('TEST: A Perl test string') x 2);\n+\n+\tis(__($got), $expect, \"Passing a string through __() in the C locale works\");\n+}\n+\n+# Test a basic message on different locales\n+SKIP: {\n+    unless ($ENV{TEST_GIT_I18N_EXHAUSTIVE}) {\n+        # Can't reliably test __() with a non-C locales because the\n+        # required locales may not be installed on the system.\n+        #\n+        # We test for these anyway as part of the shell\n+        # tests. Skipping these here will eliminate failures on odd\n+        # platforms with incomplete locale data.\n+\n+        skip \"Set TEST_GIT_I18N_EXHAUSTIVE=1 to enable exhaustive Git::I18N locale tests\", 2;\n+    }\n+\n+\tmy $test = sub {\n+\t\tmy ($got, $expect, $msg, $locale) = @_;\n+\t\t# Maybe this system doesn't have the locale we're trying to\n+\t\t# test.\n+\t\tmy $locale_ok = setlocale(LC_ALL, $locale);\n+\t\tis(__($got), $expect, \"$msg a gettext library + <$locale> locale <$got> turns into <$expect>\");\n+\t};\n+\n+\tmy $env_C = sub {\n+\t\t$ENV{LANGUAGE} = 'C';\n+\t\t$ENV{LC_ALL}   = 'C';\n+\t};\n+\n+\tmy $env_is = sub {\n+\t\t$ENV{LANGUAGE} = 'is';\n+\t\t$ENV{LC_ALL}   = 'is_IS.UTF-8';\n+\t};\n+\n+\t# Translation's the same as the original\n+\tmy ($got, $expect) = (('TEST: A Perl test string') x 2);\n+\n+\tif ($has_gettext_library) {\n+\t\t{\n+\t\t\tlocal %ENV; $env_C->();\n+\t\t\t$test->($got, $expect, \"With\", 'C');\n+\t\t}\n+\n+\t\t{\n+\t\t\tmy ($got, $expect) = ($got, 'TILRAUN: Perl tilraunastrengur');\n+\t\t\tlocal %ENV; $env_is->();\n+\t\t\t$test->($got, $expect, \"With\", 'is_IS.UTF-8');\n+\t\t}\n+\t} else {\n+\t\t{\n+\t\t\tlocal %ENV; $env_C->();\n+\t\t\t$test->($got, $expect, \"Without\", 'C');\n+\t\t}\n+\n+\t\t{\n+\t\t\tlocal %ENV; $env_is->();\n+\t\t\t$test->($got, $expect, \"Without\", 'is');\n+\t\t}\n+\t}\n+}\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 454880a..ae63316 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -37,6 +37,7 @@ ORIGINAL_TERM=$TERM\n # For repeatability, reset the environment to known value.\n LANG=C\n LC_ALL=C\n+LANGUAGE=C\n PAGER=cat\n TZ=UTC\n TERM=dumb\n@@ -845,6 +846,7 @@ esac\n \n test -z \"$NO_PERL\" && test_set_prereq PERL\n test -z \"$NO_PYTHON\" && test_set_prereq PYTHON\n+test -z \"$NO_GETTEXT\" && test_set_prereq GETTEXT\n \n # test whether the filesystem supports symbolic links\n ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS\ndiff --git a/upload-pack.c b/upload-pack.c\nindex dc464d7..ece9a4b 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -10,6 +10,7 @@\n #include \"revision.h\"\n #include \"list-objects.h\"\n #include \"run-command.h\"\n+#include \"gettext.h\"\n \n static const char upload_pack_usage[] = \"git upload-pack [--strict] [--timeout=nn] <dir>\";\n \n@@ -686,6 +687,8 @@ int main(int argc, char **argv)\n \tint i;\n \tint strict = 0;\n \n+\tgit_setup_gettext();\n+\n \tgit_extract_argv0_path(argv[0]);\n \tread_replace_refs = 0;\n \n-- \n1.7.1.243.gda92d6.dirty\n"},{"id":"143062","messageId":"1275772373-26718-3-git-send-email-avarab@gmail.com","threadId":"24020","inReplyTo":"1275772373-26718-1-git-send-email-avarab@gmail.com","subject":"[PATCH/RFC v8 2/2] Add initial C, Shell and Perl gettext translations","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-06-05T21:12:53Z","receivedAt":"2010-06-05T21:12:53Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Change the git status, git pull, and git send-email commands to have\nat least one translatable string. Each command uses a different core\nlanguage, so this makes a good example of how C, Shell and Perl\nprograms can be translated using gettext.\n\nSince this introduces translation into the real Git tools more tests\ncan be added to check if they translations actually work for real core\ntools.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n git-pull.sh         |   16 ++++---\n git-send-email.perl |    3 +-\n po/is.po            |   23 +++++++++++\n t/t0200-gettext.sh  |   28 +++++++++++++\n t/t0200/test.c      |    2 +-\n wt-status.c         |  107 ++++++++++++++++++++++++++-------------------------\n 6 files changed, 117 insertions(+), 62 deletions(-)\n\ndiff --git a/git-pull.sh b/git-pull.sh\nindex 1a4729f..0d95722 100755\n--- a/git-pull.sh\n+++ b/git-pull.sh\n@@ -9,6 +9,7 @@ LONG_USAGE='Fetch one or more remote refs and merge it/them into the current HEA\n SUBDIRECTORY_OK=Yes\n OPTIONS_SPEC=\n . git-sh-setup\n+. git-sh-i18n\n set_reflog_action \"pull $*\"\n require_work_tree\n cd_to_toplevel\n@@ -121,8 +122,8 @@ error_on_no_merge_candidates () {\n \tdo\n \t\tcase \"$opt\" in\n \t\t-t|--t|--ta|--tag|--tags)\n-\t\t\techo \"Fetching tags only, you probably meant:\"\n-\t\t\techo \"  git fetch --tags\"\n+\t\t\tgettext \"Fetching tags only, you probably meant:\"; echo\n+\t\t\tgettext \"  git fetch --tags\"; echo\n \t\t\texit 1\n \t\tesac\n \tdone\n@@ -154,11 +155,12 @@ error_on_no_merge_candidates () {\n \t\techo \"a branch. Because this is not the default configured remote\"\n \t\techo \"for your current branch, you must specify a branch on the command line.\"\n \telif [ -z \"$curr_branch\" ]; then\n-\t\techo \"You are not currently on a branch, so I cannot use any\"\n-\t\techo \"'branch.<branchname>.merge' in your configuration file.\"\n-\t\techo \"Please specify which remote branch you want to use on the command\"\n-\t\techo \"line and try again (e.g. 'git pull <repository> <refspec>').\"\n-\t\techo \"See git-pull(1) for details.\"\n+\t\tgettext \"You are not currently on a branch, so I cannot use any\n+'branch.<branchname>.merge' in your configuration file.\n+Please specify which remote branch you want to use on the command\n+line and try again (e.g. 'git pull <repository> <refspec>').\n+See git-pull(1) for details.\";\n+\t\techo\n \telif [ -z \"$upstream\" ]; then\n \t\techo \"You asked me to pull without telling me which branch you\"\n \t\techo \"want to $op_type $op_prep, and 'branch.${curr_branch}.merge' in\"\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 111c981..4977fdf 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -26,6 +26,7 @@ use Term::ANSIColor;\n use File::Temp qw/ tempdir tempfile /;\n use Error qw(:try);\n use Git;\n+use Git::I18N;\n \n Getopt::Long::Configure qw/ pass_through /;\n \n@@ -674,7 +675,7 @@ if (!defined $sender) {\n \t$sender = $repoauthor || $repocommitter || '';\n \t$sender = ask(\"Who should the emails appear to be from? [$sender] \",\n \t              default => $sender);\n-\tprint \"Emails will be sent from: \", $sender, \"\\n\";\n+\tprintf __(\"Emails will be sent from: %s\\n\"), $sender;\n \t$prompting++;\n }\n \ndiff --git a/po/is.po b/po/is.po\nindex 95739f1..8e4f8c5 100644\n--- a/po/is.po\n+++ b/po/is.po\n@@ -13,6 +13,20 @@ msgstr \"\"\n msgid \"See git help COMMAND for more information on a specific command.\"\n msgstr \"Sjá git help SKIPUN til að sjá hjálp fyrir tiltekna skipun.\"\n \n+#: wt-status.c:63 wt-status.c:79 wt-status.c:98 wt-status.c:110\n+#: wt-status.c:622\n+msgid \"On branch \"\n+msgstr \"Á greininni \"\n+\n+#: wt-status.c:629\n+msgid \"Not currently on any branch.\"\n+msgstr \"Ekki á neinni grein.\"\n+\n+#: wt-status.c:663\n+#, c-format\n+msgid \"# No changes\\n\"\n+msgstr \"# Engar breytingar\\n\"\n+\n #. TRANSLATORS: This is a test. You don't need to translate it.\n #: t/t0200/test.c:9\n msgid \"TEST: A C test string\"\n@@ -24,6 +38,10 @@ msgstr \"TILRAUN: C tilraunastrengur\"\n msgid \"TEST: A C test string %s\"\n msgstr \"TILRAUN: C tilraunastrengur %s\"\n \n+#: git-pull.sh:124\n+msgid \"Fetching tags only, you probably meant:\"\n+msgstr \"Næ aðeins í tögg, þú áttir líkast til við:\"\n+\n #. TRANSLATORS: This is a test. You don't need to translate it.\n #: t/t0200/test.sh:8\n msgid \"TEST: A Shell test string\"\n@@ -35,6 +53,11 @@ msgstr \"TILRAUN: Skeljartilraunastrengur\"\n msgid \"TEST: A Shell test $variable\"\n msgstr \"TILRAUN: Skeljartilraunastrengur með breytunni $variable\"\n \n+#: git-send-email.perl:678\n+#, perl-format\n+msgid \"Emails will be sent from: %s\\n\"\n+msgstr \"Póstarnir verða sendir frá: %s\\n\"\n+\n #. TRANSLATORS: This is a test. You don't need to translate it.\n #: t/t0200/test.perl:8\n msgid \"TEST: A Perl test string\"\ndiff --git a/t/t0200-gettext.sh b/t/t0200-gettext.sh\nindex b54e062..6b702e5 100755\n--- a/t/t0200-gettext.sh\n+++ b/t/t0200-gettext.sh\n@@ -123,4 +123,32 @@ test_expect_success 'xgettext: Perl extraction with %s' '\n     test_cmp expect actual\n '\n \n+# Actually execute some C and Shell code that uses Gettext\n+test_expect_success 'C: git-status reads our message catalog ' '\n+    test_commit \"some-file\" &&\n+    git checkout -b test/gettext &&\n+    LANGUAGE=C LC_ALL=C git status | grep test/gettext > expect &&\n+    echo \"# On branch test/gettext\" > actual &&\n+    test_cmp expect actual &&\n+\n+    LANGUAGE=is LC_ALL=is_IS.UTF-8 git status | grep test/gettext > expect &&\n+    echo \"# Á greininni test/gettext\" > actual &&\n+    test_cmp expect actual\n+'\n+\n+test_expect_success 'Shell: git-pull reads our message catalog' '\n+    # Repository for testing\n+    mkdir parent &&\n+    (cd parent && git init &&\n+     echo one >file && git add file &&\n+     git commit -m one) &&\n+\n+    # Actual test\n+    (cd parent &&\n+    (LANGUAGE=C LC_ALL=C git pull --tags \"../\" >out 2>err);\n+    grep \"Fetching tags only\" err &&\n+    (LANGUAGE=is LC_ALL=is_IS.UTF-8 git pull --tags ../ >out 2>err || :) &&\n+    grep \"Næ aðeins í\" err)\n+'\n+\n test_done\ndiff --git a/t/t0200/test.c b/t/t0200/test.c\nindex db0a23d..9f937be 100644\n--- a/t/t0200/test.c\n+++ b/t/t0200/test.c\n@@ -11,4 +11,4 @@ int main(void)\n \t/* TRANSLATORS: This is a test. You don't need to translate it. */\n \tprintf(_(\"TEST: A C test string %s\"), \"variable\");\n }\n-\t\n+\ndiff --git a/wt-status.c b/wt-status.c\nindex 14e0acc..484a866 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -9,6 +9,7 @@\n #include \"quote.h\"\n #include \"run-command.h\"\n #include \"remote.h\"\n+#include \"gettext.h\"\n \n static char default_wt_status_colors[][COLOR_MAXLEN] = {\n \tGIT_COLOR_NORMAL, /* WT_STATUS_HEADER */\n@@ -49,16 +50,16 @@ static void wt_status_print_unmerged_header(struct wt_status *s)\n {\n \tconst char *c = color(WT_STATUS_HEADER, s);\n \n-\tcolor_fprintf_ln(s->fp, c, \"# Unmerged paths:\");\n+\tcolor_fprintf_ln(s->fp, c, _(\"# Unmerged paths:\"));\n \tif (!advice_status_hints)\n \t\treturn;\n \tif (s->in_merge)\n \t\t;\n \telse if (!s->is_initial)\n-\t\tcolor_fprintf_ln(s->fp, c, \"#   (use \\\"git reset %s <file>...\\\" to unstage)\", s->reference);\n+\t\tcolor_fprintf_ln(s->fp, c, _(\"#   (use \\\"git reset %s <file>...\\\" to unstage)\"), s->reference);\n \telse\n-\t\tcolor_fprintf_ln(s->fp, c, \"#   (use \\\"git rm --cached <file>...\\\" to unstage)\");\n-\tcolor_fprintf_ln(s->fp, c, \"#   (use \\\"git add/rm <file>...\\\" as appropriate to mark resolution)\");\n+\t\tcolor_fprintf_ln(s->fp, c, _(\"#   (use \\\"git rm --cached <file>...\\\" to unstage)\"));\n+\tcolor_fprintf_ln(s->fp, c, _(\"#   (use \\\"git add/rm <file>...\\\" as appropriate to mark resolution)\"));\n \tcolor_fprintf_ln(s->fp, c, \"#\");\n }\n \n@@ -66,15 +67,15 @@ static void wt_status_print_cached_header(struct wt_status *s)\n {\n \tconst char *c = color(WT_STATUS_HEADER, s);\n \n-\tcolor_fprintf_ln(s->fp, c, \"# Changes to be committed:\");\n+\tcolor_fprintf_ln(s->fp, c, _(\"# Changes to be committed:\"));\n \tif (!advice_status_hints)\n \t\treturn;\n \tif (s->in_merge)\n \t\t; /* NEEDSWORK: use \"git reset --unresolve\"??? */\n \telse if (!s->is_initial)\n-\t\tcolor_fprintf_ln(s->fp, c, \"#   (use \\\"git reset %s <file>...\\\" to unstage)\", s->reference);\n+\t\tcolor_fprintf_ln(s->fp, c, _(\"#   (use \\\"git reset %s <file>...\\\" to unstage)\"), s->reference);\n \telse\n-\t\tcolor_fprintf_ln(s->fp, c, \"#   (use \\\"git rm --cached <file>...\\\" to unstage)\");\n+\t\tcolor_fprintf_ln(s->fp, c, _(\"#   (use \\\"git rm --cached <file>...\\\" to unstage)\"));\n \tcolor_fprintf_ln(s->fp, c, \"#\");\n }\n \n@@ -84,16 +85,16 @@ static void wt_status_print_dirty_header(struct wt_status *s,\n {\n \tconst char *c = color(WT_STATUS_HEADER, s);\n \n-\tcolor_fprintf_ln(s->fp, c, \"# Changed but not updated:\");\n+\tcolor_fprintf_ln(s->fp, c, _(\"# Changed but not updated:\"));\n \tif (!advice_status_hints)\n \t\treturn;\n \tif (!has_deleted)\n-\t\tcolor_fprintf_ln(s->fp, c, \"#   (use \\\"git add <file>...\\\" to update what will be committed)\");\n+\t\tcolor_fprintf_ln(s->fp, c, _(\"#   (use \\\"git add <file>...\\\" to update what will be committed)\"));\n \telse\n-\t\tcolor_fprintf_ln(s->fp, c, \"#   (use \\\"git add/rm <file>...\\\" to update what will be committed)\");\n-\tcolor_fprintf_ln(s->fp, c, \"#   (use \\\"git checkout -- <file>...\\\" to discard changes in working directory)\");\n+\t\tcolor_fprintf_ln(s->fp, c, _(\"#   (use \\\"git add/rm <file>...\\\" to update what will be committed)\"));\n+\tcolor_fprintf_ln(s->fp, c, _(\"#   (use \\\"git checkout -- <file>...\\\" to discard changes in working directory)\"));\n \tif (has_dirty_submodules)\n-\t\tcolor_fprintf_ln(s->fp, c, \"#   (commit or discard the untracked or modified content in submodules)\");\n+\t\tcolor_fprintf_ln(s->fp, c, _(\"#   (commit or discard the untracked or modified content in submodules)\"));\n \tcolor_fprintf_ln(s->fp, c, \"#\");\n }\n \n@@ -102,10 +103,10 @@ static void wt_status_print_other_header(struct wt_status *s,\n \t\t\t\t\t const char *how)\n {\n \tconst char *c = color(WT_STATUS_HEADER, s);\n-\tcolor_fprintf_ln(s->fp, c, \"# %s files:\", what);\n+\tcolor_fprintf_ln(s->fp, c, _(\"# %s files:\"), what);\n \tif (!advice_status_hints)\n \t\treturn;\n-\tcolor_fprintf_ln(s->fp, c, \"#   (use \\\"git %s <file>...\\\" to include in what will be committed)\", how);\n+\tcolor_fprintf_ln(s->fp, c, _(\"#   (use \\\"git %s <file>...\\\" to include in what will be committed)\"), how);\n \tcolor_fprintf_ln(s->fp, c, \"#\");\n }\n \n@@ -122,20 +123,20 @@ static void wt_status_print_unmerged_data(struct wt_status *s,\n \tconst char *c = color(WT_STATUS_UNMERGED, s);\n \tstruct wt_status_change_data *d = it->util;\n \tstruct strbuf onebuf = STRBUF_INIT;\n-\tconst char *one, *how = \"bug\";\n+\tconst char *one, *how = _(\"bug\");\n \n \tone = quote_path(it->string, -1, &onebuf, s->prefix);\n \tcolor_fprintf(s->fp, color(WT_STATUS_HEADER, s), \"#\\t\");\n \tswitch (d->stagemask) {\n-\tcase 1: how = \"both deleted:\"; break;\n-\tcase 2: how = \"added by us:\"; break;\n-\tcase 3: how = \"deleted by them:\"; break;\n-\tcase 4: how = \"added by them:\"; break;\n-\tcase 5: how = \"deleted by us:\"; break;\n-\tcase 6: how = \"both added:\"; break;\n-\tcase 7: how = \"both modified:\"; break;\n+\tcase 1: how = _(\"both deleted:\"); break;\n+\tcase 2: how = _(\"added by us:\"); break;\n+\tcase 3: how = _(\"deleted by them:\"); break;\n+\tcase 4: how = _(\"added by them:\"); break;\n+\tcase 5: how = _(\"deleted by us:\"); break;\n+\tcase 6: how = _(\"both added:\"); break;\n+\tcase 7: how = _(\"both modified:\"); break;\n \t}\n-\tcolor_fprintf(s->fp, c, \"%-20s%s\\n\", how, one);\n+\tcolor_fprintf(s->fp, c, _(\"%-20s%s\\n\"), how, one);\n \tstrbuf_release(&onebuf);\n }\n \n@@ -163,11 +164,11 @@ static void wt_status_print_change_data(struct wt_status *s,\n \t\tif (d->new_submodule_commits || d->dirty_submodule) {\n \t\t\tstrbuf_addstr(&extra, \" (\");\n \t\t\tif (d->new_submodule_commits)\n-\t\t\t\tstrbuf_addf(&extra, \"new commits, \");\n+\t\t\t\tstrbuf_addf(&extra, _(\"new commits, \"));\n \t\t\tif (d->dirty_submodule & DIRTY_SUBMODULE_MODIFIED)\n-\t\t\t\tstrbuf_addf(&extra, \"modified content, \");\n+\t\t\t\tstrbuf_addf(&extra, _(\"modified content, \"));\n \t\t\tif (d->dirty_submodule & DIRTY_SUBMODULE_UNTRACKED)\n-\t\t\t\tstrbuf_addf(&extra, \"untracked content, \");\n+\t\t\t\tstrbuf_addf(&extra, _(\"untracked content, \"));\n \t\t\tstrbuf_setlen(&extra, extra.len - 2);\n \t\t\tstrbuf_addch(&extra, ')');\n \t\t}\n@@ -178,34 +179,34 @@ static void wt_status_print_change_data(struct wt_status *s,\n \tone = quote_path(one_name, -1, &onebuf, s->prefix);\n \ttwo = quote_path(two_name, -1, &twobuf, s->prefix);\n \n-\tcolor_fprintf(s->fp, color(WT_STATUS_HEADER, s), \"#\\t\");\n+\tcolor_fprintf(s->fp, color(WT_STATUS_HEADER, s), _(\"#\\t\"));\n \tswitch (status) {\n \tcase DIFF_STATUS_ADDED:\n-\t\tcolor_fprintf(s->fp, c, \"new file:   %s\", one);\n+\t\tcolor_fprintf(s->fp, c, _(\"new file:   %s\"), one);\n \t\tbreak;\n \tcase DIFF_STATUS_COPIED:\n-\t\tcolor_fprintf(s->fp, c, \"copied:     %s -> %s\", one, two);\n+\t\tcolor_fprintf(s->fp, c, _(\"copied:     %s -> %s\"), one, two);\n \t\tbreak;\n \tcase DIFF_STATUS_DELETED:\n-\t\tcolor_fprintf(s->fp, c, \"deleted:    %s\", one);\n+\t\tcolor_fprintf(s->fp, c, _(\"deleted:    %s\"), one);\n \t\tbreak;\n \tcase DIFF_STATUS_MODIFIED:\n-\t\tcolor_fprintf(s->fp, c, \"modified:   %s\", one);\n+\t\tcolor_fprintf(s->fp, c, _(\"modified:   %s\"), one);\n \t\tbreak;\n \tcase DIFF_STATUS_RENAMED:\n-\t\tcolor_fprintf(s->fp, c, \"renamed:    %s -> %s\", one, two);\n+\t\tcolor_fprintf(s->fp, c, _(\"renamed:    %s -> %s\"), one, two);\n \t\tbreak;\n \tcase DIFF_STATUS_TYPE_CHANGED:\n-\t\tcolor_fprintf(s->fp, c, \"typechange: %s\", one);\n+\t\tcolor_fprintf(s->fp, c, _(\"typechange: %s\"), one);\n \t\tbreak;\n \tcase DIFF_STATUS_UNKNOWN:\n-\t\tcolor_fprintf(s->fp, c, \"unknown:    %s\", one);\n+\t\tcolor_fprintf(s->fp, c, _(\"unknown:    %s\"), one);\n \t\tbreak;\n \tcase DIFF_STATUS_UNMERGED:\n-\t\tcolor_fprintf(s->fp, c, \"unmerged:   %s\", one);\n+\t\tcolor_fprintf(s->fp, c, _(\"unmerged:   %s\"), one);\n \t\tbreak;\n \tdefault:\n-\t\tdie(\"bug: unhandled diff status %c\", status);\n+\t\tdie(_(\"bug: unhandled diff status %c\"), status);\n \t}\n \tif (extra.len) {\n \t\tcolor_fprintf(s->fp, color(WT_STATUS_HEADER, s), \"%s\", extra.buf);\n@@ -618,14 +619,14 @@ void wt_status_print(struct wt_status *s)\n \tconst char *branch_color = color(WT_STATUS_HEADER, s);\n \n \tif (s->branch) {\n-\t\tconst char *on_what = \"On branch \";\n+\t\tconst char *on_what = _(\"On branch \");\n \t\tconst char *branch_name = s->branch;\n \t\tif (!prefixcmp(branch_name, \"refs/heads/\"))\n \t\t\tbranch_name += 11;\n \t\telse if (!strcmp(branch_name, \"HEAD\")) {\n \t\t\tbranch_name = \"\";\n \t\t\tbranch_color = color(WT_STATUS_NOBRANCH, s);\n-\t\t\ton_what = \"Not currently on any branch.\";\n+\t\t\ton_what = _(\"Not currently on any branch.\");\n \t\t}\n \t\tcolor_fprintf(s->fp, color(WT_STATUS_HEADER, s), \"# \");\n \t\tcolor_fprintf_ln(s->fp, branch_color, \"%s%s\", on_what, branch_name);\n@@ -635,7 +636,7 @@ void wt_status_print(struct wt_status *s)\n \n \tif (s->is_initial) {\n \t\tcolor_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), \"#\");\n-\t\tcolor_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), \"# Initial commit\");\n+\t\tcolor_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), _(\"# Initial commit\"));\n \t\tcolor_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), \"#\");\n \t}\n \n@@ -647,38 +648,38 @@ void wt_status_print(struct wt_status *s)\n \t\twt_status_print_submodule_summary(s, 1);  /* unstaged */\n \t}\n \tif (s->show_untracked_files) {\n-\t\twt_status_print_other(s, &s->untracked, \"Untracked\", \"add\");\n+\t\twt_status_print_other(s, &s->untracked, _(\"Untracked\"), _(\"add\"));\n \t\tif (s->show_ignored_files)\n-\t\t\twt_status_print_other(s, &s->ignored, \"Ignored\", \"add -f\");\n+\t\t\twt_status_print_other(s, &s->ignored, _(\"Ignored\"), _(\"add -f\"));\n \t} else if (s->commitable)\n-\t\tfprintf(s->fp, \"# Untracked files not listed%s\\n\",\n+\t\tfprintf(s->fp, _(\"# Untracked files not listed%s\\n\"),\n \t\t\tadvice_status_hints\n-\t\t\t? \" (use -u option to show untracked files)\" : \"\");\n+\t\t\t? _(\" (use -u option to show untracked files)\") : \"\");\n \n \tif (s->verbose)\n \t\twt_status_print_verbose(s);\n \tif (!s->commitable) {\n \t\tif (s->amend)\n-\t\t\tfprintf(s->fp, \"# No changes\\n\");\n+\t\t\tfprintf(s->fp, _(\"# No changes\\n\"));\n \t\telse if (s->nowarn)\n \t\t\t; /* nothing */\n \t\telse if (s->workdir_dirty)\n-\t\t\tprintf(\"no changes added to commit%s\\n\",\n+\t\t\tprintf(_(\"no changes added to commit%s\\n\"),\n \t\t\t\tadvice_status_hints\n-\t\t\t\t? \" (use \\\"git add\\\" and/or \\\"git commit -a\\\")\" : \"\");\n+\t\t\t\t? _(\" (use \\\"git add\\\" and/or \\\"git commit -a\\\")\") : \"\");\n \t\telse if (s->untracked.nr)\n-\t\t\tprintf(\"nothing added to commit but untracked files present%s\\n\",\n+\t\t\tprintf(_(\"nothing added to commit but untracked files present%s\\n\"),\n \t\t\t\tadvice_status_hints\n-\t\t\t\t? \" (use \\\"git add\\\" to track)\" : \"\");\n+\t\t\t\t? _(\" (use \\\"git add\\\" to track)\") : \"\");\n \t\telse if (s->is_initial)\n \t\t\tprintf(\"nothing to commit%s\\n\", advice_status_hints\n-\t\t\t\t? \" (create/copy files and use \\\"git add\\\" to track)\" : \"\");\n+\t\t\t\t? _(\" (create/copy files and use \\\"git add\\\" to track)\") : \"\");\n \t\telse if (!s->show_untracked_files)\n-\t\t\tprintf(\"nothing to commit%s\\n\", advice_status_hints\n-\t\t\t\t? \" (use -u to show untracked files)\" : \"\");\n+\t\t\tprintf(_(\"nothing to commit%s\\n\"), advice_status_hints\n+\t\t\t\t? _(\" (use -u to show untracked files)\") : \"\");\n \t\telse\n-\t\t\tprintf(\"nothing to commit%s\\n\", advice_status_hints\n-\t\t\t\t? \" (working directory clean)\" : \"\");\n+\t\t\tprintf(_(\"nothing to commit%s\\n\"), advice_status_hints\n+\t\t\t\t? _(\" (working directory clean)\") : \"\");\n \t}\n }\n \n-- \n1.7.1.243.gda92d6.dirty\n"},{"id":"143064","messageId":"m3vd9xp3oz.fsf@localhost.localdomain","threadId":"24020","inReplyTo":"1275772373-26718-1-git-send-email-avarab@gmail.com","subject":"Re: [PATCH/RFC v8 0/2] Gettext support for Git","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2010-06-05T21:29:13Z","receivedAt":"2010-06-05T21:29:13Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:\n\n> This is version 8 of the series to make Git optionally translatable\n> with GNU gettext.\n> \n> Changes since version 7:\n[...]\n\n>    * Add back support (and a new test) for the no-op N_() macro. This\n>      is used for marking translations for later use, e.g.:\n>         \n>         const char help[] =\n>         \tN_(\"See 'git help COMMAND' for more information on a specific command.\");\n>         \n>         int main(void)\n>         {\n>             puts(_(help));\n\nShouldn't you add also corresponding N__ subroutine to Git::I18N\nmodule?\n\n  # Dummy functions for string marking.\n  sub N__($) {\n  \treturn shift;\n  }\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"},{"id":"143065","messageId":"AANLkTikvP6z4-AdbSJQYV5yo9UXKVh3lleFZ49_hmSZ5@mail.gmail.com","threadId":"24020","inReplyTo":"m3vd9xp3oz.fsf@localhost.localdomain","subject":"Re: [PATCH/RFC v8 0/2] Gettext support for Git","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-06-05T21:35:29Z","receivedAt":"2010-06-05T21:35:29Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Sat, Jun 5, 2010 at 21:29, Jakub Narebski <jnareb@gmail.com> wrote:\n> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:\n>\n>> This is version 8 of the series to make Git optionally translatable\n>> with GNU gettext.\n>>\n>> Changes since version 7:\n> [...]\n>\n>>    * Add back support (and a new test) for the no-op N_() macro. This\n>>      is used for marking translations for later use, e.g.:\n>>\n>>         const char help[] =\n>>               N_(\"See 'git help COMMAND' for more information on a specific command.\");\n>>\n>>         int main(void)\n>>         {\n>>             puts(_(help));\n>\n> Shouldn't you add also corresponding N__ subroutine to Git::I18N\n> module?\n>\n>  # Dummy functions for string marking.\n>  sub N__($) {\n>        return shift;\n>  }\n\nI don't really see the need. It's very useful in C because you can't\ncall functions outside function bodies (like in the example\nabove). Perl has no such restriction, so I don't see the use case.\n\nCan you think of one? Perhaps I'm just being unimaginative.\n"}]}