Skip to contentSkip to conversation

Add internationalization support to Git

PATCH Superseded Ævar Arnfjörð Bjarmason 5 participants 56 messages Jun 15, 2016 Kbuild

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Add internationalization support to Git

Here's an updated version of the patch series begun by Jeff Epler to make Git optionally translatable with GNU gettext. I'm submitting it now because I'd like to get some comments on the approach, and specifically whether something like this is likely to be accepted into Git.

Changes since the initial submission:

* Merged in changes to wt-status.c from the master branch

* Made Gettext play nice with the build system (.gitignore & make clean)

* Added support for making Git's shell scripts translatable by importing the gettext functions in git-sh-setup.sh, or supplying replacements if they don't work. Comments from shellscript-savy list members about whether the fallbacks work on odd non-GNU shells are especially welcome.

I made three strings in git-pull.sh translatable as a proof of concept. One problem that I ran into is that xgettext(1) seems very particular when picking up translation strings. It accepts this:

gettext "hello world"; echo

but not this:

die gettext "hello world"; die

or this:

gettext <<"END";
hello world
END

Maybe there's a way to make it play nice. But I just used a large multiline string as a workaround. I don't know what to do about 'die gettext' other than define a 'die_gettext' wrapper function and use `xgettext --keyword=die_gettext'.

* There's now a skeleton is.po file. It just has one string translated. I can't figure out what to call any of the Git core concepts so I'm stuck :)

Next up:

* Perl support. I haven't yet found what the best way of using libintl from Perl would be. GNU recommends Locale::TextDomain, but Debian only seems to have Locale::gettext which is a more lightweight wrapper.

In any case I can write a wrapper for those/the shell command and fall back on the hardcoded strings like the C/Shell code does.

Most importantly. If there are any interested list members that want to translate Git, it's now ready for translators. You just have to add a po/$lang.po file with your favorite editor and Git's build system will install it.

One thing I haven't done is to try to go ahead and make massive changes to the Git source code to make everything translatable. Due to their nature it's a big headache to maintain changes like that if anything moves upstream.

Of course that's subject to change if other people are interested in contributing.

For reference, here's the branch on GitHub I'm hacking this in, patches welcome:

http://github.com/avar/git/compare/master...topic/git-gettext

Jeff Epler (1):
Add infrastructure for translating Git with gettext

Ævar Arnfjörð Bjarmason (4):
gitignore: Ignore files generated by gettext
Makefile: Remove Gettext files on make clean
gettext: Add a skeleton po/is.po
Add infrastructure to make shellscripts translatable

 .gitignore      |    1 +
 Makefile        |   35 +++++++-
 gettext.c       |   17 ++++
 gettext.h       |   15 +++
 git-pull.sh     |   15 ++--
 git-sh-setup.sh |   33 +++++++
 git.c           |    3 +
 po/.gitignore   |    1 +
 po/is.po        |  288 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 wt-status.c     |  129 +++++++++++++------------
 10 files changed, 465 insertions(+), 72 deletions(-)
 create mode 100644 gettext.c
 create mode 100644 gettext.h
 create mode 100644 po/.gitignore
 create mode 100644 po/is.po
#1 lore raw

PATCH 1/5 Add infrastructure for translating Git with gettext

From: Jeff Epler <[email protected]>

Change the build process to use GNU's libintl if it's available. If not we define our own skeleton replacement functions which degrade gracefully to English.

---
 Makefile    |   26 ++++++++++++
 gettext.c   |   17 ++++++++
 gettext.h   |   15 +++++++
 git.c       |    3 +
 wt-status.c |  129 ++++++++++++++++++++++++++++++-----------------------------
 5 files changed, 126 insertions(+), 64 deletions(-)
 create mode 100644 gettext.c
 create mode 100644 gettext.h
Makefile +26 -0
index d5d6565..7989121 100644
@@ -297,6 +297,8 @@ RPMBUILD = rpmbuild
 TCL_PATH = tclsh
 TCLTK_PATH = wish
 PTHREAD_LIBS = -lpthread
+XGETTEXT = xgettext
+MSGFMT = msgfmt
 
 export TCL_PATH TCLTK_PATH
 
@@ -523,6 +525,7 @@ LIB_H += userdiff.h
 LIB_H += utf8.h
 LIB_H += xdiff-interface.h
 LIB_H += xdiff/xdiff.h
+LIB_H += gettext.h
 
 LIB_OBJS += abspath.o
 LIB_OBJS += advice.o
@@ -564,6 +567,7 @@ LIB_OBJS += entry.o
 LIB_OBJS += environment.o
 LIB_OBJS += exec_cmd.o
 LIB_OBJS += fsck.o
+LIB_OBJS += gettext.o
 LIB_OBJS += graph.o
 LIB_OBJS += grep.o
 LIB_OBJS += hash.o
@@ -1386,6 +1390,12 @@ ifdef USE_NED_ALLOCATOR
        COMPAT_OBJS += compat/nedmalloc/nedmalloc.o
 endif
 
+ifdef NO_GETTEXT
+	COMPAT_CFLAGS += -DNO_GETTEXT
+else
+	LIBINTL = -lintl
+endif
+
 ifeq ($(TCLTK_PATH),)
 NO_TCLTK=NoThanks
 endif
@@ -1415,6 +1425,7 @@ ifndef V
 	QUIET_BUILT_IN = @echo '   ' BUILTIN $@;
 	QUIET_GEN      = @echo '   ' GEN $@;
 	QUIET_LNCP     = @echo '   ' LN/CP $@;
+	QUIET_MSGFMT   = @echo '   ' MSGFMT $@;
 	QUIET_SUBDIR0  = +@subdir=
 	QUIET_SUBDIR1  = ;$(NO_SUBDIR) echo '   ' SUBDIR $$subdir; \
 			 $(MAKE) $(PRINT_DIR) -C $$subdir
@@ -1442,6 +1453,7 @@ gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
 template_dir_SQ = $(subst ','\'',$(template_dir))
 htmldir_SQ = $(subst ','\'',$(htmldir))
 prefix_SQ = $(subst ','\'',$(prefix))
+sharedir_SQ = $(subst ','\'',$(sharedir))
 
 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
 PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
@@ -1868,6 +1880,17 @@ cscope:
 	$(RM) cscope*
 	$(FIND) . -name '*.[hcS]' -print | xargs cscope -b
 
+pot:
+	$(XGETTEXT) -k_ -o po/git.pot $(C_OBJ:o=c)
+
+POFILES := $(wildcard po/*.po)
+MOFILES := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/git.mo,$(POFILES))
+MODIRS := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/,$(POFILES))
+all:: $(MOFILES)
+share/locale/%/LC_MESSAGES/git.mo: po/%.po
+	@mkdir -p $(dir $@)
+	$(QUIET_MSGFMT)$(MSGFMT) -o $@ $<
+
 ### Detect prefix changes
 TRACK_CFLAGS = $(subst ','\'',$(ALL_CFLAGS)):\
              $(bindir_SQ):$(gitexecdir_SQ):$(template_dir_SQ):$(prefix_SQ)
@@ -1980,6 +2003,9 @@ install: all
 	$(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 	$(INSTALL) -m 644 $(SCRIPT_LIB) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 	$(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)'
+	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(sharedir_SQ)/locale'
+	(cd share && tar cf - locale) | \
+		(cd '$(DESTDIR_SQ)$(sharedir_SQ)' && umask 022 && tar xof -)
 	$(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
 ifndef NO_PERL
 	$(MAKE) -C perl prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install
gettext.c new file +17 -0
new file mode 100644
index 0000000..aadce19
@@ -0,0 +1,17 @@
+#ifdef NO_GETTEXT
+void git_setup_gettext() {}
+#else
+#include "exec_cmd.h"
+#include <libintl.h>
+#include <stdlib.h>
+
+void git_setup_gettext() {
+    const char *podir = system_path("share/locale");
+    if(!podir) return;
+    char *ret = bindtextdomain("git", podir);
+    free((void*)podir);
+    ret = setlocale(LC_MESSAGES, "");
+    ret = setlocale(LC_CTYPE, "");
+    ret = textdomain("git");
+}
+#endif
gettext.h new file +15 -0
new file mode 100644
index 0000000..8b221b4
@@ -0,0 +1,15 @@
+#ifndef GETTEXT_H
+#define GETTEXT_H
+
+void git_setup_gettext();
+
+#ifdef NO_GETTEXT
+#define _(s) (s)
+#define N_(s) (s)
+#else
+#include <libintl.h>
+#define _(s) gettext(s)
+#define N_(s) (s)
+#endif
+
+#endif
git.c +3 -0
index 99f0363..d749eab 100644
@@ -3,6 +3,7 @@
 #include "cache.h"
 #include "quote.h"
 #include "run-command.h"
+#include "gettext.h"
 
 const char git_usage_string[] =
 	"git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]\n"
@@ -490,6 +491,8 @@ int main(int argc, const char **argv)
 	if (!cmd)
 		cmd = "git-help";
 
+	git_setup_gettext();
+
 	/*
 	 * "git-xxxx" is the same as "git xxxx", but we obviously:
 	 *
wt-status.c +65 -64

271 lines not on this page · raw message

Signature · 1 line
1.7.1.242.ge2b63.dirty
#2 lore raw

PATCH 2/5 gitignore: Ignore files generated by gettext

In reply to Ævar Arnfjörð Bjarmason

- Ignore po/git.pot which is autogenerated by a manual run of the Makefile. We're only interested in tracking the po/*.po files.

- Ignore the /share/ directory. It's created during installation and contains gettext-related files to be installed.

---
 .gitignore    |    1 +
 po/.gitignore |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
 create mode 100644 po/.gitignore
.gitignore +1 -0
index 14e2b6b..d22c0e5 100644
@@ -204,3 +204,4 @@
 *.pdb
 /Debug/
 /Release/
+/share/
po/.gitignore new file +1 -0
new file mode 100644
index 0000000..221000e
@@ -0,0 +1 @@
+/*.pot
Signature · 1 line
1.7.1.242.ge2b63.dirty
#3 lore raw

PATCH 3/5 Makefile: Remove Gettext files on make clean

In reply to Ævar Arnfjörð Bjarmason

Remove the automatically generated po/git.pot and share/ files. They're created by the gettext installation process.

---
 Makefile |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
Makefile +4 -0
index 7989121..4de0627 100644
@@ -2153,6 +2153,10 @@ ifndef NO_TCLTK
 	$(MAKE) -C git-gui clean
 endif
 	$(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-GUI-VARS GIT-BUILD-OPTIONS
+ifndef NO_GETTEXT
+	$(RM) po/git.pot
+	$(RM) -r share/
+endif
 
 .PHONY: all install clean strip
 .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
Signature · 1 line
1.7.1.242.ge2b63.dirty
#4 lore raw

PATCH 4/5 gettext: Add a skeleton po/is.po

In reply to Ævar Arnfjörð Bjarmason
---
 po/is.po |  288 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 288 insertions(+), 0 deletions(-)
 create mode 100644 po/is.po
po/is.po new file +288 -0
new file mode 100644
index 0000000..4aac4e9
@@ -0,0 +1,288 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR Free Software Foundation, Inc.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <[email protected]>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+# SOME DESCRIPTIVE TITLE.#~ 
+# Copyright (C) YEAR Free Software Foundation, Inc.#~ 
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.#~ 
+##~ 
+#, fuzzy#~ 
+msgid ""#~ 
+msgstr ""#~ 
+"Project-Id-Version: Git\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2010-05-29 21:17+0000\n"
+"PO-Revision-Date: \n"
+"Last-Translator: Ævar Arnfjörð Bjarmason <[email protected]>\n"
+"Language-Team: Git Mailing List <[email protected]>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Poedit-Language: English\n"
+"X-Poedit-SourceCharset: utf-8\n"
+
+#: wt-status.c:53
+msgid "# Unmerged paths:"
+msgstr ""
+
+#: wt-status.c:59 wt-status.c:76
+#, c-format
+msgid "#   (use \"git reset %s <file>...\" to unstage)"
+msgstr ""
+
+#: wt-status.c:61 wt-status.c:78
+msgid "#   (use \"git rm --cached <file>...\" to unstage)"
+msgstr ""
+
+#: wt-status.c:62
+msgid "#   (use \"git add/rm <file>...\" as appropriate to mark resolution)"
+msgstr ""
+
+#: wt-status.c:63 wt-status.c:79 wt-status.c:98 wt-status.c:110
+#: wt-status.c:115 wt-status.c:638 wt-status.c:640
+msgid "#"
+msgstr ""
+
+#: wt-status.c:70
+msgid "# Changes to be committed:"
+msgstr ""
+
+#: wt-status.c:88
+msgid "# Changed but not updated:"
+msgstr ""
+
+#: wt-status.c:92
+msgid "#   (use \"git add <file>...\" to update what will be committed)"
+msgstr ""
+
+#: wt-status.c:94
+msgid "#   (use \"git add/rm <file>...\" to update what will be committed)"
+msgstr ""
+
+#: wt-status.c:95
+msgid ""
+"#   (use \"git checkout -- <file>...\" to discard changes in working "
+"directory)"
+msgstr ""
+
+#: wt-status.c:97
+msgid "#   (commit or discard the untracked or modified content in submodules)"
+msgstr ""
+
+#: wt-status.c:106
+#, c-format
+msgid "# %s files:"
+msgstr ""
+
+#: wt-status.c:109
+#, c-format
+msgid "#   (use \"git %s <file>...\" to include in what will be committed)"
+msgstr ""
+
+#: wt-status.c:126
+msgid "bug"
+msgstr ""
+
+#: wt-status.c:129 wt-status.c:182
+msgid "#\t"
+msgstr ""
+
+#: wt-status.c:131
+msgid "both deleted:"
+msgstr ""
+
+#: wt-status.c:132
+msgid "added by us:"
+msgstr ""
+
+#: wt-status.c:133
+msgid "deleted by them:"
+msgstr ""
+
+#: wt-status.c:134
+msgid "added by them:"
+msgstr ""
+
+#: wt-status.c:135
+msgid "deleted by us:"
+msgstr ""
+
+#: wt-status.c:136
+msgid "both added:"
+msgstr ""
+
+#: wt-status.c:137
+msgid "both modified:"
+msgstr ""
+
+#: wt-status.c:139
+#, c-format
+msgid "%-20s%s\n"
+msgstr ""
+
+#: wt-status.c:165
+msgid " ("
+msgstr ""
+
+#: wt-status.c:167
+msgid "new commits, "
+msgstr ""
+
+#: wt-status.c:169
+msgid "modified content, "
+msgstr ""
+
+#: wt-status.c:171
+msgid "untracked content, "
+msgstr ""
+
+#: wt-status.c:185
+#, c-format
+msgid "new file:   %s"
+msgstr ""
+
+#: wt-status.c:188
+#, c-format
+msgid "copied:     %s -> %s"
+msgstr ""
+
+#: wt-status.c:191
+#, c-format
+msgid "deleted:    %s"
+msgstr ""
+
+#: wt-status.c:194
+#, c-format
+msgid "modified:   %s"
+msgstr ""
+
+#: wt-status.c:197
+#, c-format
+msgid "renamed:    %s -> %s"
+msgstr ""
+
+#: wt-status.c:200
+#, c-format
+msgid "typechange: %s"
+msgstr ""
+
+#: wt-status.c:203
+#, c-format
+msgid "unknown:    %s"
+msgstr ""
+
+#: wt-status.c:206
+#, c-format
+msgid "unmerged:   %s"
+msgstr ""
+
+#: wt-status.c:209
+#, c-format
+msgid "bug: unhandled diff status %c"
+msgstr ""
+
+#: wt-status.c:212
+#, c-format
+msgid "%s"
+msgstr ""
+
+#: wt-status.c:215
+#, c-format
+msgid "\n"
+msgstr ""
+
+#: wt-status.c:622
+msgid "On branch "
+msgstr "Á greininni "
+
+#: wt-status.c:629
+msgid "Not currently on any branch."
+msgstr "Ekki á neinni grein."
+
+#: wt-status.c:639
+msgid "# Initial commit"
+msgstr ""
+
+#: wt-status.c:651
+msgid "Untracked"
+msgstr ""
+
+#: wt-status.c:651
+msgid "add"
+msgstr ""
+
+#: wt-status.c:653
+msgid "Ignored"
+msgstr ""
+
+#: wt-status.c:653
+msgid "add -f"
+msgstr ""
+
+#: wt-status.c:655
+#, c-format
+msgid "# Untracked files not listed%s\n"
+msgstr ""
+
+#: wt-status.c:657
+msgid " (use -u option to show untracked files)"
+msgstr ""
+
+#: wt-status.c:663
+#, c-format
+msgid "# No changes\n"
+msgstr "# Engar breytingar\n"
+
+#: wt-status.c:667
+#, c-format
+msgid "no changes added to commit%s\n"
+msgstr ""
+
+#: wt-status.c:669
+msgid " (use \"git add\" and/or \"git commit -a\")"
+msgstr ""
+
+#: wt-status.c:671
+#, c-format
+msgid "nothing added to commit but untracked files present%s\n"
+msgstr ""
+
+#: wt-status.c:673
+msgid " (use \"git add\" to track)"
+msgstr ""
+
+#: wt-status.c:676
+msgid " (create/copy files and use \"git add\" to track)"
+msgstr ""
+
+#: wt-status.c:678 wt-status.c:681
+#, c-format
+msgid "nothing to commit%s\n"
+msgstr ""
+
+#: wt-status.c:679
+msgid " (use -u to show untracked files)"
+msgstr ""
+
+#: wt-status.c:682
+msgid " (working directory clean)"
+msgstr ""
+
+#: git-pull.sh:124
+msgid "Fetching tags only, you probably meant:"
+msgstr ""
+
+#: git-pull.sh:125
+msgid "  git fetch --tags"
+msgstr ""
Signature · 1 line
1.7.1.242.ge2b63.dirty
#5 lore raw

PATCH 5/5 Add infrastructure to make shellscripts translatable

In reply to Ævar Arnfjörð Bjarmason

Use GNU's gettext.sh in git-sh-setup if it's available, otherwise fallback on our own custom functions.

A couple of strings in git-pull.sh are now translatable as a proof of concept, including a multiline string.

---
 Makefile        |    7 +++++--
 git-pull.sh     |   15 ++++++++-------
 git-sh-setup.sh |   33 +++++++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+), 9 deletions(-)
Makefile +5 -2
index 4de0627..dce2faa 100644
@@ -272,6 +272,7 @@ mandir = share/man
 infodir = share/info
 gitexecdir = libexec/git-core
 sharedir = $(prefix)/share
+localedir = $(sharedir)/locale
 template_dir = share/git-core/templates
 htmldir = share/doc/git-doc
 ifeq ($(prefix),/usr)
@@ -285,7 +286,7 @@ lib = lib
 # DESTDIR=
 pathsep = :
 
-export prefix bindir sharedir sysconfdir
+export prefix bindir sharedir localedir sysconfdir
 
 CC = gcc
 AR = ar
@@ -1455,6 +1456,7 @@ htmldir_SQ = $(subst ','\'',$(htmldir))
 prefix_SQ = $(subst ','\'',$(prefix))
 sharedir_SQ = $(subst ','\'',$(sharedir))
 
+LOCALEDIR_SQ = $(subst ','\'',$(localedir))
 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
 PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
 PYTHON_PATH_SQ = $(subst ','\'',$(PYTHON_PATH))
@@ -1548,6 +1550,7 @@ $(RM) $@ $@+ && \
 sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
     -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
     -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
+    -e 's|@@LOCALEDIR@@|$(LOCALEDIR_SQ)|g' \
     -e 's/@@NO_CURL@@/$(NO_CURL)/g' \
     -e $(BROKEN_PATH_FIX) \
     [email protected] >$@+
@@ -1881,7 +1884,7 @@ cscope:
 	$(FIND) . -name '*.[hcS]' -print | xargs cscope -b
 
 pot:
-	$(XGETTEXT) -k_ -o po/git.pot $(C_OBJ:o=c)
+	$(XGETTEXT) -k_ -o po/git.pot $(C_OBJ:o=c) $(SCRIPT_SH)
 
 POFILES := $(wildcard po/*.po)
 MOFILES := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/git.mo,$(POFILES))
git-pull.sh +8 -7
index 1a4729f..22a6da2 100755
@@ -121,8 +121,8 @@ error_on_no_merge_candidates () {
 	do
 		case "$opt" in
 		-t|--t|--ta|--tag|--tags)
-			echo "Fetching tags only, you probably meant:"
-			echo "  git fetch --tags"
+			gettext "Fetching tags only, you probably meant:"; echo
+			gettext "  git fetch --tags"; echo
 			exit 1
 		esac
 	done
@@ -154,11 +154,12 @@ error_on_no_merge_candidates () {
 		echo "a branch. Because this is not the default configured remote"
 		echo "for your current branch, you must specify a branch on the command line."
 	elif [ -z "$curr_branch" ]; then
-		echo "You are not currently on a branch, so I cannot use any"
-		echo "'branch.<branchname>.merge' in your configuration file."
-		echo "Please specify which remote branch you want to use on the command"
-		echo "line and try again (e.g. 'git pull <repository> <refspec>')."
-		echo "See git-pull(1) for details."
+        gettext "You are not currently on a branch, so I cannot use any
+'branch.<branchname>.merge' in your configuration file.
+Please specify which remote branch you want to use on the command
+line and try again (e.g. 'git pull <repository> <refspec>').
+See git-pull(1) for details.";
+        echo
 	elif [ -z "$upstream" ]; then
 		echo "You asked me to pull without telling me which branch you"
 		echo "want to $op_type $op_prep, and 'branch.${curr_branch}.merge' in"
git-sh-setup.sh +33 -0
index 6131670..c8010f2 100644
@@ -211,3 +211,36 @@ case $(uname -s) in
 	}
 	;;
 esac
+
+# Try to use libintl's gettext.sh, or fall back to English if we
+# can't.
+. gettext.sh
+if test $? -ne 0
+then
+    TEXTDOMAIN=git
+    export TEXDTOMAIN
+    TEXTDOMAINDIR="@@LOCALEDIR@@"
+    export TEXTDOMAINDIR
+else
+    # Since GNU gettext.sh isn't available we'll have to define our
+    # own dummy functions.
+
+    # This code adapted from NessusClient-1.0.2's nessusclient-mkcert
+    # by Michel Arboi <[email protected]>. The original code is
+    # under the GPLv2.
+
+    # Not everyone has echo -n
+    case $(echo -n) in
+        \-n)    Xn=   ; Xc='\c' ;;
+        *)      Xn=-n ; Xc=
+    esac
+
+    gettext () {
+        echo $Xn "$1" $Xc
+    }
+
+    eval_gettext () {
+        eval_gettext_var="echo $1"
+        echo $Xn `eval $eval_gettext_var` $Xc
+    }
+fi
Signature · 1 line
1.7.1.242.ge2b63.dirty
#6 lore raw

v2 cover Add internationalization support to Git

In reply to Ævar Arnfjörð Bjarmason

Here's version 2 of the patch series begun by Jeff Epler to make Git optionally translatable with GNU gettext.

Due to an error of mine only the cover letter of the previous series had "PATCH/RFC" in the subject line. That's rectified in this series.

Aside from making sure the test suite always runs under LC_ALL=C, sanity tests for the translations, "how to translate" documentation, and the Perl Makefile issue noted below, this series is pretty much ready for inclusion in my opinion. Perl support was the last missing piece for translating all of the core C+Shell+Perl code.

New stuff:

* Perl scripts are now translatable through the Gettext facility. Like the shellscript facility I added this has a graceful fallback if the prerequisite libraries aren't installed.

I'm using the libintl-perl library which provides Locale::Messages. I could also have used liblocale-gettext-perl which provides Locale::gettext. Debian seems to prefer the latter, but the former is recomended by GNU. The new Git::Gettext library could probably be modified to try both.

It works 100% for me. Aside from this bit:

# TODO: How do I make the sed replacements in the top level # Makefile reach me here?
#our $TEXTDOMAINDIR = q|@@LOCALEDIR@@|;
our $TEXTDOMAINDIR = q</usr/local/share/locale>;

I couldn't figure out how to make the sed substitution the core /Makefile does for e.g. @@GIT_VERSION@@ work for the hybrid Makefile / perl.mak setup in perl/.

Suggestions from contributors more familiar with Git's build system welcome.

* Another thing to note regarding Perl. We have some Perl code that's obviously intended to work with perls as old as 5.6. It would be preferable to translation support if the minimum were bumped to 5.8. Here's why:

$ perl -e 'printf "%2\$s the %1\$s has\n", ("Clone War", "Begun")' Begun the Clone War has

Perl 5.6's printf doesn't support that printf syntax, which means that translators would have to make do with the word order of the English messages.

I haven't seen any documentation about Perl coding guidelines or Perl versions that we aim to support in Documentation/, so I don't know if 5.6 is supposed to be supported or whether the support is just incidental.

Note that this 5.8 could only be a requirement if the user was using a translation with positional printf formats. Users interested in running the English-only version could still do so on 5.6.

* Updated is.po. It now contains example translations for C, Shell and Perl programs as a proof of concept.

* Rewrote the commit message of the shell script support commit to use use the gettext: prefix.

Jeff Epler (1):
Add infrastructure for translating Git with gettext

Ævar Arnfjörð Bjarmason (5):
gitignore: Ignore files generated by gettext
Makefile: Remove Gettext files on make clean
gettext: Add a Gettext interface for shell scripts
gettext: Add a Gettext interface for Perl
gettext: Add a skeleton po/is.po

 .gitignore          |    1 +
 Makefile            |   37 +++++++-
 gettext.c           |   17 +++
 gettext.h           |   15 +++
 git-pull.sh         |   15 ++--
 git-send-email.perl |    3 +-
 git-sh-setup.sh     |   33 ++++++
 git.c               |    3 +
 perl/Git/Gettext.pm |   83 +++++++++++++++
 perl/Makefile.PL    |    5 +-
 po/.gitignore       |    1 +
 po/is.po            |  282 +++++++++++++++++++++++++++++++++++++++++++++++++++
 wt-status.c         |  129 ++++++++++++------------
 13 files changed, 550 insertions(+), 74 deletions(-)
 create mode 100644 gettext.c
 create mode 100644 gettext.h
 create mode 100644 perl/Git/Gettext.pm
 create mode 100644 po/.gitignore
 create mode 100644 po/is.po
#7 lore raw

PATCH v2 1/6 Add infrastructure for translating Git with gettext

In reply to Ævar Arnfjörð Bjarmason

From: Jeff Epler <[email protected]>

Change the build process to use GNU's libintl if it's available. If not we define our own skeleton replacement functions which degrade gracefully to English.

---
 Makefile    |   26 ++++++++++++
 gettext.c   |   17 ++++++++
 gettext.h   |   15 +++++++
 git.c       |    3 +
 wt-status.c |  129 ++++++++++++++++++++++++++++++-----------------------------
 5 files changed, 126 insertions(+), 64 deletions(-)
 create mode 100644 gettext.c
 create mode 100644 gettext.h
Makefile +26 -0
index d5d6565..7989121 100644
@@ -297,6 +297,8 @@ RPMBUILD = rpmbuild
 TCL_PATH = tclsh
 TCLTK_PATH = wish
 PTHREAD_LIBS = -lpthread
+XGETTEXT = xgettext
+MSGFMT = msgfmt
 
 export TCL_PATH TCLTK_PATH
 
@@ -523,6 +525,7 @@ LIB_H += userdiff.h
 LIB_H += utf8.h
 LIB_H += xdiff-interface.h
 LIB_H += xdiff/xdiff.h
+LIB_H += gettext.h
 
 LIB_OBJS += abspath.o
 LIB_OBJS += advice.o
@@ -564,6 +567,7 @@ LIB_OBJS += entry.o
 LIB_OBJS += environment.o
 LIB_OBJS += exec_cmd.o
 LIB_OBJS += fsck.o
+LIB_OBJS += gettext.o
 LIB_OBJS += graph.o
 LIB_OBJS += grep.o
 LIB_OBJS += hash.o
@@ -1386,6 +1390,12 @@ ifdef USE_NED_ALLOCATOR
        COMPAT_OBJS += compat/nedmalloc/nedmalloc.o
 endif
 
+ifdef NO_GETTEXT
+	COMPAT_CFLAGS += -DNO_GETTEXT
+else
+	LIBINTL = -lintl
+endif
+
 ifeq ($(TCLTK_PATH),)
 NO_TCLTK=NoThanks
 endif
@@ -1415,6 +1425,7 @@ ifndef V
 	QUIET_BUILT_IN = @echo '   ' BUILTIN $@;
 	QUIET_GEN      = @echo '   ' GEN $@;
 	QUIET_LNCP     = @echo '   ' LN/CP $@;
+	QUIET_MSGFMT   = @echo '   ' MSGFMT $@;
 	QUIET_SUBDIR0  = +@subdir=
 	QUIET_SUBDIR1  = ;$(NO_SUBDIR) echo '   ' SUBDIR $$subdir; \
 			 $(MAKE) $(PRINT_DIR) -C $$subdir
@@ -1442,6 +1453,7 @@ gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
 template_dir_SQ = $(subst ','\'',$(template_dir))
 htmldir_SQ = $(subst ','\'',$(htmldir))
 prefix_SQ = $(subst ','\'',$(prefix))
+sharedir_SQ = $(subst ','\'',$(sharedir))
 
 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
 PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
@@ -1868,6 +1880,17 @@ cscope:
 	$(RM) cscope*
 	$(FIND) . -name '*.[hcS]' -print | xargs cscope -b
 
+pot:
+	$(XGETTEXT) -k_ -o po/git.pot $(C_OBJ:o=c)
+
+POFILES := $(wildcard po/*.po)
+MOFILES := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/git.mo,$(POFILES))
+MODIRS := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/,$(POFILES))
+all:: $(MOFILES)
+share/locale/%/LC_MESSAGES/git.mo: po/%.po
+	@mkdir -p $(dir $@)
+	$(QUIET_MSGFMT)$(MSGFMT) -o $@ $<
+
 ### Detect prefix changes
 TRACK_CFLAGS = $(subst ','\'',$(ALL_CFLAGS)):\
              $(bindir_SQ):$(gitexecdir_SQ):$(template_dir_SQ):$(prefix_SQ)
@@ -1980,6 +2003,9 @@ install: all
 	$(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 	$(INSTALL) -m 644 $(SCRIPT_LIB) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 	$(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)'
+	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(sharedir_SQ)/locale'
+	(cd share && tar cf - locale) | \
+		(cd '$(DESTDIR_SQ)$(sharedir_SQ)' && umask 022 && tar xof -)
 	$(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
 ifndef NO_PERL
 	$(MAKE) -C perl prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install
gettext.c new file +17 -0
new file mode 100644
index 0000000..aadce19
@@ -0,0 +1,17 @@
+#ifdef NO_GETTEXT
+void git_setup_gettext() {}
+#else
+#include "exec_cmd.h"
+#include <libintl.h>
+#include <stdlib.h>
+
+void git_setup_gettext() {
+    const char *podir = system_path("share/locale");
+    if(!podir) return;
+    char *ret = bindtextdomain("git", podir);
+    free((void*)podir);
+    ret = setlocale(LC_MESSAGES, "");
+    ret = setlocale(LC_CTYPE, "");
+    ret = textdomain("git");
+}
+#endif
gettext.h new file +15 -0
new file mode 100644
index 0000000..8b221b4
@@ -0,0 +1,15 @@
+#ifndef GETTEXT_H
+#define GETTEXT_H
+
+void git_setup_gettext();
+
+#ifdef NO_GETTEXT
+#define _(s) (s)
+#define N_(s) (s)
+#else
+#include <libintl.h>
+#define _(s) gettext(s)
+#define N_(s) (s)
+#endif
+
+#endif
git.c +3 -0
index 99f0363..d749eab 100644
@@ -3,6 +3,7 @@
 #include "cache.h"
 #include "quote.h"
 #include "run-command.h"
+#include "gettext.h"
 
 const char git_usage_string[] =
 	"git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]\n"
@@ -490,6 +491,8 @@ int main(int argc, const char **argv)
 	if (!cmd)
 		cmd = "git-help";
 
+	git_setup_gettext();
+
 	/*
 	 * "git-xxxx" is the same as "git xxxx", but we obviously:
 	 *
wt-status.c +65 -64

271 lines not on this page · raw message

Signature · 1 line
1.7.1.248.gcd6d1
#11 lore raw

PATCH v2 2/6 gitignore: Ignore files generated by gettext

In reply to Ævar Arnfjörð Bjarmason

- Ignore po/git.pot which is autogenerated by a manual run of the Makefile. We're only interested in tracking the po/*.po files.

- Ignore the /share/ directory. It's created during installation and contains gettext-related files to be installed.

---
 .gitignore    |    1 +
 po/.gitignore |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
 create mode 100644 po/.gitignore
.gitignore +1 -0
index 14e2b6b..d22c0e5 100644
@@ -204,3 +204,4 @@
 *.pdb
 /Debug/
 /Release/
+/share/
po/.gitignore new file +1 -0
new file mode 100644
index 0000000..221000e
@@ -0,0 +1 @@
+/*.pot
Signature · 1 line
1.7.1.248.gcd6d1
#12 lore raw

PATCH v2 3/6 Makefile: Remove Gettext files on make clean

In reply to Ævar Arnfjörð Bjarmason

Remove the automatically generated po/git.pot and share/ files. They're created by the gettext installation process.

---
 Makefile |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
Makefile +4 -0
index 7989121..4de0627 100644
@@ -2153,6 +2153,10 @@ ifndef NO_TCLTK
 	$(MAKE) -C git-gui clean
 endif
 	$(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-GUI-VARS GIT-BUILD-OPTIONS
+ifndef NO_GETTEXT
+	$(RM) po/git.pot
+	$(RM) -r share/
+endif
 
 .PHONY: all install clean strip
 .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
Signature · 1 line
1.7.1.248.gcd6d1
#13 lore raw

PATCH v2 4/6 gettext: Add a Gettext interface for shell scripts

In reply to Ævar Arnfjörð Bjarmason

Use GNU's gettext.sh in git-sh-setup if it's available, otherwise fallback on our own custom functions.

A couple of strings in git-pull.sh are now translatable as a proof of concept, including a multiline string.

---
 Makefile        |    7 +++++--
 git-pull.sh     |   15 ++++++++-------
 git-sh-setup.sh |   33 +++++++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+), 9 deletions(-)
Makefile +5 -2
index 4de0627..dce2faa 100644
@@ -272,6 +272,7 @@ mandir = share/man
 infodir = share/info
 gitexecdir = libexec/git-core
 sharedir = $(prefix)/share
+localedir = $(sharedir)/locale
 template_dir = share/git-core/templates
 htmldir = share/doc/git-doc
 ifeq ($(prefix),/usr)
@@ -285,7 +286,7 @@ lib = lib
 # DESTDIR=
 pathsep = :
 
-export prefix bindir sharedir sysconfdir
+export prefix bindir sharedir localedir sysconfdir
 
 CC = gcc
 AR = ar
@@ -1455,6 +1456,7 @@ htmldir_SQ = $(subst ','\'',$(htmldir))
 prefix_SQ = $(subst ','\'',$(prefix))
 sharedir_SQ = $(subst ','\'',$(sharedir))
 
+LOCALEDIR_SQ = $(subst ','\'',$(localedir))
 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
 PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
 PYTHON_PATH_SQ = $(subst ','\'',$(PYTHON_PATH))
@@ -1548,6 +1550,7 @@ $(RM) $@ $@+ && \
 sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
     -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
     -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
+    -e 's|@@LOCALEDIR@@|$(LOCALEDIR_SQ)|g' \
     -e 's/@@NO_CURL@@/$(NO_CURL)/g' \
     -e $(BROKEN_PATH_FIX) \
     [email protected] >$@+
@@ -1881,7 +1884,7 @@ cscope:
 	$(FIND) . -name '*.[hcS]' -print | xargs cscope -b
 
 pot:
-	$(XGETTEXT) -k_ -o po/git.pot $(C_OBJ:o=c)
+	$(XGETTEXT) -k_ -o po/git.pot $(C_OBJ:o=c) $(SCRIPT_SH)
 
 POFILES := $(wildcard po/*.po)
 MOFILES := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/git.mo,$(POFILES))
git-pull.sh +8 -7
index 1a4729f..22a6da2 100755
@@ -121,8 +121,8 @@ error_on_no_merge_candidates () {
 	do
 		case "$opt" in
 		-t|--t|--ta|--tag|--tags)
-			echo "Fetching tags only, you probably meant:"
-			echo "  git fetch --tags"
+			gettext "Fetching tags only, you probably meant:"; echo
+			gettext "  git fetch --tags"; echo
 			exit 1
 		esac
 	done
@@ -154,11 +154,12 @@ error_on_no_merge_candidates () {
 		echo "a branch. Because this is not the default configured remote"
 		echo "for your current branch, you must specify a branch on the command line."
 	elif [ -z "$curr_branch" ]; then
-		echo "You are not currently on a branch, so I cannot use any"
-		echo "'branch.<branchname>.merge' in your configuration file."
-		echo "Please specify which remote branch you want to use on the command"
-		echo "line and try again (e.g. 'git pull <repository> <refspec>')."
-		echo "See git-pull(1) for details."
+        gettext "You are not currently on a branch, so I cannot use any
+'branch.<branchname>.merge' in your configuration file.
+Please specify which remote branch you want to use on the command
+line and try again (e.g. 'git pull <repository> <refspec>').
+See git-pull(1) for details.";
+        echo
 	elif [ -z "$upstream" ]; then
 		echo "You asked me to pull without telling me which branch you"
 		echo "want to $op_type $op_prep, and 'branch.${curr_branch}.merge' in"
git-sh-setup.sh +33 -0
index 6131670..c8010f2 100644
@@ -211,3 +211,36 @@ case $(uname -s) in
 	}
 	;;
 esac
+
+# Try to use libintl's gettext.sh, or fall back to English if we
+# can't.
+. gettext.sh
+if test $? -ne 0
+then
+    TEXTDOMAIN=git
+    export TEXDTOMAIN
+    TEXTDOMAINDIR="@@LOCALEDIR@@"
+    export TEXTDOMAINDIR
+else
+    # Since GNU gettext.sh isn't available we'll have to define our
+    # own dummy functions.
+
+    # This code adapted from NessusClient-1.0.2's nessusclient-mkcert
+    # by Michel Arboi <[email protected]>. The original code is
+    # under the GPLv2.
+
+    # Not everyone has echo -n
+    case $(echo -n) in
+        \-n)    Xn=   ; Xc='\c' ;;
+        *)      Xn=-n ; Xc=
+    esac
+
+    gettext () {
+        echo $Xn "$1" $Xc
+    }
+
+    eval_gettext () {
+        eval_gettext_var="echo $1"
+        echo $Xn `eval $eval_gettext_var` $Xc
+    }
+fi
Signature · 1 line
1.7.1.248.gcd6d1
#14 lore raw

PATCH v2 5/6 gettext: Add a Gettext interface for Perl

In reply to Ævar Arnfjörð Bjarmason

Make Git's gettext messages available to Perl programs through Locale::Messages. Gracefully fall back to English on systems that don't contain the module.

---
 Makefile            |    4 ++-
 git-send-email.perl |    3 +-
 perl/Git/Gettext.pm |   83 +++++++++++++++++++++++++++++++++++++++++++++++++++
 perl/Makefile.PL    |    5 ++-
 4 files changed, 92 insertions(+), 3 deletions(-)
 create mode 100644 perl/Git/Gettext.pm
Makefile +3 -1
index dce2faa..2101713 100644
@@ -1884,7 +1884,9 @@ cscope:
 	$(FIND) . -name '*.[hcS]' -print | xargs cscope -b
 
 pot:
-	$(XGETTEXT) -k_ -o po/git.pot $(C_OBJ:o=c) $(SCRIPT_SH)
+	$(XGETTEXT) --keyword=_ --output=po/git.pot --language=C $(C_OBJ:o=c)
+	$(XGETTEXT) --join-existing --output=po/git.pot --language=Shell $(SCRIPT_SH)
+	$(XGETTEXT) --join-existing --output=po/git.pot --language=Perl $(SCRIPT_PERL)
 
 POFILES := $(wildcard po/*.po)
 MOFILES := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/git.mo,$(POFILES))
git-send-email.perl +2 -1
index 111c981..a36718e 100755
@@ -26,6 +26,7 @@ use Term::ANSIColor;
 use File::Temp qw/ tempdir tempfile /;
 use Error qw(:try);
 use Git;
+use Git::Gettext qw< :all >;
 
 Getopt::Long::Configure qw/ pass_through /;
 
@@ -674,7 +675,7 @@ if (!defined $sender) {
 	$sender = $repoauthor || $repocommitter || '';
 	$sender = ask("Who should the emails appear to be from? [$sender] ",
 	              default => $sender);
-	print "Emails will be sent from: ", $sender, "\n";
+	printf gettext("Emails will be sent from: %s\n"), $sender;
 	$prompting++;
 }
 
perl/Git/Gettext.pm new file +83 -0

83 lines not on this page · raw message

perl/Makefile.PL +4 -1
index 0b9deca..702ec7c 100644
@@ -16,7 +16,10 @@ endif
 MAKE_FRAG
 }
 
-my %pm = ('Git.pm' => '$(INST_LIBDIR)/Git.pm');
+my %pm = (
+	'Git.pm' => '$(INST_LIBDIR)/Git.pm',
+	'Git/Gettext.pm' => '$(INST_LIBDIR)/Git/Gettext.pm',
+);
 
 # We come with our own bundled Error.pm. It's not in the set of default
 # Perl modules so install it if it's not available on the system yet.
Signature · 1 line
1.7.1.248.gcd6d1
#18 lore raw

PATCH v2 6/6 gettext: Add a skeleton po/is.po

In reply to Ævar Arnfjörð Bjarmason

This example is.po file translates a little bit of C, Shell and Perl as an example.

---
 po/is.po |  282 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 282 insertions(+), 0 deletions(-)
 create mode 100644 po/is.po
po/is.po new file +282 -0
new file mode 100644
index 0000000..b716e23
@@ -0,0 +1,282 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: Git\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2010-05-30 19:24+0000\n"
+"PO-Revision-Date: 2010-05-30 19:31+0000\n"
+"Last-Translator: Ævar Arnfjörð Bjarmason <[email protected]>\n"
+"Language-Team: Git Mailing List <[email protected]>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Poedit-Language: English\n"
+"X-Poedit-SourceCharset: utf-8\n"
+
+#: wt-status.c:53
+msgid "# Unmerged paths:"
+msgstr ""
+
+#: wt-status.c:59 wt-status.c:76
+#, c-format
+msgid "#   (use \"git reset %s <file>...\" to unstage)"
+msgstr ""
+
+#: wt-status.c:61 wt-status.c:78
+msgid "#   (use \"git rm --cached <file>...\" to unstage)"
+msgstr ""
+
+#: wt-status.c:62
+msgid "#   (use \"git add/rm <file>...\" as appropriate to mark resolution)"
+msgstr ""
+
+#: wt-status.c:63 wt-status.c:79 wt-status.c:98 wt-status.c:110
+#: wt-status.c:115 wt-status.c:638 wt-status.c:640
+msgid "#"
+msgstr ""
+
+#: wt-status.c:70
+msgid "# Changes to be committed:"
+msgstr ""
+
+#: wt-status.c:88
+msgid "# Changed but not updated:"
+msgstr ""
+
+#: wt-status.c:92
+msgid "#   (use \"git add <file>...\" to update what will be committed)"
+msgstr ""
+
+#: wt-status.c:94
+msgid "#   (use \"git add/rm <file>...\" to update what will be committed)"
+msgstr ""
+
+#: wt-status.c:95
+msgid ""
+"#   (use \"git checkout -- <file>...\" to discard changes in working "
+"directory)"
+msgstr ""
+
+#: wt-status.c:97
+msgid "#   (commit or discard the untracked or modified content in submodules)"
+msgstr ""
+
+#: wt-status.c:106
+#, c-format
+msgid "# %s files:"
+msgstr ""
+
+#: wt-status.c:109
+#, c-format
+msgid "#   (use \"git %s <file>...\" to include in what will be committed)"
+msgstr ""
+
+#: wt-status.c:126
+msgid "bug"
+msgstr ""
+
+#: wt-status.c:129 wt-status.c:182
+msgid "#\t"
+msgstr ""
+
+#: wt-status.c:131
+msgid "both deleted:"
+msgstr ""
+
+#: wt-status.c:132
+msgid "added by us:"
+msgstr ""
+
+#: wt-status.c:133
+msgid "deleted by them:"
+msgstr ""
+
+#: wt-status.c:134
+msgid "added by them:"
+msgstr ""
+
+#: wt-status.c:135
+msgid "deleted by us:"
+msgstr ""
+
+#: wt-status.c:136
+msgid "both added:"
+msgstr ""
+
+#: wt-status.c:137
+msgid "both modified:"
+msgstr ""
+
+#: wt-status.c:139
+#, c-format
+msgid "%-20s%s\n"
+msgstr ""
+
+#: wt-status.c:165
+msgid " ("
+msgstr ""
+
+#: wt-status.c:167
+msgid "new commits, "
+msgstr ""
+
+#: wt-status.c:169
+msgid "modified content, "
+msgstr ""
+
+#: wt-status.c:171
+msgid "untracked content, "
+msgstr ""
+
+#: wt-status.c:185
+#, c-format
+msgid "new file:   %s"
+msgstr ""
+
+#: wt-status.c:188
+#, c-format
+msgid "copied:     %s -> %s"
+msgstr ""
+
+#: wt-status.c:191
+#, c-format
+msgid "deleted:    %s"
+msgstr ""
+
+#: wt-status.c:194
+#, c-format
+msgid "modified:   %s"
+msgstr ""
+
+#: wt-status.c:197
+#, c-format
+msgid "renamed:    %s -> %s"
+msgstr ""
+
+#: wt-status.c:200
+#, c-format
+msgid "typechange: %s"
+msgstr ""
+
+#: wt-status.c:203
+#, c-format
+msgid "unknown:    %s"
+msgstr ""
+
+#: wt-status.c:206
+#, c-format
+msgid "unmerged:   %s"
+msgstr ""
+
+#: wt-status.c:209
+#, c-format
+msgid "bug: unhandled diff status %c"
+msgstr ""
+
+#: wt-status.c:212
+#, c-format
+msgid "%s"
+msgstr ""
+
+#: wt-status.c:215
+#, c-format
+msgid "\n"
+msgstr ""
+
+#: wt-status.c:622
+msgid "On branch "
+msgstr "Á greininni "
+
+#: wt-status.c:629
+msgid "Not currently on any branch."
+msgstr "Ekki á neinni grein."
+
+#: wt-status.c:639
+msgid "# Initial commit"
+msgstr ""
+
+#: wt-status.c:651
+msgid "Untracked"
+msgstr ""
+
+#: wt-status.c:651
+msgid "add"
+msgstr ""
+
+#: wt-status.c:653
+msgid "Ignored"
+msgstr ""
+
+#: wt-status.c:653
+msgid "add -f"
+msgstr ""
+
+#: wt-status.c:655
+#, c-format
+msgid "# Untracked files not listed%s\n"
+msgstr ""
+
+#: wt-status.c:657
+msgid " (use -u option to show untracked files)"
+msgstr ""
+
+#: wt-status.c:663
+#, c-format
+msgid "# No changes\n"
+msgstr "# Engar breytingar\n"
+
+#: wt-status.c:667
+#, c-format
+msgid "no changes added to commit%s\n"
+msgstr ""
+
+#: wt-status.c:669
+msgid " (use \"git add\" and/or \"git commit -a\")"
+msgstr ""
+
+#: wt-status.c:671
+#, c-format
+msgid "nothing added to commit but untracked files present%s\n"
+msgstr ""
+
+#: wt-status.c:673
+msgid " (use \"git add\" to track)"
+msgstr ""
+
+#: wt-status.c:676
+msgid " (create/copy files and use \"git add\" to track)"
+msgstr ""
+
+#: wt-status.c:678 wt-status.c:681
+#, c-format
+msgid "nothing to commit%s\n"
+msgstr ""
+
+#: wt-status.c:679
+msgid " (use -u to show untracked files)"
+msgstr ""
+
+#: wt-status.c:682
+msgid " (working directory clean)"
+msgstr ""
+
+#: git-pull.sh:124
+msgid "Fetching tags only, you probably meant:"
+msgstr ""
+
+#: git-pull.sh:125
+msgid "  git fetch --tags"
+msgstr ""
+
+#: git-pull.sh:157
+msgid ""
+"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."
+msgstr ""
+
+#: git-send-email.perl:678
+#, perl-format
+msgid "Emails will be sent from: %s\n"
+msgstr "Póstarnir verða sendir frá: %s\n"
Signature · 1 line
1.7.1.248.gcd6d1
#19 lore raw

Re: [PATCH/RFC v2 6/6] gettext: Add a skeleton po/is.po

Hi Ævar,

po/is.po line 17

Quoted 3 lines · Ævar Arnfjörð Bjarmason
po/is.po new file +3 -0
+#: wt-status.c:53
+msgid "# Unmerged paths:"
+msgstr ""

On projects that use gettext, merging these line number changes can be a royal pain. In effect, the .po files are mixing semantically meaningful text and automatically generated cruft.

So my ignorant questions:

. does gettext use the #: comments for anything important? . can they be suppressed when generating the .po file? . can they be easily re-added if some translation front-end needs
them?

po/is.po line 264

Quoted 3 lines
po/is.po new file +3 -0
+#: git-pull.sh:124
+msgid "Fetching tags only, you probably meant:"
+msgstr ""

I noticed there are no printf formats among the shell scripting examples. Would we have to roll our own, like this?

gettext 'You asked me to pull without telling me which branch you
want to OP_TYPE OP_PREP, and 'branch.CURR_BRANCH.merge' in your configuration file does not tell me, either. Please try again (e.g., 'git pull <repository> <refspec>').
See git-pull(1) for details.
' |
sed "

	s/OP_TYPE/$op_type/g
	s/OP_PREP/$op_prep/g
	s/CURR_BRANCH/$curr_branch/g

"

Jonathan

#22 lore raw
In reply to Ævar Arnfjörð Bjarmason

Hi Ævar,

Quoted 6 lines · Ævar Arnfjörð Bjarmason

I made three strings in git-pull.sh translatable as a proof of concept. One problem that I ran into is that xgettext(1) seems very particular when picking up translation strings. It accepts this:

gettext "hello world"; echo

Does ‘gettext -s "hello world"’ work, too? (Just curious.)

Quoted 1 line

but not this:

[...]

Quoted 7 lines
        gettext <<"END";

hello world
END

Maybe there's a way to make it play nice. But I just used a large multiline string as a workaround.

Not so nice, but it seems that gettext expects a message id as an argument (i.e., it will only replace echo and not cat).

Quoted 3 lines

I don't know what to do about
'die gettext' other than define a 'die_gettext' wrapper function and use `xgettext --keyword=die_gettext'.

Sounds sensible.

Quoted 2 lines

One thing I haven't done is to try to go ahead and make massive changes to the Git source code to make everything translatable.

I am vaguely worried about performance. Suppose a function does

	for (i = 0; i < 1000000; i++)
		printf(_("Some interesting label: %s\n"), foo(i));

Will this compile to the equivalent of

	const char *s = _("Some interesting label: %s\n");
	for (i = 0; i < 1000000; i++)
		printf(s, foo(i));

Suppose someone decides to make that change by hand (maybe the loop is too large for the compiler to notice the potential winnings). Then presumably gcc cannot be able to type-check the format any more. Is there some way around this that avoids both speed regressions and loss of type-safety?

Apologies if this was already answered in the earlier discussion.

Thanks,
Jonathan

#23 lore raw
Quoted 1 line · Jonathan Nieder

Hi Ævar,

Hi, and thanks for taking the time to review this.

Quoted 10 lines
Quoted 6 lines · Ævar Arnfjörð Bjarmason

    I made three strings in git-pull.sh translatable as a proof of concept. One problem that I ran into is that xgettext(1) seems very particular when picking up translation strings. It accepts this:

        gettext "hello world"; echo

Does ‘gettext -s "hello world"’ work, too?  (Just curious.)

No, that just makes "-s" translatable. Even options that gettext accepts don't work either, you have to use eval_gettext "\$foo" instead of gettext -e "\$foo". The xgettext program is quite naïve like that.

Quoted 7 lines
Quoted 1 line

    but not this:

[...]

Quoted 5 lines

        gettext <<"END";
hello world
END

Quoted 5 lines
Quoted 2 lines

    Maybe there's a way to make it play nice. But I just used a large multiline string as a workaround.

Not so nice, but it seems that gettext expects a message id as an argument (i.e., it will only replace echo and not cat).

Yes. I mailed the maintainer about this. gettext would need to accept text on STDIN and xgettext would need to find the messages for it to work.

In the meantime we could just use multiline strings. It works for the test suite.

Quoted 20 lines
Quoted 3 lines

    I don't know what to do about
    'die gettext' other than define a 'die_gettext' wrapper function and use `xgettext --keyword=die_gettext'.

Sounds sensible.

Quoted 2 lines

One thing I haven't done is to try to go ahead and make massive changes to the Git source code to make everything translatable.

I am vaguely worried about performance.  Suppose a function does

       for (i = 0; i < 1000000; i++)
               printf(_("Some interesting label: %s\n"), foo(i));

Will this compile to the equivalent of

       const char *s = _("Some interesting label: %s\n"); for (i = 0; i < 1000000; i++)
               printf(s, foo(i));

Quoted 5 lines

Suppose someone decides to make that change by hand (maybe the loop is too large for the compiler to notice the potential winnings).  Then presumably gcc cannot be able to type-check the format any more.  Is there some way around this that avoids both speed regressions and loss of type-safety?

Any level of indirection is of course going to be slower, there's no way around that. I made two test programs to test this out:

test-in-loop.c:

    #include <stdio.h>
    #include <stdlib.h>
    #include <locale.h>
    #include <libintl.h>

    #define _(s) gettext(s)

    int foo(long int x) {
        return x * x;
    }

    int main(void) {
        const char *podir = "/usr/local/share/locale";
        if(!podir) puts("zomg error");
        char *ret = bindtextdomain("git", podir);
        ret = setlocale(LC_MESSAGES, "");
        ret = setlocale(LC_CTYPE, "");
        ret = textdomain("git");

        for (long int i = 0; i < 10000000; i++) {
            printf(_("Some interesting label: %ld\n"), foo(i));
        }

        return 0;
    }

test-outside-loop.c:

    #include <stdio.h>
    #include <stdlib.h>
    #include <locale.h>
    #include <libintl.h>

    #define _(s) gettext(s)

    int foo(long int x) {
        return x * x;
    }

    int main(void) {
        const char *podir = "/usr/local/share/locale";
        if(!podir) puts("zomg error");
        char *ret = bindtextdomain("git", podir);
        ret = setlocale(LC_MESSAGES, "");
        ret = setlocale(LC_CTYPE, "");
        ret = textdomain("git");

        const char *s = _("Some interesting label: %ld\n");
        for (long int i = 0; i < 10000000; i++)
            printf(s, foo(i));

        return 0;
    }

Note that I use 10 million iterations, not 1 million like in your example.

Here's how they compile:

    $ gcc -std=c99 -o test-in-loop test-in-loop.c ; gcc -std=c99 -o
test-outside-loop test-outside-loop.c
    test-in-loop.c: In function ‘main’:
    test-in-loop.c:21: warning: format ‘%ld’ expects type ‘long int’,
but argument 2 has type ‘int’

I.e. your concerns are valid. GCC won't catch an invalid format specifier in this case.

And even though gettext tries to make cases like these fast
(http://www.gnu.org/software/hello/manual/gettext/Optimized-gettext.html)
it's still a lot slower than hardcoded English:

    perl -MBenchmark=:all -MData::Dump=dump -E 'cmpthese(10, {
         outside => sub { system "./test-outside-loop >/dev/null" },
         inside =>  sub { system "./test-in-loop >/dev/null" },
    });'

            s/iter  inside outside
    inside    13.4      --    -83%
    outside   2.26    495%      --
Quoted 1 line

Apologies if this was already answered in the earlier discussion.

What you can do (and this was covered) is to use msgfmt to check that no translations use different format specifiers. But hopefully cases where you have messages like these in tight loops and the message lookup itself is a significant contributor to the program time will be so rare as to not be an issue.

#8 lore raw

Re: [PATCH/RFC v2 1/6] Add infrastructure for translating Git with gettext

In reply to Ævar Arnfjörð Bjarmason
Quoted 5 lines · Ævar Arnfjörð Bjarmason

From: Jeff Epler <[email protected]>

Change the build process to use GNU's libintl if it's available. If not we define our own skeleton replacement functions which degrade gracefully to English.

Very nice.

Quoted 12 lines
---
 Makefile    |   26 ++++++++++++
 gettext.c   |   17 ++++++++
 gettext.h   |   15 +++++++
 git.c       |    3 +
 wt-status.c |  129 ++++++++++++++++++++++++++++++-----------------------------
 5 files changed, 126 insertions(+), 64 deletions(-)
 create mode 100644 gettext.c
 create mode 100644 gettext.h

Could you also provide change to configure.ac, so that ./configure would detect if we have gettext installed or not? Thanks in advance.

Signature · 3 lines
Jakub Narebski
Poland
ShadeHawk on #git
#9 lore raw

[PATCH/RCF] autoconf: Check if <libintl.h> exists and set NO_GETTEXT

---

Quoted 3 lines · Jakub Narebski

[...]
Could you also provide change to configure.ac, so that ./configure would detect if we have gettext installed or not? Thanks in advance.

Here's a check that just checks if we have libintl.h similar to the existing checks for libgen.h and other headers.

Do you think this be adequate?

 config.mak.in |    1 +
 configure.ac  |    6 ++++++
 2 files changed, 7 insertions(+), 0 deletions(-)
config.mak.in +1 -0
index 0d4b64d..a15f3c1 100644
@@ -32,6 +32,7 @@ NO_CURL=@NO_CURL@
 NO_EXPAT=@NO_EXPAT@
 NO_LIBGEN_H=@NO_LIBGEN_H@
 HAVE_PATHS_H=@HAVE_PATHS_H@
+NO_GETTEXT=@NO_GETTEXT@
 NEEDS_LIBICONV=@NEEDS_LIBICONV@
 NEEDS_SOCKET=@NEEDS_SOCKET@
 NEEDS_RESOLV=@NEEDS_RESOLV@
configure.ac +6 -0
index 71038fc..7bebfd8 100644
@@ -730,6 +730,12 @@ AC_CHECK_HEADER([paths.h],
 [HAVE_PATHS_H=])
 AC_SUBST(HAVE_PATHS_H)
 #
+# Define NO_GETTEXT if you don't have libintl.h
+AC_CHECK_HEADER([libintl.h],
+[NO_GETTEXT=],
+[NO_GETTEXT=YesPlease])
+AC_SUBST(NO_GETTEXT)
+#
 # Define NO_STRCASESTR if you don't have strcasestr.
 GIT_CHECK_FUNC(strcasestr,
 [NO_STRCASESTR=],
Signature · 1 line
1.7.1.243.g01eae
#10 lore raw

Re: [PATCH/RCF] autoconf: Check if <libintl.h> exists and set NO_GETTEXT

Quoted 9 lines · Ævar Arnfjörð Bjarmason
Quoted 3 lines · Jakub Narebski

[...]
Could you also provide change to configure.ac, so that ./configure would detect if we have gettext installed or not? Thanks in advance.

Here's a check that just checks if we have libintl.h similar to the existing checks for libgen.h and other headers.

Do you think this be adequate?

I'm not sure. If NO_GETTEXT is used only to protect '#include <libintl.h>' it might be enough.

Quoted 10 lines
 config.mak.in |    1 +
 configure.ac  |    6 ++++++
 2 files changed, 7 insertions(+), 0 deletions(-)
config.mak.in +0 -0
index 0d4b64d..a15f3c1 100644

config.mak.in NO_CURL=@NO_CURL@ · line 38

Quoted 7 lines
config.mak.in +1 -0
@@ -32,6 +32,7 @@ NO_CURL=@NO_CURL@
 NO_EXPAT=@NO_EXPAT@
 NO_LIBGEN_H=@NO_LIBGEN_H@
 HAVE_PATHS_H=@HAVE_PATHS_H@
+NO_GETTEXT=@NO_GETTEXT@
 NEEDS_LIBICONV=@NEEDS_LIBICONV@
 NEEDS_SOCKET=@NEEDS_SOCKET@
 NEEDS_RESOLV=@NEEDS_RESOLV@

O.K.

Quoted 7 lines
configure.ac +0 -0
index 71038fc..7bebfd8 100644
@@ -730,6 +730,12 @@ AC_CHECK_HEADER([paths.h],
 [HAVE_PATHS_H=])
 AC_SUBST(HAVE_PATHS_H)

configure.ac AC_CHECK_HEADER([paths.h], · line 741

Quoted 10 lines
configure.ac +6 -0
 #
+# Define NO_GETTEXT if you don't have libintl.h
+AC_CHECK_HEADER([libintl.h],
+[NO_GETTEXT=],
+[NO_GETTEXT=YesPlease])
+AC_SUBST(NO_GETTEXT)
+#
 # Define NO_STRCASESTR if you don't have strcasestr.
 GIT_CHECK_FUNC(strcasestr,
 [NO_STRCASESTR=],

The getext documentation says that `gettext.m4' defines AM_GNU_GETTEXT macro that tests for the presence of GNU gettext function family.

The complication is that `gettext.m4' might not exist, and then AM_GNU_GETTEXT would be not defined. So if we are to use AM_GNU_GETTEXT, we should I guess protect it with m4_ifdef():

m4_ifdef([AM_GNU_GETTEXT], [AM_GNU_GETTEXT([external])])

or something like that. And of course we need to work around the fact that AM_GNU_GETTEXT sets USE_NLS to either 'yes' or 'no' instead of setting setting NO_GETTEXT to either non-empty or empty value.

Or we can do something similar to what we do for NEEDS_LIBICINV / NO_ICONV, namely make ./configure compile simple test program using gettext.

Cc-ed Ben Walton and David M. Syzdek: perhaps they can help with this issue.

Signature · 2 lines
Jakub Narebski
Poland
#15 lore raw

Re: [PATCH/RFC v2 5/6] gettext: Add a Gettext interface for Perl

In reply to Ævar Arnfjörð Bjarmason
Quoted 3 lines · Ævar Arnfjörð Bjarmason

Make Git's gettext messages available to Perl programs through Locale::Messages. Gracefully fall back to English on systems that don't contain the module.

This is I think a very good idea, both providing wrapper with fallback to untranslated messages (and encapsulating translation), and using the Locale::Messages module from libintl-perl library. The "On the state of i18n in Perl" (http://rassie.org/archives/247) blog post from 26 April 2009 provides nice counterpoint to Locale::Maketext::TPJ13 / The Perl Journal #13 article[1] from 1999... especially because using gettext is natural for translating git command output and GUI, because git uses it already for Tcl/Tk (gitk and git-gui), and it is natural solution for code in C, which slightly less than half of git code.

Well, we could use Locale::Maketext::Gettext, but it is not in Perl core either, and as http://rassie.org/archives/247 says its '*.po' files are less natural. The gettext documentation (gettext.info) also recommends libintl-perl, or to be more exact Locale::TextDomain from it.

[1] http://search.cpan.org/perldoc?Locale::Maketext::TPJ13
http://interglacial.com/~sburke/tpj/as_html/tpj13.html

The question is why not use Locale::TextDomain, the high-level Perl-y framework, wrapper around Locale::Messages from the same libintl-perl library? The gettext documentation (in gettext.info, chapter "13.5.18 Perl") says:

Prerequisite
`use POSIX;'
`use Locale::TextDomain;' (included in the package libintl-perl which is available on the Comprehensive Perl Archive Network CPAN,
http://www.cpan.org/).

This would change

- print "Emails will be sent from: ", $sender, "\n";
+ printf gettext("Emails will be sent from: %s\n"), $sender;

to either

+ print __"Emails will be sent from: ", $sender, "\n";

or

+ printf __("Emails will be sent from: %s\n"), $sender;

or

+ print __x("Emails will be sent from: {sender}\n",
+ sender => $sender);

Quoted 15 lines
---
 Makefile            |    4 ++-
 git-send-email.perl |    3 +-
 perl/Git/Gettext.pm |   83 +++++++++++++++++++++++++++++++++++++++++++++++++++
 perl/Makefile.PL    |    5 ++-
 4 files changed, 92 insertions(+), 3 deletions(-)
 create mode 100644 perl/Git/Gettext.pm
Makefile +0 -0
index dce2faa..2101713 100644

Makefile cscope: · line 1888

Quoted 6 lines
Makefile +2 -1
@@ -1884,7 +1884,9 @@ cscope:
 	$(FIND) . -name '*.[hcS]' -print | xargs cscope -b
 
 pot:
-	$(XGETTEXT) -k_ -o po/git.pot $(C_OBJ:o=c) $(SCRIPT_SH)
+	$(XGETTEXT) --keyword=_ --output=po/git.pot --language=C $(C_OBJ:o=c)
+	$(XGETTEXT) --join-existing --output=po/git.pot --language=Shell $(SCRIPT_SH)

Shouldn't this line be in earlier patch, i.e. in "gettext: Add a Gettext interface for shell scripts"?

Makefile cscope: · line 1889

Quoted 1 line
Makefile +1 -0
+	$(XGETTEXT) --join-existing --output=po/git.pot --language=Perl $(SCRIPT_PERL)

From gettext documentation (in gettext.info, chapter "13.5.18 Perl"):

Extractor

     `xgettext -k__ -k\$__ -k%__ -k__x -k__n:1,2 -k__nx:1,2 -k__xn:1,2
     -kN__ -k'

Is it equivalent to specifying 'xgettext --language=Perl'?

Of course the above assumes that you are using Locale::TextDomain, or at least use the same conventions.

git-send-email.perl use Term::ANSIColor; · line 29

Quoted 12 lines
Makefile +0 -0
 POFILES := $(wildcard po/*.po)
 MOFILES := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/git.mo,$(POFILES))
git-send-email.perl +1 -0
index 111c981..a36718e 100755
@@ -26,6 +26,7 @@ use Term::ANSIColor;
 use File::Temp qw/ tempdir tempfile /;
 use Error qw(:try);
 use Git;
+use Git::Gettext qw< :all >;

Please follow the existing convention, i.e.

  +use Git::Gettext qw(:all);

like you see in context line for 'use Error'.

Well, not that git-send-email.perl is very consistent about this issue, see 'use File::Temp qw/ tempdir tempfile /;' versus 'use Error qw(:try);' but I'd reather you didn't introduce yet another form.

git-send-email.perl if (!defined $sender) { · line 678

Quoted 9 lines
git-send-email.perl +1 -1
 Getopt::Long::Configure qw/ pass_through /;
 
@@ -674,7 +675,7 @@ if (!defined $sender) {
 	$sender = $repoauthor || $repocommitter || '';
 	$sender = ask("Who should the emails appear to be from? [$sender] ",
 	              default => $sender);
-	print "Emails will be sent from: ", $sender, "\n";
+	printf gettext("Emails will be sent from: %s\n"), $sender;

As I wrote, this IMHO should be either

  +	printf __("Emails will be sent from: %s\n"), $sender;

or

  +	print __x("Emails will be sent from: {sender}\n", sender => $sender);

(note that parantheses differ in those two examples).

perl/Git/Gettext.pm line 1

Quoted 10 lines
git-send-email.perl +0 -0
 	$prompting++;
 }
 
perl/Git/Gettext.pm new file +1 -0
new file mode 100644
index 0000000..f434783
@@ -0,0 +1,83 @@
+package Git::Gettext;

Should this package be named Git::Gettext, or other name would be better, perhaps Git::I18N (like e.g. Games::Risk have Games::Risk::I18N), or Git::Locale, or even Git::Translator?

Not very important.

perl/Git/Gettext.pm line 5

Quoted 4 lines
perl/Git/Gettext.pm new file +4 -0
+use strict;
+use warnings;
+use Exporter;
+use base 'Exporter';

O.K.

The alternative would be to use

  +use Exporter qw(import);

perl/Git/Gettext.pm line 10

Quoted 5 lines
perl/Git/Gettext.pm new file +5 -0
+
+our $VERSION = '0.01';
+
+our @EXPORT;
+our @EXPORT_OK = qw< gettext >;

Same comment as above: more common way is to use qw(gettext) not qw< gettext >; it is also the notation used in Exporter documentation.

perl/Git/Gettext.pm line 12

Quoted 2 lines
perl/Git/Gettext.pm new file +2 -0
+our %EXPORT_TAGS;
+@{ $EXPORT_TAGS{'all'} } = @EXPORT_OK;

Why not simply

  +our %EXPORT_TAGS = ('all' => [ @EXPORT_OK ]);

or the reverse

  +our %EXPORT_TAGS = ('all' => [qw(gettext)]);
  +our @EXPORT_OK   = @{$EXPORT_TAGS{'all'}};

or the reverse using tag utility functions

  +our %EXPORT_TAGS = ('all' => [qw(gettext)]);
  +Exporter::export_ok_tags('all');

perl/Git/Gettext.pm line 19

Quoted 7 lines
perl/Git/Gettext.pm new file +7 -0
+
+sub __bootstrap_locale_messages {
+	our $TEXTDOMAIN = 'git';
+
+	# TODO: How do I make the sed replacements in the top level
+	# Makefile reach me here?
+	#our $TEXTDOMAINDIR = q|@@LOCALEDIR@@|;

In Perl (well, in gitweb/gitweb.perl) we use '++VAR++' and not '@@VAR@@' for placeholders, because '@' is sigil in Perl. This is not important in above example, because it is not interpolated string.

Make invoked on perl/Makefile, when invoked from main Makefile by '$(MAKE) -C perl' (via QUIET_SUBDIR0) passes 'localedir' to submake; perl/Makefile should probably have something like

  localedir ?= $(sharedir)/locale

That is assuming that 'localedir' is added to list of exported variables.

But I am not sure how such substitution should be performed.

perl/Git/Gettext.pm line 20

Quoted 1 line
perl/Git/Gettext.pm new file +1 -0
+	our $TEXTDOMAINDIR = q</usr/local/share/locale>;

Why q<...> and not simply '...'?

Quoted 4 lines
perl/Git/Gettext.pm new file +4 -0
+
+	require POSIX;
+	POSIX->import(qw< setlocale >);
+	# Non-core prerequisite module

perl/Git/Gettext.pm line 34

Quoted 10 lines
perl/Git/Gettext.pm new file +10 -0
+	require Locale::Messages;
+	Locale::Messages->import(qw< :locale_h :libintl_h >);
+
+	setlocale(LC_MESSAGES(), '');
+	setlocale(LC_CTYPE(), '');
+	textdomain($TEXTDOMAIN);
+	bindtextdomain($TEXTDOMAIN => $TEXTDOMAINDIR);
+
+	return;
+}

This would probably be a bit simpler with Locale::TextDomain.

perl/Git/Gettext.pm line 42

Quoted 8 lines
perl/Git/Gettext.pm new file +8 -0
+
+BEGIN
+{
+	local ($@, $!);
+	eval { __bootstrap_locale_messages() };
+	if ($@) {
+		# Oh noes, no Locale::Messages here
+		*gettext = sub ($) { $_[0] };

Do you intended to use subroutine protytype here? Ah, I see that Locale::Messages::gettext has the same prototype...

perl/Git/Gettext.pm line 44

Quoted 2 lines
perl/Git/Gettext.pm new file +2 -0
+	}
+}

Does it need to be in BEGIN block? Probably yes.

perl/Git/Gettext.pm line 49

Quoted 5 lines
perl/Git/Gettext.pm new file +5 -0
+
+1;
+
+__END__
+

It's nice that you have provided documentation.

perl/Git/Gettext.pm line 58

Quoted 9 lines
perl/Git/Gettext.pm new file +9 -0
+=head1 NAME
+
+Git::Gettext - Perl interface to Git's Gettext localizations
+
+=head1 DESCRIPTION
+
+Git's internal interface to Gettext via L<Locale::Messages>. If
+L<Locale::Messages> can't be loaded (it's not a core module) we
+provide stub passthrough fallbacks.

Very good.

It would probably be better though to use L<Locale::TextDomain> instead of low(er)-level L<Locale::Messages>.

perl/Git/Gettext.pm line 65

Quoted 7 lines
perl/Git/Gettext.pm new file +7 -0
+
+=head1 FUNCTIONS
+
+=head2 gettext($)
+
+L<Locale::Messages>'s gettext function if all goes well, otherwise our
+passthrough fallback function.

Other packages use _T() function for that, or like Locale::TextDomain __() function.

perl/Git/Gettext.pm line 70

Quoted 5 lines
perl/Git/Gettext.pm new file +5 -0
+
+=head1 EXPORTS
+
+Exports are done via L<Exporter>. Invididual functions can be
+exporter, or all of them via the C<:all> export tag.

Shouldn't this be described in less technical way in SYNOPSIS and DESCRIPTION sections instead?

perl/Git/Gettext.pm line 81

Quoted 11 lines
perl/Git/Gettext.pm new file +11 -0
+
+=head1 AUTHOR
+
+E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <[email protected]>
+
+=head1 LICENSE AND COPYRIGHT
+
+Copyright 2010 E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <[email protected]>
+
+This program is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.

Which is dual licensed: GPL + Perl artistic.

Was it intended to use 'same terms as Perl itself' rather than GPLv2 or GPLv2+?

Quoted 21 lines
perl/Git/Gettext.pm new file +2 -0
+
+=cut
perl/Makefile.PL +4 -1
index 0b9deca..702ec7c 100644
@@ -16,7 +16,10 @@ endif
 MAKE_FRAG
 }
 
-my %pm = ('Git.pm' => '$(INST_LIBDIR)/Git.pm');
+my %pm = (
+	'Git.pm' => '$(INST_LIBDIR)/Git.pm',
+	'Git/Gettext.pm' => '$(INST_LIBDIR)/Git/Gettext.pm',
+);
 
 # We come with our own bundled Error.pm. It's not in the set of default
 # Perl modules so install it if it's not available on the system yet.
Signature · 1 line
1.7.1.248.gcd6d1
Signature · 3 lines
Jakub Narebski
Poland
ShadeHawk on #git
#16 lore raw

Re: [PATCH/RFC v2 5/6] gettext: Add a Gettext interface for Perl

Quoted 17 lines · Jakub Narebski
Quoted 3 lines · Ævar Arnfjörð Bjarmason

Make Git's gettext messages available to Perl programs through Locale::Messages. Gracefully fall back to English on systems that don't contain the module.

This is I think a very good idea, both providing wrapper with fallback to untranslated messages (and encapsulating translation), and using the Locale::Messages module from libintl-perl library.  The "On the state of i18n in Perl" (http://rassie.org/archives/247) blog post from 26 April 2009 provides nice counterpoint to Locale::Maketext::TPJ13 / The Perl Journal #13 article[1] from 1999... especially because using gettext is natural for translating git command output and GUI, because git uses it already for Tcl/Tk (gitk and git-gui), and it is natural solution for code in C, which slightly less than half of git code.

Quoted 8 lines

Well, we could use Locale::Maketext::Gettext, but it is not in Perl core either, and as http://rassie.org/archives/247 says its '*.po' files are less natural.  The gettext documentation (gettext.info) also recommends libintl-perl, or to be more exact Locale::TextDomain from it.

[1] http://search.cpan.org/perldoc?Locale::Maketext::TPJ13
   http://interglacial.com/~sburke/tpj/as_html/tpj13.html

Locale::Maketext is a less complete and non-standard alternative as the above blogs note. I think the main reason it's used in favor of Gettext in many Perl projects is that it can be compiled stand-alone from the CPAN, i.e. it doesn't depend on libintl.

That's comfortable when CPAN is your main distribution channel, but Git's main distribution channel is via OS packages, which can trivially introduce a gettext dependency (for which they doubtless already have a package).

Locale::Maketext has a Gettext emulation layer, but using it would be a potential source of bugs (no emulation is perfect).

That being said the way I wrote Git::Gexttext means any alterante implementation or emulation layer can be seemlessly added later on. We could use (or write) something for Perl, C or Shell that completely bypasses libintl for systems that don't have a gettext C library.

Quoted 21 lines

The question is why not use Locale::TextDomain, the high-level Perl-y framework, wrapper around Locale::Messages from the same libintl-perl library?  The gettext documentation (in gettext.info, chapter "13.5.18 Perl") says:

 Prerequisite
    `use POSIX;'
    `use Locale::TextDomain;' (included in the package libintl-perl which is available on the Comprehensive Perl Archive Network CPAN,
    http://www.cpan.org/).

This would change

 -      print "Emails will be sent from: ", $sender, "\n";
 +      printf gettext("Emails will be sent from: %s\n"), $sender;

to either

 +      print __"Emails will be sent from: ", $sender, "\n";

Quoted 8 lines

or

 +      printf __("Emails will be sent from: %s\n"), $sender;

or

 +      print __x("Emails will be sent from: {sender}\n",
 +                sender => $sender);

I didn't use Locale::TextDomain because it exports a fatter interface by default, and I'm not sure at this point what subset of it it would make sense to support.

This is the default Locale::TexdDomain interface:

@EXPORT = qw (__ __x __n __nx __xn __p __px __np __npx $__ %__

                 N__ N__n N__p N__np);

My Git::Gettext only exports a single gettext() function now. I think it's better at this point to have a really small interface and decide later if we'd like to expand it, preferably in a way that'll work consistently across C, Perl and Shell programs.

We might want to improve plural support, add msgctxt etc. later. But for an initial implementation I'd rather have something simple & stupid.

Quoted 16 lines
Quoted 16 lines

---
 Makefile            |    4 ++-
 git-send-email.perl |    3 +-
 perl/Git/Gettext.pm |   83 +++++++++++++++++++++++++++++++++++++++++++++++++++ perl/Makefile.PL    |    5 ++-

 4 files changed, 92 insertions(+), 3 deletions(-)

 create mode 100644 perl/Git/Gettext.pm

Makefile +0 -0
index dce2faa..2101713 100644
@@ -1884,7 +1884,9 @@ cscope:

      $(FIND) . -name '*.[hcS]' -print | xargs cscope -b

Quoted 7 lines
Quoted 4 lines

 pot:
-     $(XGETTEXT) -k_ -o po/git.pot $(C_OBJ:o=c) $(SCRIPT_SH)
+     $(XGETTEXT) --keyword=_ --output=po/git.pot --language=C $(C_OBJ:o=c)
+     $(XGETTEXT) --join-existing --output=po/git.pot --language=Shell $(SCRIPT_SH)

Shouldn't this line be in earlier patch, i.e. in "gettext: Add a Gettext interface for shell scripts"?

It needed to be split up into seperate line in the Perl commit because ...

Quoted 9 lines
Quoted 1 line

+     $(XGETTEXT) --join-existing --output=po/git.pot --language=Perl $(SCRIPT_PERL)

From gettext documentation (in gettext.info, chapter "13.5.18 Perl"):

 Extractor
    `xgettext -k__ -k\$__ -k%__ -k__x -k__n:1,2 -k__nx:1,2 -k__xn:1,2 -kN__ -k'

Is it equivalent to specifying 'xgettext --language=Perl'?

I'm doing --language=Perl because gettext doesn't recognize .perl as a valid Perl extension. It only knows about pl', PL', pm', cgi'. (As an aside, I haven't found why Git chose to use the quaint .perl extension).

But yeah, using --language=Perl is overshooting it with regards to keyword extraction. From "5.1 Invoking the `xgettext' Program":

To disable the default keyword specifications, the option -k' or --keyword' or `--keyword=', without a KEYWORDSPEC, can be used.

I'll check if I can supply --keyword to all the XGETTEXT invocations.

Quoted 20 lines

Of course the above assumes that you are using Locale::TextDomain, or at least use the same conventions.

git-send-email.perl use Term::ANSIColor; · line 29

Quoted 12 lines

 POFILES := $(wildcard po/*.po)
 MOFILES := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/git.mo,$(POFILES))

git-send-email.perl +1 -0
index 111c981..a36718e 100755
@@ -26,6 +26,7 @@ use Term::ANSIColor;
  use File::Temp qw/ tempdir tempfile /;
  use Error qw(:try);
  use Git;
+use Git::Gettext qw< :all >;

Please follow the existing convention, i.e.

 +use Git::Gettext qw(:all);

Quoted 7 lines

like you see in context line for 'use Error'.

Well, not that git-send-email.perl is very consistent about this issue, see 'use File::Temp qw/ tempdir tempfile /;' versus 'use Error qw(:try);' but I'd reather you didn't introduce yet another form.

OK. I'll change that. I usually just pick whatever Perl quote delimiters that happen to, literally, be close at hand at the time :)

Quoted 11 lines

git-send-email.perl if (!defined $sender) { · line 678

Quoted 8 lines
git-send-email.perl +1 -1
  Getopt::Long::Configure qw/ pass_through /;
 
@@ -674,7 +675,7 @@ if (!defined $sender) {
       $sender = $repoauthor || $repocommitter || '';
       $sender = ask("Who should the emails appear to be from? [$sender] ",
                     default => $sender);
-     print "Emails will be sent from: ", $sender, "\n";
+     printf gettext("Emails will be sent from: %s\n"), $sender;

As I wrote, this IMHO should be either

Quoted 7 lines

 +     printf __("Emails will be sent from: %s\n"), $sender;

or

 +     print __x("Emails will be sent from: {sender}\n", sender => $sender);

(note that parantheses differ in those two examples).

I'd prefer the former argument expansion form (i.e. %s, not {$sender}), just so translators don't have to deal with two different argument forms.

As for __ or gettext I don't mind. I just picked the former on a whim to match the Shell version. Maybe I should just change C|Perl|Shell to use _?

And we can use _, __ is just used to disambiguate it from the _ filehandle, and Perl's pretty good at disambiguating that already:

    $ perl -E 'sub _ ($) { scalar reverse $_[0] }; say _("moo"); stat
"/etc/hosts"; say ((stat(_))[7])'
    oom
    168
Quoted 15 lines

perl/Git/Gettext.pm line 1

Quoted 10 lines
git-send-email.perl +0 -0
       $prompting++;
  }
 
perl/Git/Gettext.pm new file +1 -0
new file mode 100644
index 0000000..f434783
@@ -0,0 +1,83 @@
+package Git::Gettext;

Should this package be named Git::Gettext, or other name would be better, perhaps Git::I18N (like e.g. Games::Risk have Games::Risk::I18N), or Git::Locale, or even Git::Translator?

Quoted 1 line

Not very important.

I really have no opinion on that, but it does seem like a lot of Perl packages on CPAN use the ::I18N suffix.

Quoted 10 lines

perl/Git/Gettext.pm line 5

Quoted 4 lines
perl/Git/Gettext.pm new file +4 -0
+use strict;
+use warnings;
+use Exporter;
+use base 'Exporter';

O.K.

The alternative would be to use

 +use Exporter qw(import);

Not if we want to maintain 5.6 support. The `use Exporter "import"' form was only introduced in 5.8. I use it everywhere where I don't have to care about 5.6 support (which is everywhere but Git).

Quoted 8 lines

perl/Git/Gettext.pm line 10

Quoted 5 lines
perl/Git/Gettext.pm new file +5 -0
+
+our $VERSION = '0.01';
+
+our @EXPORT;
+our @EXPORT_OK = qw< gettext >;

Same comment as above: more common way is to use qw(gettext) not qw< gettext >; it is also the notation used in Exporter documentation.

Will do.

Quoted 9 lines

perl/Git/Gettext.pm line 12

Quoted 2 lines
perl/Git/Gettext.pm new file +2 -0
+our %EXPORT_TAGS;
+@{ $EXPORT_TAGS{'all'} } = @EXPORT_OK;

Why not simply

 +our %EXPORT_TAGS = ('all' => [ @EXPORT_OK ]);

or the reverse

Quoted 7 lines

 +our %EXPORT_TAGS = ('all' => [qw(gettext)]);
 +our @EXPORT_OK   = @{$EXPORT_TAGS{'all'}};

or the reverse using tag utility functions

 +our %EXPORT_TAGS = ('all' => [qw(gettext)]);
 +Exporter::export_ok_tags('all');

Just because it some old code of mine I had around that I copied from. I could rewrite it to a nicer form.

Actually I was considering changing it to just have @EXPORT and nothing else. You're going to use gettext if you use the medule anyway, so we might as well just import them all everywhere we use Gettext in Perl.

Quoted 11 lines

perl/Git/Gettext.pm line 19

Quoted 7 lines
perl/Git/Gettext.pm new file +7 -0
+
+sub __bootstrap_locale_messages {
+     our $TEXTDOMAIN = 'git';
+
+     # TODO: How do I make the sed replacements in the top level
+     # Makefile reach me here?
+     #our $TEXTDOMAINDIR = q|@@LOCALEDIR@@|;

In Perl (well, in gitweb/gitweb.perl) we use '++VAR++' and not '@@VAR@@' for placeholders, because '@' is sigil in Perl.  This is not important in above example, because it is not interpolated string.

I'll change it to follow that convention.

Quoted 10 lines

Make invoked on perl/Makefile, when invoked from main Makefile by '$(MAKE) -C perl' (via QUIET_SUBDIR0) passes 'localedir' to submake; perl/Makefile should probably have something like

 localedir ?= $(sharedir)/locale

That is assuming that 'localedir' is added to list of exported variables.

But I am not sure how such substitution should be performed.

I'll try to get something like that to work. Actually the main problem seemed to be that it had a hybrid handwritten Makefile and one made by EU::MM.

Quoted 3 lines

perl/Git/Gettext.pm line 20

Quoted 1 line
perl/Git/Gettext.pm new file +1 -0
+     our $TEXTDOMAINDIR = q</usr/local/share/locale>;

Why q<...> and not simply '...'?

Same reason I use qw<>, that is no particular reason other than it being easier to type on my keyboard. I'll just change it to ''.

Quoted 16 lines

perl/Git/Gettext.pm line 34

Quoted 13 lines
perl/Git/Gettext.pm new file +13 -0
+     require POSIX;
+     POSIX->import(qw< setlocale >);
+     # Non-core prerequisite module
+     require Locale::Messages;
+     Locale::Messages->import(qw< :locale_h :libintl_h >);
+
+     setlocale(LC_MESSAGES(), '');
+     setlocale(LC_CTYPE(), '');
+     textdomain($TEXTDOMAIN);
+     bindtextdomain($TEXTDOMAIN => $TEXTDOMAINDIR);
+
+     return;
+}

This would probably be a bit simpler with Locale::TextDomain.

Quoted 11 lines

perl/Git/Gettext.pm line 42

Quoted 8 lines
perl/Git/Gettext.pm new file +8 -0
+
+BEGIN
+{
+     local ($@, $!);
+     eval { __bootstrap_locale_messages() };
+     if ($@) {
+             # Oh noes, no Locale::Messages here
+             *gettext = sub ($) { $_[0] };

Do you intended to use subroutine protytype here?  Ah, I see that Locale::Messages::gettext has the same prototype...

Yeah, otherwise the fallback would have different semantics.

Quoted 4 lines

perl/Git/Gettext.pm line 43

Quoted 2 lines
perl/Git/Gettext.pm new file +2 -0
+     }
+}

Does it need to be in BEGIN block?  Probably yes.

I'm pretty sure it needs to all be at BEGIN time. I recall that declaring prototypes at runtime was an error in some older versions, but it works now:

    $ perl -E '*meh = sub ($) { "foo" }; say prototype "meh"'
    $

Anyway since it's code that's being use'd it's going to always be at BEGIN time anyway. I just wanted to be explicit.

Quoted 34 lines

perl/Git/Gettext.pm line 49

Quoted 5 lines
perl/Git/Gettext.pm new file +5 -0
+
+1;
+
+__END__
+

It's nice that you have provided documentation.

perl/Git/Gettext.pm line 58

Quoted 9 lines
perl/Git/Gettext.pm new file +9 -0
+=head1 NAME
+
+Git::Gettext - Perl interface to Git's Gettext localizations
+
+=head1 DESCRIPTION
+
+Git's internal interface to Gettext via L<Locale::Messages>. If
+L<Locale::Messages> can't be loaded (it's not a core module) we
+provide stub passthrough fallbacks.

Very good.

It would probably be better though to use L<Locale::TextDomain> instead of low(er)-level L<Locale::Messages>.

perl/Git/Gettext.pm line 65

Quoted 7 lines
perl/Git/Gettext.pm new file +7 -0
+
+=head1 FUNCTIONS
+
+=head2 gettext($)
+
+L<Locale::Messages>'s gettext function if all goes well, otherwise our
+passthrough fallback function.

Other packages use _T() function for that, or like Locale::TextDomain __() function.

Quoted 8 lines

perl/Git/Gettext.pm line 70

Quoted 5 lines
perl/Git/Gettext.pm new file +5 -0
+
+=head1 EXPORTS
+
+Exports are done via L<Exporter>. Invididual functions can be
+exporter, or all of them via the C<:all> export tag.

Shouldn't this be described in less technical way in SYNOPSIS and DESCRIPTION sections instead?

Yeah, maybe. But there's a convention for `=head1 EXPORTS' in perl core / CPAN. So that's what I added at a whim.

Quoted 14 lines

perl/Git/Gettext.pm line 81

Quoted 11 lines
perl/Git/Gettext.pm new file +11 -0
+
+=head1 AUTHOR
+
+E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <[email protected]>
+
+=head1 LICENSE AND COPYRIGHT
+
+Copyright 2010 E<AElig>var ArnfjE<ouml>rE<eth> Bjarmason <[email protected]>
+
+This program is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.

Which is dual licensed: GPL + Perl artistic.

Quoted 2 lines

Was it intended to use 'same terms as Perl itself' rather than GPLv2 or GPLv2+?

It's the permissive boilerplate I auto-insert for Perl code. I'll just remove it. The COPYING file at the top level will suffice.

Quoted 21 lines
Quoted 21 lines
perl/Git/Gettext.pm new file +2 -0
+
+=cut
perl/Makefile.PL +0 -0
index 0b9deca..702ec7c 100644
@@ -16,7 +16,10 @@ endif

 MAKE_FRAG
 }

perl/Makefile.PL +4 -1
-my %pm = ('Git.pm' => '$(INST_LIBDIR)/Git.pm');
+my %pm = (
+     'Git.pm' => '$(INST_LIBDIR)/Git.pm',
+     'Git/Gettext.pm' => '$(INST_LIBDIR)/Git/Gettext.pm',
+);

 # We come with our own bundled Error.pm. It's not in the set of default # Perl modules so install it if it's not available on the system yet. --
1.7.1.248.gcd6d1

#20 lore raw

Re: [PATCH/RFC v2 6/6] gettext: Add a skeleton po/is.po

In reply to Jonathan Nieder
Quoted 11 lines · Jonathan Nieder

gettext 'You asked me to pull without telling me which branch you
want to OP_TYPE OP_PREP, and 'branch.CURR_BRANCH.merge' in your configuration file does not tell me, either. Please try again (e.g., 'git pull <repository> <refspec>').
See git-pull(1) for details.
' |
sed "

	s/OP_TYPE/$op_type/g
	s/OP_PREP/$op_prep/g
	s/CURR_BRANCH/$curr_branch/g

"

Apparently this is what "gettext -e"/eval_gettext is for. Sorry for the noise.

Jonathan

#21 lore raw

Re: [PATCH/RFC v2 6/6] gettext: Add a skeleton po/is.po

In reply to Jonathan Nieder
Quoted 12 lines · Jonathan Nieder

Hi Ęvar,

po/is.po line 17

Quoted 3 lines · Ęvar Arnfjörš Bjarmason
po/is.po new file +3 -0
+#: wt-status.c:53
+msgid "# Unmerged paths:"
+msgstr ""

On projects that use gettext, merging these line number changes can be a royal pain.  In effect, the .po files are mixing semantically meaningful text and automatically generated cruft.

Quoted 6 lines

So my ignorant questions:

 . does gettext use the #: comments for anything important? . can they be suppressed when generating the .po file? . can they be easily re-added if some translation front-end needs them?

Let me answer that more generally.

Usually when people first see the Gettext format they go "ew!". The thing is that it's really meant as a format for mixed human and programmatic editing. Almost everyone editing PO files doesn't do so purely with a simple non-PO aware text editor.

PO editors use these comments to allow you to jump to the source definition to see the message in context. E.g. Emacs's po-mode allows you to do this, and Launchpad displays the file & line number (but last I checked they didn't have an embedded viewer).

A merge of two PO files that doesn't use msgmerge(1) is going to be painful. There are some things that it'll throw out and regenerate (e.g. automated comments, those matching /^#\S/), and it might move messages around to match their new position in the respective source files. Thus a merge that might be hard with a simple git merge might be very easy with a msgmerge-based merge.

Now, we could filter out all these comments (and e.g. context comments) before checking these files in. But that would cause a lot of tools like Launchpad and PO editors to behave in unexpected ways. The Gettext utilities themselves also seem to have no support for initializing/emitting these sort of slim files.

I don't know what the answer is, but this is all something to consider. I'm new to the Gettext format myself, but I've come to like the automatic editing the tools do, especially the automaticy fuzzy tagging.

#24 lore raw
In reply to Ævar Arnfjörð Bjarmason
Quoted 4 lines · Ævar Arnfjörð Bjarmason

And even though gettext tries to make cases like these fast
(http://www.gnu.org/software/hello/manual/gettext/Optimized-gettext.html)
it's still a lot slower than hardcoded English:

Quoted 8 lines
    perl -MBenchmark=:all -MData::Dump=dump -E 'cmpthese(10, {
         outside => sub { system "./test-outside-loop >/dev/null" },
         inside =>  sub { system "./test-in-loop >/dev/null" },
    });'

            s/iter  inside outside
    inside    13.4      --    -83%
    outside   2.26    495%      --

Given:

-- 8< --
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <libintl.h>
#include "gettext.h"

int foo(long int x) {
	return x * x;
}
int main(void) {
	const char *podir = "/usr/local/share/locale";
	long int i;

	bindtextdomain("git", podir);
	setlocale(LC_MESSAGES, "");
	setlocale(LC_CTYPE, "");
	textdomain("git");

	for (i = 0; i < 1000000; i++)
		printf(_("Some interesting label: %ld\n"), foo(i));

	return 0;
}

-- >8 --

No message catalog is installed here, and I compile with gcc-4.5 -Wall -W -O2. The results are similar.

A: the standard way. gettext.h contains "#define _(s) gettext(s)" or

| static inline char *_(const char *s) __attribute__((__format_arg(1)__))
| {
|	return gettext(s);
| }

6.74user 0.02system 0:06.78elapsed 99%CPU (0avgtext+0avgdata 2304maxresident)k 0inputs+0outputs (0major+182minor)pagefaults 0swaps

(about 7 seconds.)

B: noop. gettext.h contains "#define _(s) s"

1.35user 0.01system 0:01.37elapsed 99%CPU (0avgtext+0avgdata 2192maxresident)k 0inputs+0outputs (0major+172minor)pagefaults 0swaps

(about 1.5 seconds.)

It would seem that __attribute__((__pure__)) should let the compiler give us the best of both worlds, but no luck. Even __attribute__((__const__)) is ignored; the compiler inlines the body of _() before it has a chance to notice.

We can fool the compiler into paying attention by making it not
inlinable: if gettext.h contains

| extern char *_(const char *s) __attribute__((__format_arg__(1), __const__));

and a separate gettext.c contains

| #include <libintl.h>
| #include "gettext.h"
| char *_(const char *s) { return gettext(s); }

we get the performance of B again:

1.36user 0.01system 0:01.38elapsed 98%CPU (0avgtext+0avgdata 2304maxresident)k 0inputs+0outputs (0major+180minor)pagefaults 0swaps

This amounts to lying to the compiler, since it is possible for the string pointed to by a single address s to differ between calls to _. The __pure__ attribute would be more honest, but for reasons I don’t understand it suppresses the optimization.

Moral of the story: at least in simple cases, we can keep the performance and the typechecking. Phew.

HTH,
Jonathan

#25 lore raw
Quoted 22 lines · Jonathan Nieder

[...]
It would seem that __attribute__((__pure__)) should let the compiler give us the best of both worlds, but no luck.  Even __attribute__((__const__)) is ignored; the compiler inlines the body of _() before it has a chance to notice.

We can fool the compiler into paying attention by making it not
inlinable: if gettext.h contains

| extern char *_(const char *s) __attribute__((__format_arg__(1), __const__));

and a separate gettext.c contains

| #include <libintl.h>
| #include "gettext.h"
| char *_(const char *s) { return gettext(s); }

we get the performance of B again:

 1.36user 0.01system 0:01.38elapsed 98%CPU (0avgtext+0avgdata 2304maxresident)k 0inputs+0outputs (0major+180minor)pagefaults 0swaps

Quoted 7 lines

This amounts to lying to the compiler, since it is possible for the string pointed to by a single address s to differ between calls to _.  The __pure__ attribute would be more honest, but for reasons I don’t understand it suppresses the optimization.

Moral of the story: at least in simple cases, we can keep the performance and the typechecking.  Phew.

Awesome, how portable is this? If it's just GCC I guess it can just be wrapped in #ifdef __GNUC__.

Thanks for investingating this.

#26 lore raw

v3 cover Add internationalization support to Git

In reply to Ævar Arnfjörð Bjarmason

Here's version 3 of the patch series begun by Jeff Epler to make Git optionally translatable with GNU gettext.

This version contains a lot of fixes to issues pointe out by Jakub Narebski, and other misc.

Since the last RFC:

* Squashed some infrastructure patches into the initial commit.

* Added basic sanity testing for the Gettext support

* .mo files aren't installed on make install time if NO_GETTEXT was specified during the build.

In C gettext support isn't compiled in. But this happens implicitly in Shell/Perl because the locale files won't be there on the system.

* NO_GETTEXT is now set correctly depending on whether libintl.h exists when autoconf is used to build Git. Whether this is the best approach to gettext detection with autoconf is being discussed in the "[PATCH/RCF] autoconf: Check if <libintl.h> exists and set NO_GETTEX" thread.

* The localedir is now passed to the Perl code via Makefile trickery. It's no longer hardcoded to /usr/local/share/locale

* Add --keyword= to all xgettext invocations. This way we make sure that only our gettext functions are extracted, not the defaults xgettext.

* Git::Gettext is now called Git::I18N

* Remove LICENSE from I18N.pm. It was a boilerplate that shouldn't have been there.

* Use qw() not qw< > in Perl code.

* Changed the interface to Git::I18N. Now it exports all its functions by default. If something's using the module it's going to want to import everything anyway. This makes the issue of '@{ $EXPORT_TAGS{'all'} }' being ugly syntax moot since it isn't used anymore.

Users can still import selectively by specifying arguments to import().

* The GIT_TEXTDOMAINDIR environment variable can be set to override where the C/Perl/Shell locale files are found. This is intended to be set by the test suite.

* The boolean test for whether gettext.sh was successfully loaded was inverted (oops!)

Things that haven't changed:

Jakub pointed out some things that I might want to change that I didn't yet. Mostly because I didn't have time yet.

* Git::I18N still uses Locale::Messages, not Locale::TextDomain.

I'm still not convinced that the low-level Locale::Messages interface isn't a better fit for us. But I didn't get Locale::TextDomain working at all today so I'm still using Locale::Messages.

* Perl still uses gettext($), not __($) (see above).

* use Exporter 'import': Subclassing Exporter instead since we apparently need Perl 5.6 compatibility.

Jeff Epler (1):
Add infrastructure for translating Git with gettext

Ævar Arnfjörð Bjarmason (6):
gettext: Add a Gettext interface for shell scripts
gettext: Add a Gettext interface for Perl
Makefile: Don't install Gettext .mo files if NO_GETTEXT
Makefile: Override --keyword= for all languages
gettext: Basic sanity tests for Git's Gettext support
gettext: Add a skeleton po/is.po

 .gitignore          |    1 +
 Makefile            |   43 ++++++++-
 config.mak.in       |    1 +
 configure.ac        |    6 +
 gettext.c           |   25 +++++
 gettext.h           |   13 +++
 git-pull.sh         |   15 ++--
 git-send-email.perl |    3 +-
 git-sh-setup.sh     |   33 ++++++
 git.c               |    3 +
 perl/Git/I18N.pm    |   73 +++++++++++++
 perl/Makefile       |    3 +-
 perl/Makefile.PL    |   14 +++-
 po/.gitignore       |    1 +
 po/is.po            |  282 +++++++++++++++++++++++++++++++++++++++++++++++++++
 t/t0200-gettext.sh  |   28 +++++
 wt-status.c         |  129 ++++++++++++------------
 17 files changed, 597 insertions(+), 76 deletions(-)
 create mode 100644 gettext.c
 create mode 100644 gettext.h
 create mode 100644 perl/Git/I18N.pm
 create mode 100644 po/.gitignore
 create mode 100644 po/is.po
 create mode 100755 t/t0200-gettext.sh
#27 lore raw
Quoted 9 lines · Ævar Arnfjörð Bjarmason

Here's version 3 of the patch series begun by Jeff Epler to make Git optionally translatable with GNU gettext.

This version contains a lot of fixes to issues pointe out by Jakub Narebski, and other misc.
[...]
 * The GIT_TEXTDOMAINDIR environment variable can be set to override where the C/Perl/Shell locale files are found. This is intended to be set by the test suite.

I made a silly error in my rebases and rewrote this commit out of my tree. Instead of sending new commits here's the git diff -w below:

    diff --git a/git-sh-setup.sh b/git-sh-setup.sh
    index d67901c..379c9a1 100644
    --- a/git-sh-setup.sh
    +++ b/git-sh-setup.sh
    @@ -219,7 +219,12 @@ if test $? -eq 0
     then
         TEXTDOMAIN=git
         export TEXDTOMAIN
    +	if [ -z "$GIT_TEXTDOMAINDIR" ]
    +	then
         TEXTDOMAINDIR="@@LOCALEDIR@@"
    +	else
    +		TEXTDOMAINDIR=$GIT_TEXTDOMAINDIR
    +	fi
         export TEXTDOMAINDIR
     else
         # Since GNU gettext.sh isn't available we'll have to define our
    diff --git a/perl/Git/I18N.pm b/perl/Git/I18N.pm
    index 568fd3d..e19d99b 100644
    --- a/perl/Git/I18N.pm
    +++ b/perl/Git/I18N.pm
    @@ -11,7 +11,7 @@ our @EXPORT_OK = @EXPORT;

     sub __bootstrap_locale_messages {
     	our $TEXTDOMAIN = 'git';
    -	our $TEXTDOMAINDIR = '++LOCALEDIR++';
    +	our $TEXTDOMAINDIR = $ENV{GIT_TEXTDOMAINDIR} || '++LOCALEDIR++';

     	require POSIX;
     	POSIX->import(qw(setlocale));
    diff --git a/t/t0200-gettext.sh b/t/t0200-gettext.sh
    index a8f9edd..7c2a4cb 100755
    --- a/t/t0200-gettext.sh
    +++ b/t/t0200-gettext.sh
    @@ -1,5 +1,7 @@
     #!/bin/sh

    +export GIT_TEXTDOMAINDIR=`pwd`/../share/locale
    +
     test_description='Gettext support for Git'
     . ./test-lib.sh
     . ../../git-sh-setup
    @@ -9,7 +11,8 @@ test_expect_success 'sanity: $TEXTDOMAIN is git' '
     '

     test_expect_success 'sanity: $TEXTDOMAINDIR exists' '
    -	test -d $TEXTDOMAINDIR
    +	test -d $TEXTDOMAINDIR &&
    +	test $TEXTDOMAINDIR = $GIT_TEXTDOMAINDIR
     '

     test_expect_success 'sanity: Icelandic locale was compiled' '

Along with another silly error:

    diff --git a/git-sh-setup.sh b/git-sh-setup.sh
    index 379c9a1..da8c47f 100644
    --- a/git-sh-setup.sh
    +++ b/git-sh-setup.sh
    @@ -218,7 +218,7 @@ esac
     if test $? -eq 0
     then
         TEXTDOMAIN=git
    -       export TEXDTOMAIN
    +       export TEXTDOMAIN
            if [ -z "$GIT_TEXTDOMAINDIR" ]
            then
                    TEXTDOMAINDIR="@@LOCALEDIR@@"

These fixes will be included (along with any other fixes) in my next series. Which'll be submitted after soliciting more RFC comments. Sorry everyone.

#28 lore raw

v4 cover Add internationalization support to Git

Here's version 4 of the patch series begun by Jeff Epler to make Git optionally translatable with GNU gettext.

It's like the version 4 I submitted an ~hour ago, sans the annoying errors I made and lots of tests:

Changes from v3 to v4:

* Fix typos and removal of GIT_TEXTDOMAINDIR that I rewrote out with some rebase mistakes.

* Add meaningful testing. The C, Shell and Perl wrappers are now tested as part of a new t/t0200-gettext.sh test file. Put under the t/t0* namespace because it's a core feature, and using a new t02 prefix because there'll probably be a lot of Gettext tests down the line.

Changes from v2 to v3:

* Squashed some infrastructure patches into the initial commit.

* Added basic sanity testing for the Gettext support

* .mo files aren't installed on make install time if NO_GETTEXT was specified during the build.

In C gettext support isn't compiled in. But this happens implicitly in Shell/Perl because the locale files won't be there on the system.

* NO_GETTEXT is now set correctly depending on whether libintl.h exists when autoconf is used to build Git. Whether this is the best approach to gettext detection with autoconf is being discussed in the "[PATCH/RCF] autoconf: Check if <libintl.h> exists and set NO_GETTEX" thread.

* The localedir is now passed to the Perl code via Makefile trickery. It's no longer hardcoded to /usr/local/share/locale

* Add --keyword= to all xgettext invocations. This way we make sure that only our gettext functions are extracted, not the defaults xgettext.

* Git::Gettext is now called Git::I18N

* Remove LICENSE from I18N.pm. It was a boilerplate that shouldn't have been there.

* Use qw() not qw< > in Perl code.

* Changed the interface to Git::I18N. Now it exports all its functions by default. If something's using the module it's going to want to import everything anyway. This makes the issue of '@{ $EXPORT_TAGS{'all'} }' being ugly syntax moot since it isn't used anymore.

Users can still import selectively by specifying arguments to import().

* The GIT_TEXTDOMAINDIR environment variable can be set to override where the C/Perl/Shell locale files are found. This is intended to be set by the test suite.

* The boolean test for whether gettext.sh was successfully loaded was inverted (oops!)

Things that haven't changed:

Jakub pointed out some things that I might want to change that I didn't yet. Mostly because I didn't have time yet.

* Git::I18N still uses Locale::Messages, not Locale::TextDomain.

I'm still not convinced that the low-level Locale::Messages interface isn't a better fit for us. But I didn't get Locale::TextDomain working at all today so I'm still using Locale::Messages.

* Perl still uses gettext($), not __($) (see above).

* use Exporter 'import': Subclassing Exporter instead since we apparently need Perl 5.6 compatibility.

Jeff Epler (1):
Add infrastructure for translating Git with gettext

Ævar Arnfjörð Bjarmason (6):
gettext: Add a Gettext interface for shell scripts
gettext: Add a Gettext interface for Perl
Makefile: Don't install Gettext .mo files if NO_GETTEXT
Makefile: Override --keyword= for all languages
gettext: Sanity tests for Git's Gettext support
gettext: Add a skeleton po/is.po

 .gitignore          |    1 +
 Makefile            |   43 ++++++++-
 config.mak.in       |    1 +
 configure.ac        |    6 +
 gettext.c           |   25 +++++
 gettext.h           |   13 +++
 git-pull.sh         |   15 ++--
 git-send-email.perl |    3 +-
 git-sh-setup.sh     |   38 +++++++
 git.c               |    3 +
 perl/Git/I18N.pm    |   73 +++++++++++++
 perl/Makefile       |    3 +-
 perl/Makefile.PL    |   14 +++-
 po/.gitignore       |    1 +
 po/is.po            |  282 +++++++++++++++++++++++++++++++++++++++++++++++++++
 t/t0200-gettext.sh  |   73 +++++++++++++
 wt-status.c         |  129 ++++++++++++------------
 17 files changed, 647 insertions(+), 76 deletions(-)
 create mode 100644 gettext.c
 create mode 100644 gettext.h
 create mode 100644 perl/Git/I18N.pm
 create mode 100644 po/.gitignore
 create mode 100644 po/is.po
 create mode 100755 t/t0200-gettext.sh
#29 lore raw

PATCH v4 1/7 Add infrastructure for translating Git with gettext

In reply to Ævar Arnfjörð Bjarmason

From: Jeff Epler <[email protected]>

Change the build process to use GNU's libintl if it's available. If not we define our own skeleton replacement functions which degrade gracefully to English.

Gettext .mo files will be installed and looked for in $(prefix)/share/locale. GIT_LOCALEDIR can also be set to override that, this variable is only intended for testing Git itself.

---
 .gitignore    |    1 +
 Makefile      |   30 +++++++++++++
 config.mak.in |    1 +
 configure.ac  |    6 +++
 gettext.c     |   25 +++++++++++
 gettext.h     |   13 ++++++
 git.c         |    3 +
 po/.gitignore |    1 +
 wt-status.c   |  129 +++++++++++++++++++++++++++++----------------------------
 9 files changed, 145 insertions(+), 64 deletions(-)
 create mode 100644 gettext.c
 create mode 100644 gettext.h
 create mode 100644 po/.gitignore
.gitignore +1 -0
index 14e2b6b..d22c0e5 100644
@@ -204,3 +204,4 @@
 *.pdb
 /Debug/
 /Release/
+/share/
Makefile +30 -0
index d5d6565..4de0627 100644
@@ -297,6 +297,8 @@ RPMBUILD = rpmbuild
 TCL_PATH = tclsh
 TCLTK_PATH = wish
 PTHREAD_LIBS = -lpthread
+XGETTEXT = xgettext
+MSGFMT = msgfmt
 
 export TCL_PATH TCLTK_PATH
 
@@ -523,6 +525,7 @@ LIB_H += userdiff.h
 LIB_H += utf8.h
 LIB_H += xdiff-interface.h
 LIB_H += xdiff/xdiff.h
+LIB_H += gettext.h
 
 LIB_OBJS += abspath.o
 LIB_OBJS += advice.o
@@ -564,6 +567,7 @@ LIB_OBJS += entry.o
 LIB_OBJS += environment.o
 LIB_OBJS += exec_cmd.o
 LIB_OBJS += fsck.o
+LIB_OBJS += gettext.o
 LIB_OBJS += graph.o
 LIB_OBJS += grep.o
 LIB_OBJS += hash.o
@@ -1386,6 +1390,12 @@ ifdef USE_NED_ALLOCATOR
        COMPAT_OBJS += compat/nedmalloc/nedmalloc.o
 endif
 
+ifdef NO_GETTEXT
+	COMPAT_CFLAGS += -DNO_GETTEXT
+else
+	LIBINTL = -lintl
+endif
+
 ifeq ($(TCLTK_PATH),)
 NO_TCLTK=NoThanks
 endif
@@ -1415,6 +1425,7 @@ ifndef V
 	QUIET_BUILT_IN = @echo '   ' BUILTIN $@;
 	QUIET_GEN      = @echo '   ' GEN $@;
 	QUIET_LNCP     = @echo '   ' LN/CP $@;
+	QUIET_MSGFMT   = @echo '   ' MSGFMT $@;
 	QUIET_SUBDIR0  = +@subdir=
 	QUIET_SUBDIR1  = ;$(NO_SUBDIR) echo '   ' SUBDIR $$subdir; \
 			 $(MAKE) $(PRINT_DIR) -C $$subdir
@@ -1442,6 +1453,7 @@ gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
 template_dir_SQ = $(subst ','\'',$(template_dir))
 htmldir_SQ = $(subst ','\'',$(htmldir))
 prefix_SQ = $(subst ','\'',$(prefix))
+sharedir_SQ = $(subst ','\'',$(sharedir))
 
 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
 PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
@@ -1868,6 +1880,17 @@ cscope:
 	$(RM) cscope*
 	$(FIND) . -name '*.[hcS]' -print | xargs cscope -b
 
+pot:
+	$(XGETTEXT) -k_ -o po/git.pot $(C_OBJ:o=c)
+
+POFILES := $(wildcard po/*.po)
+MOFILES := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/git.mo,$(POFILES))
+MODIRS := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/,$(POFILES))
+all:: $(MOFILES)
+share/locale/%/LC_MESSAGES/git.mo: po/%.po
+	@mkdir -p $(dir $@)
+	$(QUIET_MSGFMT)$(MSGFMT) -o $@ $<
+
 ### Detect prefix changes
 TRACK_CFLAGS = $(subst ','\'',$(ALL_CFLAGS)):\
              $(bindir_SQ):$(gitexecdir_SQ):$(template_dir_SQ):$(prefix_SQ)
@@ -1980,6 +2003,9 @@ install: all
 	$(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 	$(INSTALL) -m 644 $(SCRIPT_LIB) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 	$(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)'
+	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(sharedir_SQ)/locale'
+	(cd share && tar cf - locale) | \
+		(cd '$(DESTDIR_SQ)$(sharedir_SQ)' && umask 022 && tar xof -)
 	$(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
 ifndef NO_PERL
 	$(MAKE) -C perl prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install
@@ -2127,6 +2153,10 @@ ifndef NO_TCLTK
 	$(MAKE) -C git-gui clean
 endif
 	$(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-GUI-VARS GIT-BUILD-OPTIONS
+ifndef NO_GETTEXT
+	$(RM) po/git.pot
+	$(RM) -r share/
+endif
 
 .PHONY: all install clean strip
 .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
config.mak.in +1 -0
index 0d4b64d..a15f3c1 100644
@@ -32,6 +32,7 @@ NO_CURL=@NO_CURL@
 NO_EXPAT=@NO_EXPAT@
 NO_LIBGEN_H=@NO_LIBGEN_H@
 HAVE_PATHS_H=@HAVE_PATHS_H@
+NO_GETTEXT=@NO_GETTEXT@
 NEEDS_LIBICONV=@NEEDS_LIBICONV@
 NEEDS_SOCKET=@NEEDS_SOCKET@
 NEEDS_RESOLV=@NEEDS_RESOLV@
configure.ac +6 -0
index 71038fc..7bebfd8 100644
@@ -730,6 +730,12 @@ AC_CHECK_HEADER([paths.h],
 [HAVE_PATHS_H=])
 AC_SUBST(HAVE_PATHS_H)
 #
+# Define NO_GETTEXT if you don't have libintl.h
+AC_CHECK_HEADER([libintl.h],
+[NO_GETTEXT=],
+[NO_GETTEXT=YesPlease])
+AC_SUBST(NO_GETTEXT)
+#
 # Define NO_STRCASESTR if you don't have strcasestr.
 GIT_CHECK_FUNC(strcasestr,
 [NO_STRCASESTR=],
gettext.c new file +25 -0
new file mode 100644
index 0000000..22cdcc1
@@ -0,0 +1,25 @@
+#ifdef NO_GETTEXT
+void git_setup_gettext(void) {}
+#else
+#include "exec_cmd.h"
+#include <libintl.h>
+#include <stdlib.h>
+
+void git_setup_gettext(void) {
+	char *podir;
+	char *envdir = getenv("GIT_TEXTDOMAINDIR");
+
+	if (envdir) {
+		(void)bindtextdomain("git", envdir);
+	} else {
+		podir = (char *)system_path("share/locale");
+		if (!podir) return;
+		(void)bindtextdomain("git", podir);
+		free(podir);
+	}
+
+	(void)setlocale(LC_MESSAGES, "");
+	(void)setlocale(LC_CTYPE, "");
+	(void)textdomain("git");
+}
+#endif
gettext.h new file +13 -0
new file mode 100644
index 0000000..a99da6a
@@ -0,0 +1,13 @@
+#ifndef GETTEXT_H
+#define GETTEXT_H
+
+void git_setup_gettext(void);
+
+#ifdef NO_GETTEXT
+#define _(s) (s)
+#else
+#include <libintl.h>
+#define _(s) gettext(s)
+#endif
+
+#endif
git.c +3 -0
index 99f0363..d749eab 100644
@@ -3,6 +3,7 @@
 #include "cache.h"
 #include "quote.h"
 #include "run-command.h"
+#include "gettext.h"
 
 const char git_usage_string[] =
 	"git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]\n"
@@ -490,6 +491,8 @@ int main(int argc, const char **argv)
 	if (!cmd)
 		cmd = "git-help";
 
+	git_setup_gettext();
+
 	/*
 	 * "git-xxxx" is the same as "git xxxx", but we obviously:
 	 *
po/.gitignore new file +1 -0
new file mode 100644
index 0000000..221000e
@@ -0,0 +1 @@
+/*.pot
wt-status.c +65 -64

271 lines not on this page · raw message

Signature · 1 line
1.7.1.251.gec7f5.dirty
#35 lore raw

PATCH v4 2/7 gettext: Add a Gettext interface for shell scripts

In reply to Ævar Arnfjörð Bjarmason

Use GNU's gettext.sh in git-sh-setup if it's available, otherwise fallback on our own custom functions.

A couple of strings in git-pull.sh are now translatable as a proof of concept, including a multiline string.

---
 Makefile        |    7 +++++--
 git-pull.sh     |   15 ++++++++-------
 git-sh-setup.sh |   38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+), 9 deletions(-)
Makefile +5 -2
index 4de0627..dce2faa 100644
@@ -272,6 +272,7 @@ mandir = share/man
 infodir = share/info
 gitexecdir = libexec/git-core
 sharedir = $(prefix)/share
+localedir = $(sharedir)/locale
 template_dir = share/git-core/templates
 htmldir = share/doc/git-doc
 ifeq ($(prefix),/usr)
@@ -285,7 +286,7 @@ lib = lib
 # DESTDIR=
 pathsep = :
 
-export prefix bindir sharedir sysconfdir
+export prefix bindir sharedir localedir sysconfdir
 
 CC = gcc
 AR = ar
@@ -1455,6 +1456,7 @@ htmldir_SQ = $(subst ','\'',$(htmldir))
 prefix_SQ = $(subst ','\'',$(prefix))
 sharedir_SQ = $(subst ','\'',$(sharedir))
 
+LOCALEDIR_SQ = $(subst ','\'',$(localedir))
 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
 PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
 PYTHON_PATH_SQ = $(subst ','\'',$(PYTHON_PATH))
@@ -1548,6 +1550,7 @@ $(RM) $@ $@+ && \
 sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
     -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
     -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
+    -e 's|@@LOCALEDIR@@|$(LOCALEDIR_SQ)|g' \
     -e 's/@@NO_CURL@@/$(NO_CURL)/g' \
     -e $(BROKEN_PATH_FIX) \
     [email protected] >$@+
@@ -1881,7 +1884,7 @@ cscope:
 	$(FIND) . -name '*.[hcS]' -print | xargs cscope -b
 
 pot:
-	$(XGETTEXT) -k_ -o po/git.pot $(C_OBJ:o=c)
+	$(XGETTEXT) -k_ -o po/git.pot $(C_OBJ:o=c) $(SCRIPT_SH)
 
 POFILES := $(wildcard po/*.po)
 MOFILES := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/git.mo,$(POFILES))
git-pull.sh +8 -7
index 1a4729f..22a6da2 100755
@@ -121,8 +121,8 @@ error_on_no_merge_candidates () {
 	do
 		case "$opt" in
 		-t|--t|--ta|--tag|--tags)
-			echo "Fetching tags only, you probably meant:"
-			echo "  git fetch --tags"
+			gettext "Fetching tags only, you probably meant:"; echo
+			gettext "  git fetch --tags"; echo
 			exit 1
 		esac
 	done
@@ -154,11 +154,12 @@ error_on_no_merge_candidates () {
 		echo "a branch. Because this is not the default configured remote"
 		echo "for your current branch, you must specify a branch on the command line."
 	elif [ -z "$curr_branch" ]; then
-		echo "You are not currently on a branch, so I cannot use any"
-		echo "'branch.<branchname>.merge' in your configuration file."
-		echo "Please specify which remote branch you want to use on the command"
-		echo "line and try again (e.g. 'git pull <repository> <refspec>')."
-		echo "See git-pull(1) for details."
+        gettext "You are not currently on a branch, so I cannot use any
+'branch.<branchname>.merge' in your configuration file.
+Please specify which remote branch you want to use on the command
+line and try again (e.g. 'git pull <repository> <refspec>').
+See git-pull(1) for details.";
+        echo
 	elif [ -z "$upstream" ]; then
 		echo "You asked me to pull without telling me which branch you"
 		echo "want to $op_type $op_prep, and 'branch.${curr_branch}.merge' in"
git-sh-setup.sh +38 -0
index 6131670..53cfc42 100644
@@ -211,3 +211,41 @@ case $(uname -s) in
 	}
 	;;
 esac
+
+# Try to use libintl's gettext.sh, or fall back to English if we
+# can't.
+. gettext.sh
+if test $? -eq 0
+then
+	TEXTDOMAIN=git
+	export TEXTDOMAIN
+	if [ -z "$GIT_TEXTDOMAINDIR" ]
+	then
+		TEXTDOMAINDIR="@@LOCALEDIR@@"
+	else
+		TEXTDOMAINDIR=$GIT_TEXTDOMAINDIR
+	fi
+	export TEXTDOMAINDIR
+else
+	# Since GNU gettext.sh isn't available we'll have to define our
+	# own dummy functions.
+
+	# This code adapted from NessusClient-1.0.2's nessusclient-mkcert
+	# by Michel Arboi <[email protected]>. The original code is
+	# under the GPLv2.
+
+	# Not everyone has echo -n
+	case $(echo -n) in
+		\-n)	Xn=	  ; Xc='\c' ;;
+		*)		Xn=-n ; Xc=
+	esac
+
+	gettext () {
+		echo $Xn "$1" $Xc
+	}
+
+	eval_gettext () {
+		eval_gettext_var="echo $1"
+		echo $Xn `eval $eval_gettext_var` $Xc
+	}
+fi
Signature · 1 line
1.7.1.251.gec7f5.dirty
#36 lore raw

PATCH v4 3/7 gettext: Add a Gettext interface for Perl

In reply to Ævar Arnfjörð Bjarmason

Make Git's gettext messages available to Perl programs through Locale::Messages. Gracefully fall back to English on systems that don't contain the module.

This contains some makefile hacks to pass localedir to perl/Makefile. Which in turn passes it to perl.mak, which'll use it to search/replace occurances of ++LOCALEDIR++ in .pm files.

---
 Makefile            |    6 +++-
 git-send-email.perl |    3 +-
 perl/Git/I18N.pm    |   73 +++++++++++++++++++++++++++++++++++++++++++++++++++
 perl/Makefile       |    3 +-
 perl/Makefile.PL    |   14 +++++++++-
 5 files changed, 94 insertions(+), 5 deletions(-)
 create mode 100644 perl/Git/I18N.pm
Makefile +4 -2
index dce2faa..3f0e305 100644
@@ -1505,7 +1505,7 @@ ifndef NO_TCLTK
 	$(QUIET_SUBDIR0)gitk-git $(QUIET_SUBDIR1) all
 endif
 ifndef NO_PERL
-	$(QUIET_SUBDIR0)perl $(QUIET_SUBDIR1) PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' all
+	$(QUIET_SUBDIR0)perl $(QUIET_SUBDIR1) PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' localedir='$(localedir_SQ)' all
 endif
 ifndef NO_PYTHON
 	$(QUIET_SUBDIR0)git_remote_helpers $(QUIET_SUBDIR1) PYTHON_PATH='$(PYTHON_PATH_SQ)' prefix='$(prefix_SQ)' all
@@ -1884,7 +1884,9 @@ cscope:
 	$(FIND) . -name '*.[hcS]' -print | xargs cscope -b
 
 pot:
-	$(XGETTEXT) -k_ -o po/git.pot $(C_OBJ:o=c) $(SCRIPT_SH)
+	$(XGETTEXT) --keyword=_ --output=po/git.pot --language=C $(C_OBJ:o=c)
+	$(XGETTEXT) --join-existing --output=po/git.pot --language=Shell $(SCRIPT_SH)
+	$(XGETTEXT) --join-existing --output=po/git.pot --language=Perl $(SCRIPT_PERL)
 
 POFILES := $(wildcard po/*.po)
 MOFILES := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/git.mo,$(POFILES))
git-send-email.perl +2 -1
index 111c981..b9288af 100755
@@ -26,6 +26,7 @@ use Term::ANSIColor;
 use File::Temp qw/ tempdir tempfile /;
 use Error qw(:try);
 use Git;
+use Git::I18N;
 
 Getopt::Long::Configure qw/ pass_through /;
 
@@ -674,7 +675,7 @@ if (!defined $sender) {
 	$sender = $repoauthor || $repocommitter || '';
 	$sender = ask("Who should the emails appear to be from? [$sender] ",
 	              default => $sender);
-	print "Emails will be sent from: ", $sender, "\n";
+	printf gettext("Emails will be sent from: %s\n"), $sender;
 	$prompting++;
 }
 
perl/Git/I18N.pm new file +73 -0

73 lines not on this page · raw message

perl/Makefile +2 -1
index 4ab21d6..4e624ff 100644
@@ -5,6 +5,7 @@ makfile:=perl.mak
 
 PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
 prefix_SQ = $(subst ','\'',$(prefix))
+localedir_SQ = $(subst ','\'',$(localedir))
 
 ifndef V
 	QUIET = @
@@ -38,7 +39,7 @@ $(makfile): ../GIT-CFLAGS Makefile
 	echo '	echo $(instdir_SQ)' >> $@
 else
 $(makfile): Makefile.PL ../GIT-CFLAGS
-	$(PERL_PATH) $< PREFIX='$(prefix_SQ)'
+	$(PERL_PATH) $< PREFIX='$(prefix_SQ)' --localedir='$(localedir_SQ)'
 endif
 
 # this is just added comfort for calling make directly in perl dir
perl/Makefile.PL +13 -1
index 0b9deca..456d45b 100644
@@ -1,4 +1,12 @@
+use strict;
+use warnings;
 use ExtUtils::MakeMaker;
+use Getopt::Long;
+
+# Sanity: die at first unknown option
+Getopt::Long::Configure qw/ pass_through /;
+
+GetOptions("localedir=s" => \my $localedir);
 
 sub MY::postamble {
 	return <<'MAKE_FRAG';
@@ -16,7 +24,10 @@ endif
 MAKE_FRAG
 }
 
-my %pm = ('Git.pm' => '$(INST_LIBDIR)/Git.pm');
+my %pm = (
+	'Git.pm' => '$(INST_LIBDIR)/Git.pm',
+	'Git/I18N.pm' => '$(INST_LIBDIR)/Git/I18N.pm',
+);
 
 # We come with our own bundled Error.pm. It's not in the set of default
 # Perl modules so install it if it's not available on the system yet.
@@ -33,6 +44,7 @@ WriteMakefile(
 	NAME            => 'Git',
 	VERSION_FROM    => 'Git.pm',
 	PM		=> \%pm,
+	PM_FILTER	=> qq[\$(PERL) -pe "s<\\Q++LOCALEDIR++\\E><$localedir>"],
 	MAKEFILE	=> 'perl.mak',
 	INSTALLSITEMAN3DIR => '$(SITEPREFIX)/share/man/man3'
 );
Signature · 1 line
1.7.1.251.gec7f5.dirty
#37 lore raw

PATCH v4 4/7 Makefile: Don't install Gettext .mo files if NO_GETTEXT

In reply to Ævar Arnfjörð Bjarmason

Change the Makefile not to build/install .mo files as part of the default target if NO_GETTEXT=1 is given.

This was both redundant, and meant that the Perl and Shell programs would use the Gettext strings, since they don't use the git_setup_gettext() function in gettext.c, which is compiled to a stub if NO_GETTEXT=1 is set.

---
 Makefile |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
Makefile +4 -0
index 3f0e305..40eb1a2 100644
@@ -1891,7 +1891,9 @@ pot:
 POFILES := $(wildcard po/*.po)
 MOFILES := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/git.mo,$(POFILES))
 MODIRS := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/,$(POFILES))
+ifndef NO_GETTEXT
 all:: $(MOFILES)
+endif
 share/locale/%/LC_MESSAGES/git.mo: po/%.po
 	@mkdir -p $(dir $@)
 	$(QUIET_MSGFMT)$(MSGFMT) -o $@ $<
@@ -2008,9 +2010,11 @@ install: all
 	$(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 	$(INSTALL) -m 644 $(SCRIPT_LIB) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 	$(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)'
+ifndef NO_GETTEXT
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(sharedir_SQ)/locale'
 	(cd share && tar cf - locale) | \
 		(cd '$(DESTDIR_SQ)$(sharedir_SQ)' && umask 022 && tar xof -)
+endif
 	$(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
 ifndef NO_PERL
 	$(MAKE) -C perl prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install
Signature · 1 line
1.7.1.251.gec7f5.dirty
#38 lore raw

PATCH v4 5/7 Makefile: Override --keyword= for all languages

In reply to Ævar Arnfjörð Bjarmason

By default xgettext will supply a default list of keywords depending on the --language parameter. Disable this in favor of supplying a list of keywords manually.

This reduced the surface area for potential bugs.

---
 Makefile |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
Makefile +3 -3
index 40eb1a2..62b8279 100644
@@ -1884,9 +1884,9 @@ cscope:
 	$(FIND) . -name '*.[hcS]' -print | xargs cscope -b
 
 pot:
-	$(XGETTEXT) --keyword=_ --output=po/git.pot --language=C $(C_OBJ:o=c)
-	$(XGETTEXT) --join-existing --output=po/git.pot --language=Shell $(SCRIPT_SH)
-	$(XGETTEXT) --join-existing --output=po/git.pot --language=Perl $(SCRIPT_PERL)
+	$(XGETTEXT) --keyword= --keyword=_ --output=po/git.pot --language=C $(C_OBJ:o=c)
+	$(XGETTEXT) --join-existing --keyword= --keyword=gettext --output=po/git.pot --language=Shell $(SCRIPT_SH)
+	$(XGETTEXT) --join-existing --keyword= --keyword=gettext --output=po/git.pot --language=Perl $(SCRIPT_PERL)
 
 POFILES := $(wildcard po/*.po)
 MOFILES := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/git.mo,$(POFILES))
Signature · 1 line
1.7.1.251.gec7f5.dirty
#39 lore raw

PATCH v4 6/7 gettext: Sanity tests for Git's Gettext support

In reply to Ævar Arnfjörð Bjarmason

These tests check if Git's C, Shell and Perl wrappers for Gettext are working.

---
 t/t0200-gettext.sh |   73 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 73 insertions(+), 0 deletions(-)
 create mode 100755 t/t0200-gettext.sh
t/t0200-gettext.sh new file +73 -0
new file mode 100755
index 0000000..ff2f9f9
@@ -0,0 +1,73 @@
+#!/bin/sh
+D=`pwd`
+export GIT_TEXTDOMAINDIR=$D/../share/locale
+
+test_description='Gettext support for Git'
+. ./test-lib.sh
+. ../../git-sh-setup
+
+test_expect_success 'sanity: $TEXTDOMAIN is git' '
+    test $TEXTDOMAIN = "git"
+'
+
+test_expect_success 'sanity: $TEXTDOMAINDIR exists' '
+    test -d $TEXTDOMAINDIR &&
+    test $TEXTDOMAINDIR = $GIT_TEXTDOMAINDIR
+'
+
+test_expect_success 'sanity: Icelandic locale was compiled' '
+    test -f $TEXTDOMAINDIR/is/LC_MESSAGES/git.mo
+'
+
+test_expect_success 'sanity: gettext("") metadata is OK' '
+    LC_ALL=is_IS.UTF-8 gettext "" > expect &&
+    grep "Project-Id-Version: Git" expect &&
+    grep "Git Mailing List <[email protected]>" expect &&
+    grep "Content-Type: text/plain; charset=UTF-8" expect &&
+    grep "Content-Transfer-Encoding: 8bit" expect
+'
+
+test_expect_success 'sanity: gettext(unknown) is passed through' '
+    printf "This is not a translation string"  > expect
+    gettext "This is not a translation string" > actual &&
+    test_cmp expect actual
+'
+
+test_expect_success 'sanity: C program git-status reads our message catalog ' '
+    > foo &&
+    test_commit foo "a message"
+    git checkout -b topic/gettext-testing &&
+    git status | grep topic/gettext-testing > expect
+    echo "# On branch topic/gettext-testing" > actual
+    test_cmp expect actual &&
+    LC_ALL=is_IS.UTF-8 git status | grep topic/gettext-testing > expect
+    echo "# � greininni topic/gettext-testing" > actual
+    test_cmp expect actual
+'
+
+test_expect_success 'sanity: Perl program Git::I18N reads our message catalog ' '
+    echo "On branch " > expect &&
+    perl -I"$D/../perl" -MGit::I18N -le "print gettext(q[On branch ])" > actual &&
+    test_cmp expect actual &&
+
+    echo "� greininni " > expect &&
+    LC_ALL=is_IS.UTF-8 perl -I"$D/../perl" -MGit::I18N -le "print gettext(q[On branch ])" > actual &&
+    test_cmp expect actual
+'
+
+test_expect_success 'Setup another Git repository for testing' '
+    mkdir parent &&
+    (cd parent && git init &&
+     echo one >file && git add file &&
+     git commit -m one)
+'
+
+test_expect_success 'sanity: Shell program git-pull reads our message catalog' '
+    cd parent &&
+    (git pull --tags "../" >out 2>err || :) &&
+    grep "Fetching tags only" err &&
+    (LC_ALL=is_IS.UTF-8 git pull --tags "../" >out 2>err || :) &&
+    grep "Næ aðeins í" err 
+'
+
+test_done
Signature · 1 line
1.7.1.251.gec7f5.dirty
#40 lore raw

PATCH v4 7/7 gettext: Add a skeleton po/is.po

In reply to Ævar Arnfjörð Bjarmason

This example is.po file translates a little bit of C, Shell and Perl as an example.

---
 po/is.po |  282 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 282 insertions(+), 0 deletions(-)
 create mode 100644 po/is.po
po/is.po new file +282 -0
new file mode 100644
index 0000000..aa1923e
@@ -0,0 +1,282 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: Git\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2010-05-30 19:24+0000\n"
+"PO-Revision-Date: 2010-06-01 22:15+0000\n"
+"Last-Translator: Ævar Arnfjörð Bjarmason <[email protected]>\n"
+"Language-Team: Git Mailing List <[email protected]>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Poedit-Language: English\n"
+"X-Poedit-SourceCharset: utf-8\n"
+
+#: wt-status.c:53
+msgid "# Unmerged paths:"
+msgstr ""
+
+#: wt-status.c:59 wt-status.c:76
+#, c-format
+msgid "#   (use \"git reset %s <file>...\" to unstage)"
+msgstr ""
+
+#: wt-status.c:61 wt-status.c:78
+msgid "#   (use \"git rm --cached <file>...\" to unstage)"
+msgstr ""
+
+#: wt-status.c:62
+msgid "#   (use \"git add/rm <file>...\" as appropriate to mark resolution)"
+msgstr ""
+
+#: wt-status.c:63 wt-status.c:79 wt-status.c:98 wt-status.c:110
+#: wt-status.c:115 wt-status.c:638 wt-status.c:640
+msgid "#"
+msgstr ""
+
+#: wt-status.c:70
+msgid "# Changes to be committed:"
+msgstr ""
+
+#: wt-status.c:88
+msgid "# Changed but not updated:"
+msgstr ""
+
+#: wt-status.c:92
+msgid "#   (use \"git add <file>...\" to update what will be committed)"
+msgstr ""
+
+#: wt-status.c:94
+msgid "#   (use \"git add/rm <file>...\" to update what will be committed)"
+msgstr ""
+
+#: wt-status.c:95
+msgid ""
+"#   (use \"git checkout -- <file>...\" to discard changes in working "
+"directory)"
+msgstr ""
+
+#: wt-status.c:97
+msgid "#   (commit or discard the untracked or modified content in submodules)"
+msgstr ""
+
+#: wt-status.c:106
+#, c-format
+msgid "# %s files:"
+msgstr ""
+
+#: wt-status.c:109
+#, c-format
+msgid "#   (use \"git %s <file>...\" to include in what will be committed)"
+msgstr ""
+
+#: wt-status.c:126
+msgid "bug"
+msgstr ""
+
+#: wt-status.c:129 wt-status.c:182
+msgid "#\t"
+msgstr ""
+
+#: wt-status.c:131
+msgid "both deleted:"
+msgstr ""
+
+#: wt-status.c:132
+msgid "added by us:"
+msgstr ""
+
+#: wt-status.c:133
+msgid "deleted by them:"
+msgstr ""
+
+#: wt-status.c:134
+msgid "added by them:"
+msgstr ""
+
+#: wt-status.c:135
+msgid "deleted by us:"
+msgstr ""
+
+#: wt-status.c:136
+msgid "both added:"
+msgstr ""
+
+#: wt-status.c:137
+msgid "both modified:"
+msgstr ""
+
+#: wt-status.c:139
+#, c-format
+msgid "%-20s%s\n"
+msgstr ""
+
+#: wt-status.c:165
+msgid " ("
+msgstr ""
+
+#: wt-status.c:167
+msgid "new commits, "
+msgstr ""
+
+#: wt-status.c:169
+msgid "modified content, "
+msgstr ""
+
+#: wt-status.c:171
+msgid "untracked content, "
+msgstr ""
+
+#: wt-status.c:185
+#, c-format
+msgid "new file:   %s"
+msgstr ""
+
+#: wt-status.c:188
+#, c-format
+msgid "copied:     %s -> %s"
+msgstr ""
+
+#: wt-status.c:191
+#, c-format
+msgid "deleted:    %s"
+msgstr ""
+
+#: wt-status.c:194
+#, c-format
+msgid "modified:   %s"
+msgstr ""
+
+#: wt-status.c:197
+#, c-format
+msgid "renamed:    %s -> %s"
+msgstr ""
+
+#: wt-status.c:200
+#, c-format
+msgid "typechange: %s"
+msgstr ""
+
+#: wt-status.c:203
+#, c-format
+msgid "unknown:    %s"
+msgstr ""
+
+#: wt-status.c:206
+#, c-format
+msgid "unmerged:   %s"
+msgstr ""
+
+#: wt-status.c:209
+#, c-format
+msgid "bug: unhandled diff status %c"
+msgstr ""
+
+#: wt-status.c:212
+#, c-format
+msgid "%s"
+msgstr ""
+
+#: wt-status.c:215
+#, c-format
+msgid "\n"
+msgstr ""
+
+#: wt-status.c:622
+msgid "On branch "
+msgstr "Á greininni "
+
+#: wt-status.c:629
+msgid "Not currently on any branch."
+msgstr "Ekki á neinni grein."
+
+#: wt-status.c:639
+msgid "# Initial commit"
+msgstr ""
+
+#: wt-status.c:651
+msgid "Untracked"
+msgstr ""
+
+#: wt-status.c:651
+msgid "add"
+msgstr ""
+
+#: wt-status.c:653
+msgid "Ignored"
+msgstr ""
+
+#: wt-status.c:653
+msgid "add -f"
+msgstr ""
+
+#: wt-status.c:655
+#, c-format
+msgid "# Untracked files not listed%s\n"
+msgstr ""
+
+#: wt-status.c:657
+msgid " (use -u option to show untracked files)"
+msgstr ""
+
+#: wt-status.c:663
+#, c-format
+msgid "# No changes\n"
+msgstr "# Engar breytingar\n"
+
+#: wt-status.c:667
+#, c-format
+msgid "no changes added to commit%s\n"
+msgstr ""
+
+#: wt-status.c:669
+msgid " (use \"git add\" and/or \"git commit -a\")"
+msgstr ""
+
+#: wt-status.c:671
+#, c-format
+msgid "nothing added to commit but untracked files present%s\n"
+msgstr ""
+
+#: wt-status.c:673
+msgid " (use \"git add\" to track)"
+msgstr ""
+
+#: wt-status.c:676
+msgid " (create/copy files and use \"git add\" to track)"
+msgstr ""
+
+#: wt-status.c:678 wt-status.c:681
+#, c-format
+msgid "nothing to commit%s\n"
+msgstr ""
+
+#: wt-status.c:679
+msgid " (use -u to show untracked files)"
+msgstr ""
+
+#: wt-status.c:682
+msgid " (working directory clean)"
+msgstr ""
+
+#: git-pull.sh:124
+msgid "Fetching tags only, you probably meant:"
+msgstr "Næ aðeins í tögg, þú áttir líkast til við:"
+
+#: git-pull.sh:125
+msgid "  git fetch --tags"
+msgstr ""
+
+#: git-pull.sh:157
+msgid ""
+"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."
+msgstr ""
+
+#: git-send-email.perl:678
+#, perl-format
+msgid "Emails will be sent from: %s\n"
+msgstr "Póstarnir verða sendir frá: %s\n"
Signature · 1 line
1.7.1.251.gec7f5.dirty
#45 lore raw

PATCH v3 1/7 Add infrastructure for translating Git with gettext

In reply to Ævar Arnfjörð Bjarmason

From: Jeff Epler <[email protected]>

Change the build process to use GNU's libintl if it's available. If not we define our own skeleton replacement functions which degrade gracefully to English.

Gettext .mo files will be installed and looked for in $(prefix)/share/locale. GIT_LOCALEDIR can also be set to override that, this variable is only intended for testing Git itself.

---
 .gitignore    |    1 +
 Makefile      |   30 +++++++++++++
 config.mak.in |    1 +
 configure.ac  |    6 +++
 gettext.c     |   25 +++++++++++
 gettext.h     |   13 ++++++
 git.c         |    3 +
 po/.gitignore |    1 +
 wt-status.c   |  129 +++++++++++++++++++++++++++++----------------------------
 9 files changed, 145 insertions(+), 64 deletions(-)
 create mode 100644 gettext.c
 create mode 100644 gettext.h
 create mode 100644 po/.gitignore
.gitignore +1 -0
index 14e2b6b..d22c0e5 100644
@@ -204,3 +204,4 @@
 *.pdb
 /Debug/
 /Release/
+/share/
Makefile +30 -0
index d5d6565..4de0627 100644
@@ -297,6 +297,8 @@ RPMBUILD = rpmbuild
 TCL_PATH = tclsh
 TCLTK_PATH = wish
 PTHREAD_LIBS = -lpthread
+XGETTEXT = xgettext
+MSGFMT = msgfmt
 
 export TCL_PATH TCLTK_PATH
 
@@ -523,6 +525,7 @@ LIB_H += userdiff.h
 LIB_H += utf8.h
 LIB_H += xdiff-interface.h
 LIB_H += xdiff/xdiff.h
+LIB_H += gettext.h
 
 LIB_OBJS += abspath.o
 LIB_OBJS += advice.o
@@ -564,6 +567,7 @@ LIB_OBJS += entry.o
 LIB_OBJS += environment.o
 LIB_OBJS += exec_cmd.o
 LIB_OBJS += fsck.o
+LIB_OBJS += gettext.o
 LIB_OBJS += graph.o
 LIB_OBJS += grep.o
 LIB_OBJS += hash.o
@@ -1386,6 +1390,12 @@ ifdef USE_NED_ALLOCATOR
        COMPAT_OBJS += compat/nedmalloc/nedmalloc.o
 endif
 
+ifdef NO_GETTEXT
+	COMPAT_CFLAGS += -DNO_GETTEXT
+else
+	LIBINTL = -lintl
+endif
+
 ifeq ($(TCLTK_PATH),)
 NO_TCLTK=NoThanks
 endif
@@ -1415,6 +1425,7 @@ ifndef V
 	QUIET_BUILT_IN = @echo '   ' BUILTIN $@;
 	QUIET_GEN      = @echo '   ' GEN $@;
 	QUIET_LNCP     = @echo '   ' LN/CP $@;
+	QUIET_MSGFMT   = @echo '   ' MSGFMT $@;
 	QUIET_SUBDIR0  = +@subdir=
 	QUIET_SUBDIR1  = ;$(NO_SUBDIR) echo '   ' SUBDIR $$subdir; \
 			 $(MAKE) $(PRINT_DIR) -C $$subdir
@@ -1442,6 +1453,7 @@ gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
 template_dir_SQ = $(subst ','\'',$(template_dir))
 htmldir_SQ = $(subst ','\'',$(htmldir))
 prefix_SQ = $(subst ','\'',$(prefix))
+sharedir_SQ = $(subst ','\'',$(sharedir))
 
 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
 PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
@@ -1868,6 +1880,17 @@ cscope:
 	$(RM) cscope*
 	$(FIND) . -name '*.[hcS]' -print | xargs cscope -b
 
+pot:
+	$(XGETTEXT) -k_ -o po/git.pot $(C_OBJ:o=c)
+
+POFILES := $(wildcard po/*.po)
+MOFILES := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/git.mo,$(POFILES))
+MODIRS := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/,$(POFILES))
+all:: $(MOFILES)
+share/locale/%/LC_MESSAGES/git.mo: po/%.po
+	@mkdir -p $(dir $@)
+	$(QUIET_MSGFMT)$(MSGFMT) -o $@ $<
+
 ### Detect prefix changes
 TRACK_CFLAGS = $(subst ','\'',$(ALL_CFLAGS)):\
              $(bindir_SQ):$(gitexecdir_SQ):$(template_dir_SQ):$(prefix_SQ)
@@ -1980,6 +2003,9 @@ install: all
 	$(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 	$(INSTALL) -m 644 $(SCRIPT_LIB) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 	$(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)'
+	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(sharedir_SQ)/locale'
+	(cd share && tar cf - locale) | \
+		(cd '$(DESTDIR_SQ)$(sharedir_SQ)' && umask 022 && tar xof -)
 	$(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
 ifndef NO_PERL
 	$(MAKE) -C perl prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install
@@ -2127,6 +2153,10 @@ ifndef NO_TCLTK
 	$(MAKE) -C git-gui clean
 endif
 	$(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-GUI-VARS GIT-BUILD-OPTIONS
+ifndef NO_GETTEXT
+	$(RM) po/git.pot
+	$(RM) -r share/
+endif
 
 .PHONY: all install clean strip
 .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
config.mak.in +1 -0
index 0d4b64d..a15f3c1 100644
@@ -32,6 +32,7 @@ NO_CURL=@NO_CURL@
 NO_EXPAT=@NO_EXPAT@
 NO_LIBGEN_H=@NO_LIBGEN_H@
 HAVE_PATHS_H=@HAVE_PATHS_H@
+NO_GETTEXT=@NO_GETTEXT@
 NEEDS_LIBICONV=@NEEDS_LIBICONV@
 NEEDS_SOCKET=@NEEDS_SOCKET@
 NEEDS_RESOLV=@NEEDS_RESOLV@
configure.ac +6 -0
index 71038fc..7bebfd8 100644
@@ -730,6 +730,12 @@ AC_CHECK_HEADER([paths.h],
 [HAVE_PATHS_H=])
 AC_SUBST(HAVE_PATHS_H)
 #
+# Define NO_GETTEXT if you don't have libintl.h
+AC_CHECK_HEADER([libintl.h],
+[NO_GETTEXT=],
+[NO_GETTEXT=YesPlease])
+AC_SUBST(NO_GETTEXT)
+#
 # Define NO_STRCASESTR if you don't have strcasestr.
 GIT_CHECK_FUNC(strcasestr,
 [NO_STRCASESTR=],
gettext.c new file +25 -0
new file mode 100644
index 0000000..c67e5ca
@@ -0,0 +1,25 @@
+#ifdef NO_GETTEXT
+void git_setup_gettext(void) {}
+#else
+#include "exec_cmd.h"
+#include <libintl.h>
+#include <stdlib.h>
+
+void git_setup_gettext(void) {
+	char *podir;
+    char *envdir = getenv("GIT_TEXTDOMAINDIR");
+
+	if (envdir) {
+		(void)bindtextdomain("git", envdir);
+	} else {
+		podir = (char *)system_path("share/locale");
+		if (!podir) return;
+		(void)bindtextdomain("git", podir);
+		free(podir);
+	}
+
+	(void)setlocale(LC_MESSAGES, "");
+	(void)setlocale(LC_CTYPE, "");
+	(void)textdomain("git");
+}
+#endif
gettext.h new file +13 -0
new file mode 100644
index 0000000..a99da6a
@@ -0,0 +1,13 @@
+#ifndef GETTEXT_H
+#define GETTEXT_H
+
+void git_setup_gettext(void);
+
+#ifdef NO_GETTEXT
+#define _(s) (s)
+#else
+#include <libintl.h>
+#define _(s) gettext(s)
+#endif
+
+#endif
git.c +3 -0
index 99f0363..d749eab 100644
@@ -3,6 +3,7 @@
 #include "cache.h"
 #include "quote.h"
 #include "run-command.h"
+#include "gettext.h"
 
 const char git_usage_string[] =
 	"git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]\n"
@@ -490,6 +491,8 @@ int main(int argc, const char **argv)
 	if (!cmd)
 		cmd = "git-help";
 
+	git_setup_gettext();
+
 	/*
 	 * "git-xxxx" is the same as "git xxxx", but we obviously:
 	 *
po/.gitignore new file +1 -0
new file mode 100644
index 0000000..221000e
@@ -0,0 +1 @@
+/*.pot
wt-status.c +65 -64

271 lines not on this page · raw message

Signature · 1 line
1.7.1.248.gb7713.dirty
#46 lore raw

PATCH v3 2/7 gettext: Add a Gettext interface for shell scripts

In reply to Ævar Arnfjörð Bjarmason

Use GNU's gettext.sh in git-sh-setup if it's available, otherwise fallback on our own custom functions.

A couple of strings in git-pull.sh are now translatable as a proof of concept, including a multiline string.

---
 Makefile        |    7 +++++--
 git-pull.sh     |   15 ++++++++-------
 git-sh-setup.sh |   33 +++++++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+), 9 deletions(-)
Makefile +5 -2
index 4de0627..dce2faa 100644
@@ -272,6 +272,7 @@ mandir = share/man
 infodir = share/info
 gitexecdir = libexec/git-core
 sharedir = $(prefix)/share
+localedir = $(sharedir)/locale
 template_dir = share/git-core/templates
 htmldir = share/doc/git-doc
 ifeq ($(prefix),/usr)
@@ -285,7 +286,7 @@ lib = lib
 # DESTDIR=
 pathsep = :
 
-export prefix bindir sharedir sysconfdir
+export prefix bindir sharedir localedir sysconfdir
 
 CC = gcc
 AR = ar
@@ -1455,6 +1456,7 @@ htmldir_SQ = $(subst ','\'',$(htmldir))
 prefix_SQ = $(subst ','\'',$(prefix))
 sharedir_SQ = $(subst ','\'',$(sharedir))
 
+LOCALEDIR_SQ = $(subst ','\'',$(localedir))
 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
 PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
 PYTHON_PATH_SQ = $(subst ','\'',$(PYTHON_PATH))
@@ -1548,6 +1550,7 @@ $(RM) $@ $@+ && \
 sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
     -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
     -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
+    -e 's|@@LOCALEDIR@@|$(LOCALEDIR_SQ)|g' \
     -e 's/@@NO_CURL@@/$(NO_CURL)/g' \
     -e $(BROKEN_PATH_FIX) \
     [email protected] >$@+
@@ -1881,7 +1884,7 @@ cscope:
 	$(FIND) . -name '*.[hcS]' -print | xargs cscope -b
 
 pot:
-	$(XGETTEXT) -k_ -o po/git.pot $(C_OBJ:o=c)
+	$(XGETTEXT) -k_ -o po/git.pot $(C_OBJ:o=c) $(SCRIPT_SH)
 
 POFILES := $(wildcard po/*.po)
 MOFILES := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/git.mo,$(POFILES))
git-pull.sh +8 -7
index 1a4729f..22a6da2 100755
@@ -121,8 +121,8 @@ error_on_no_merge_candidates () {
 	do
 		case "$opt" in
 		-t|--t|--ta|--tag|--tags)
-			echo "Fetching tags only, you probably meant:"
-			echo "  git fetch --tags"
+			gettext "Fetching tags only, you probably meant:"; echo
+			gettext "  git fetch --tags"; echo
 			exit 1
 		esac
 	done
@@ -154,11 +154,12 @@ error_on_no_merge_candidates () {
 		echo "a branch. Because this is not the default configured remote"
 		echo "for your current branch, you must specify a branch on the command line."
 	elif [ -z "$curr_branch" ]; then
-		echo "You are not currently on a branch, so I cannot use any"
-		echo "'branch.<branchname>.merge' in your configuration file."
-		echo "Please specify which remote branch you want to use on the command"
-		echo "line and try again (e.g. 'git pull <repository> <refspec>')."
-		echo "See git-pull(1) for details."
+        gettext "You are not currently on a branch, so I cannot use any
+'branch.<branchname>.merge' in your configuration file.
+Please specify which remote branch you want to use on the command
+line and try again (e.g. 'git pull <repository> <refspec>').
+See git-pull(1) for details.";
+        echo
 	elif [ -z "$upstream" ]; then
 		echo "You asked me to pull without telling me which branch you"
 		echo "want to $op_type $op_prep, and 'branch.${curr_branch}.merge' in"
git-sh-setup.sh +33 -0
index 6131670..d67901c 100644
@@ -211,3 +211,36 @@ case $(uname -s) in
 	}
 	;;
 esac
+
+# Try to use libintl's gettext.sh, or fall back to English if we
+# can't.
+. gettext.sh
+if test $? -eq 0
+then
+    TEXTDOMAIN=git
+    export TEXDTOMAIN
+    TEXTDOMAINDIR="@@LOCALEDIR@@"
+    export TEXTDOMAINDIR
+else
+    # Since GNU gettext.sh isn't available we'll have to define our
+    # own dummy functions.
+
+    # This code adapted from NessusClient-1.0.2's nessusclient-mkcert
+    # by Michel Arboi <[email protected]>. The original code is
+    # under the GPLv2.
+
+    # Not everyone has echo -n
+    case $(echo -n) in
+        \-n)    Xn=   ; Xc='\c' ;;
+        *)      Xn=-n ; Xc=
+    esac
+
+    gettext () {
+        echo $Xn "$1" $Xc
+    }
+
+    eval_gettext () {
+        eval_gettext_var="echo $1"
+        echo $Xn `eval $eval_gettext_var` $Xc
+    }
+fi
Signature · 1 line
1.7.1.248.gb7713.dirty
#50 lore raw

PATCH v3 3/7 gettext: Add a Gettext interface for Perl

In reply to Ævar Arnfjörð Bjarmason

Make Git's gettext messages available to Perl programs through Locale::Messages. Gracefully fall back to English on systems that don't contain the module.

This contains some makefile hacks to pass localedir to perl/Makefile. Which in turn passes it to perl.mak, which'll use it to search/replace occurances of ++LOCALEDIR++ in .pm files.

---
 Makefile            |    6 +++-
 git-send-email.perl |    3 +-
 perl/Git/I18N.pm    |   73 +++++++++++++++++++++++++++++++++++++++++++++++++++
 perl/Makefile       |    3 +-
 perl/Makefile.PL    |   14 +++++++++-
 5 files changed, 94 insertions(+), 5 deletions(-)
 create mode 100644 perl/Git/I18N.pm
Makefile +4 -2
index dce2faa..3f0e305 100644
@@ -1505,7 +1505,7 @@ ifndef NO_TCLTK
 	$(QUIET_SUBDIR0)gitk-git $(QUIET_SUBDIR1) all
 endif
 ifndef NO_PERL
-	$(QUIET_SUBDIR0)perl $(QUIET_SUBDIR1) PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' all
+	$(QUIET_SUBDIR0)perl $(QUIET_SUBDIR1) PERL_PATH='$(PERL_PATH_SQ)' prefix='$(prefix_SQ)' localedir='$(localedir_SQ)' all
 endif
 ifndef NO_PYTHON
 	$(QUIET_SUBDIR0)git_remote_helpers $(QUIET_SUBDIR1) PYTHON_PATH='$(PYTHON_PATH_SQ)' prefix='$(prefix_SQ)' all
@@ -1884,7 +1884,9 @@ cscope:
 	$(FIND) . -name '*.[hcS]' -print | xargs cscope -b
 
 pot:
-	$(XGETTEXT) -k_ -o po/git.pot $(C_OBJ:o=c) $(SCRIPT_SH)
+	$(XGETTEXT) --keyword=_ --output=po/git.pot --language=C $(C_OBJ:o=c)
+	$(XGETTEXT) --join-existing --output=po/git.pot --language=Shell $(SCRIPT_SH)
+	$(XGETTEXT) --join-existing --output=po/git.pot --language=Perl $(SCRIPT_PERL)
 
 POFILES := $(wildcard po/*.po)
 MOFILES := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/git.mo,$(POFILES))
git-send-email.perl +2 -1
index 111c981..b9288af 100755
@@ -26,6 +26,7 @@ use Term::ANSIColor;
 use File::Temp qw/ tempdir tempfile /;
 use Error qw(:try);
 use Git;
+use Git::I18N;
 
 Getopt::Long::Configure qw/ pass_through /;
 
@@ -674,7 +675,7 @@ if (!defined $sender) {
 	$sender = $repoauthor || $repocommitter || '';
 	$sender = ask("Who should the emails appear to be from? [$sender] ",
 	              default => $sender);
-	print "Emails will be sent from: ", $sender, "\n";
+	printf gettext("Emails will be sent from: %s\n"), $sender;
 	$prompting++;
 }
 
perl/Git/I18N.pm new file +73 -0

73 lines not on this page · raw message

perl/Makefile +2 -1
index 4ab21d6..4e624ff 100644
@@ -5,6 +5,7 @@ makfile:=perl.mak
 
 PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
 prefix_SQ = $(subst ','\'',$(prefix))
+localedir_SQ = $(subst ','\'',$(localedir))
 
 ifndef V
 	QUIET = @
@@ -38,7 +39,7 @@ $(makfile): ../GIT-CFLAGS Makefile
 	echo '	echo $(instdir_SQ)' >> $@
 else
 $(makfile): Makefile.PL ../GIT-CFLAGS
-	$(PERL_PATH) $< PREFIX='$(prefix_SQ)'
+	$(PERL_PATH) $< PREFIX='$(prefix_SQ)' --localedir='$(localedir_SQ)'
 endif
 
 # this is just added comfort for calling make directly in perl dir
perl/Makefile.PL +13 -1
index 0b9deca..456d45b 100644
@@ -1,4 +1,12 @@
+use strict;
+use warnings;
 use ExtUtils::MakeMaker;
+use Getopt::Long;
+
+# Sanity: die at first unknown option
+Getopt::Long::Configure qw/ pass_through /;
+
+GetOptions("localedir=s" => \my $localedir);
 
 sub MY::postamble {
 	return <<'MAKE_FRAG';
@@ -16,7 +24,10 @@ endif
 MAKE_FRAG
 }
 
-my %pm = ('Git.pm' => '$(INST_LIBDIR)/Git.pm');
+my %pm = (
+	'Git.pm' => '$(INST_LIBDIR)/Git.pm',
+	'Git/I18N.pm' => '$(INST_LIBDIR)/Git/I18N.pm',
+);
 
 # We come with our own bundled Error.pm. It's not in the set of default
 # Perl modules so install it if it's not available on the system yet.
@@ -33,6 +44,7 @@ WriteMakefile(
 	NAME            => 'Git',
 	VERSION_FROM    => 'Git.pm',
 	PM		=> \%pm,
+	PM_FILTER	=> qq[\$(PERL) -pe "s<\\Q++LOCALEDIR++\\E><$localedir>"],
 	MAKEFILE	=> 'perl.mak',
 	INSTALLSITEMAN3DIR => '$(SITEPREFIX)/share/man/man3'
 );
Signature · 1 line
1.7.1.248.gb7713.dirty
#51 lore raw

PATCH v3 4/7 Makefile: Don't install Gettext .mo files if NO_GETTEXT

In reply to Ævar Arnfjörð Bjarmason

Change the Makefile not to build/install .mo files as part of the default target if NO_GETTEXT=1 is given.

This was both redundant, and meant that the Perl and Shell programs would use the Gettext strings, since they don't use the git_setup_gettext() function in gettext.c, which is compiled to a stub if NO_GETTEXT=1 is set.

---
 Makefile |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
Makefile +4 -0
index 3f0e305..40eb1a2 100644
@@ -1891,7 +1891,9 @@ pot:
 POFILES := $(wildcard po/*.po)
 MOFILES := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/git.mo,$(POFILES))
 MODIRS := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/,$(POFILES))
+ifndef NO_GETTEXT
 all:: $(MOFILES)
+endif
 share/locale/%/LC_MESSAGES/git.mo: po/%.po
 	@mkdir -p $(dir $@)
 	$(QUIET_MSGFMT)$(MSGFMT) -o $@ $<
@@ -2008,9 +2010,11 @@ install: all
 	$(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 	$(INSTALL) -m 644 $(SCRIPT_LIB) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 	$(INSTALL) $(install_bindir_programs) '$(DESTDIR_SQ)$(bindir_SQ)'
+ifndef NO_GETTEXT
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(sharedir_SQ)/locale'
 	(cd share && tar cf - locale) | \
 		(cd '$(DESTDIR_SQ)$(sharedir_SQ)' && umask 022 && tar xof -)
+endif
 	$(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
 ifndef NO_PERL
 	$(MAKE) -C perl prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install
Signature · 1 line
1.7.1.248.gb7713.dirty
#52 lore raw

PATCH v3 5/7 Makefile: Override --keyword= for all languages

In reply to Ævar Arnfjörð Bjarmason

By default xgettext will supply a default list of keywords depending on the --language parameter. Disable this in favor of supplying a list of keywords manually.

This reduced the surface area for potential bugs.

---
 Makefile |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
Makefile +3 -3
index 40eb1a2..62b8279 100644
@@ -1884,9 +1884,9 @@ cscope:
 	$(FIND) . -name '*.[hcS]' -print | xargs cscope -b
 
 pot:
-	$(XGETTEXT) --keyword=_ --output=po/git.pot --language=C $(C_OBJ:o=c)
-	$(XGETTEXT) --join-existing --output=po/git.pot --language=Shell $(SCRIPT_SH)
-	$(XGETTEXT) --join-existing --output=po/git.pot --language=Perl $(SCRIPT_PERL)
+	$(XGETTEXT) --keyword= --keyword=_ --output=po/git.pot --language=C $(C_OBJ:o=c)
+	$(XGETTEXT) --join-existing --keyword= --keyword=gettext --output=po/git.pot --language=Shell $(SCRIPT_SH)
+	$(XGETTEXT) --join-existing --keyword= --keyword=gettext --output=po/git.pot --language=Perl $(SCRIPT_PERL)
 
 POFILES := $(wildcard po/*.po)
 MOFILES := $(patsubst po/%.po,share/locale/%/LC_MESSAGES/git.mo,$(POFILES))
Signature · 1 line
1.7.1.248.gb7713.dirty
#53 lore raw

PATCH v3 6/7 gettext: Basic sanity tests for Git's Gettext support

In reply to Ævar Arnfjörð Bjarmason
---
 t/t0200-gettext.sh |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)
 create mode 100755 t/t0200-gettext.sh
t/t0200-gettext.sh new file +28 -0
new file mode 100755
index 0000000..a8f9edd
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+test_description='Gettext support for Git'
+. ./test-lib.sh
+. ../../git-sh-setup
+
+test_expect_success 'sanity: $TEXTDOMAIN is git' '
+	test $TEXTDOMAIN = "git"
+'
+
+test_expect_success 'sanity: $TEXTDOMAINDIR exists' '
+	test -d $TEXTDOMAINDIR 
+'
+
+test_expect_success 'sanity: Icelandic locale was compiled' '
+    test -f $TEXTDOMAINDIR/is/LC_MESSAGES/git.mo
+'
+
+test_expect_success 'sanity: gettext(unknown) is passed through' '
+    gettext "" > expect &&
+    > actual &&
+    test_cmp expect actual &&
+    printf "This is not a translation string"  > expect
+	gettext "This is not a translation string" > actual &&
+    test_cmp expect actual
+'
+
+test_done
Signature · 1 line
1.7.1.248.gb7713.dirty
#55 lore raw

PATCH v3 7/7 gettext: Add a skeleton po/is.po

In reply to Ævar Arnfjörð Bjarmason

This example is.po file translates a little bit of C, Shell and Perl as an example.

---
 po/is.po |  282 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 282 insertions(+), 0 deletions(-)
 create mode 100644 po/is.po
po/is.po new file +282 -0
new file mode 100644
index 0000000..aa1923e
@@ -0,0 +1,282 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: Git\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2010-05-30 19:24+0000\n"
+"PO-Revision-Date: 2010-06-01 22:15+0000\n"
+"Last-Translator: Ævar Arnfjörð Bjarmason <[email protected]>\n"
+"Language-Team: Git Mailing List <[email protected]>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Poedit-Language: English\n"
+"X-Poedit-SourceCharset: utf-8\n"
+
+#: wt-status.c:53
+msgid "# Unmerged paths:"
+msgstr ""
+
+#: wt-status.c:59 wt-status.c:76
+#, c-format
+msgid "#   (use \"git reset %s <file>...\" to unstage)"
+msgstr ""
+
+#: wt-status.c:61 wt-status.c:78
+msgid "#   (use \"git rm --cached <file>...\" to unstage)"
+msgstr ""
+
+#: wt-status.c:62
+msgid "#   (use \"git add/rm <file>...\" as appropriate to mark resolution)"
+msgstr ""
+
+#: wt-status.c:63 wt-status.c:79 wt-status.c:98 wt-status.c:110
+#: wt-status.c:115 wt-status.c:638 wt-status.c:640
+msgid "#"
+msgstr ""
+
+#: wt-status.c:70
+msgid "# Changes to be committed:"
+msgstr ""
+
+#: wt-status.c:88
+msgid "# Changed but not updated:"
+msgstr ""
+
+#: wt-status.c:92
+msgid "#   (use \"git add <file>...\" to update what will be committed)"
+msgstr ""
+
+#: wt-status.c:94
+msgid "#   (use \"git add/rm <file>...\" to update what will be committed)"
+msgstr ""
+
+#: wt-status.c:95
+msgid ""
+"#   (use \"git checkout -- <file>...\" to discard changes in working "
+"directory)"
+msgstr ""
+
+#: wt-status.c:97
+msgid "#   (commit or discard the untracked or modified content in submodules)"
+msgstr ""
+
+#: wt-status.c:106
+#, c-format
+msgid "# %s files:"
+msgstr ""
+
+#: wt-status.c:109
+#, c-format
+msgid "#   (use \"git %s <file>...\" to include in what will be committed)"
+msgstr ""
+
+#: wt-status.c:126
+msgid "bug"
+msgstr ""
+
+#: wt-status.c:129 wt-status.c:182
+msgid "#\t"
+msgstr ""
+
+#: wt-status.c:131
+msgid "both deleted:"
+msgstr ""
+
+#: wt-status.c:132
+msgid "added by us:"
+msgstr ""
+
+#: wt-status.c:133
+msgid "deleted by them:"
+msgstr ""
+
+#: wt-status.c:134
+msgid "added by them:"
+msgstr ""
+
+#: wt-status.c:135
+msgid "deleted by us:"
+msgstr ""
+
+#: wt-status.c:136
+msgid "both added:"
+msgstr ""
+
+#: wt-status.c:137
+msgid "both modified:"
+msgstr ""
+
+#: wt-status.c:139
+#, c-format
+msgid "%-20s%s\n"
+msgstr ""
+
+#: wt-status.c:165
+msgid " ("
+msgstr ""
+
+#: wt-status.c:167
+msgid "new commits, "
+msgstr ""
+
+#: wt-status.c:169
+msgid "modified content, "
+msgstr ""
+
+#: wt-status.c:171
+msgid "untracked content, "
+msgstr ""
+
+#: wt-status.c:185
+#, c-format
+msgid "new file:   %s"
+msgstr ""
+
+#: wt-status.c:188
+#, c-format
+msgid "copied:     %s -> %s"
+msgstr ""
+
+#: wt-status.c:191
+#, c-format
+msgid "deleted:    %s"
+msgstr ""
+
+#: wt-status.c:194
+#, c-format
+msgid "modified:   %s"
+msgstr ""
+
+#: wt-status.c:197
+#, c-format
+msgid "renamed:    %s -> %s"
+msgstr ""
+
+#: wt-status.c:200
+#, c-format
+msgid "typechange: %s"
+msgstr ""
+
+#: wt-status.c:203
+#, c-format
+msgid "unknown:    %s"
+msgstr ""
+
+#: wt-status.c:206
+#, c-format
+msgid "unmerged:   %s"
+msgstr ""
+
+#: wt-status.c:209
+#, c-format
+msgid "bug: unhandled diff status %c"
+msgstr ""
+
+#: wt-status.c:212
+#, c-format
+msgid "%s"
+msgstr ""
+
+#: wt-status.c:215
+#, c-format
+msgid "\n"
+msgstr ""
+
+#: wt-status.c:622
+msgid "On branch "
+msgstr "Á greininni "
+
+#: wt-status.c:629
+msgid "Not currently on any branch."
+msgstr "Ekki á neinni grein."
+
+#: wt-status.c:639
+msgid "# Initial commit"
+msgstr ""
+
+#: wt-status.c:651
+msgid "Untracked"
+msgstr ""
+
+#: wt-status.c:651
+msgid "add"
+msgstr ""
+
+#: wt-status.c:653
+msgid "Ignored"
+msgstr ""
+
+#: wt-status.c:653
+msgid "add -f"
+msgstr ""
+
+#: wt-status.c:655
+#, c-format
+msgid "# Untracked files not listed%s\n"
+msgstr ""
+
+#: wt-status.c:657
+msgid " (use -u option to show untracked files)"
+msgstr ""
+
+#: wt-status.c:663
+#, c-format
+msgid "# No changes\n"
+msgstr "# Engar breytingar\n"
+
+#: wt-status.c:667
+#, c-format
+msgid "no changes added to commit%s\n"
+msgstr ""
+
+#: wt-status.c:669
+msgid " (use \"git add\" and/or \"git commit -a\")"
+msgstr ""
+
+#: wt-status.c:671
+#, c-format
+msgid "nothing added to commit but untracked files present%s\n"
+msgstr ""
+
+#: wt-status.c:673
+msgid " (use \"git add\" to track)"
+msgstr ""
+
+#: wt-status.c:676
+msgid " (create/copy files and use \"git add\" to track)"
+msgstr ""
+
+#: wt-status.c:678 wt-status.c:681
+#, c-format
+msgid "nothing to commit%s\n"
+msgstr ""
+
+#: wt-status.c:679
+msgid " (use -u to show untracked files)"
+msgstr ""
+
+#: wt-status.c:682
+msgid " (working directory clean)"
+msgstr ""
+
+#: git-pull.sh:124
+msgid "Fetching tags only, you probably meant:"
+msgstr "Næ aðeins í tögg, þú áttir líkast til við:"
+
+#: git-pull.sh:125
+msgid "  git fetch --tags"
+msgstr ""
+
+#: git-pull.sh:157
+msgid ""
+"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."
+msgstr ""
+
+#: git-send-email.perl:678
+#, perl-format
+msgid "Emails will be sent from: %s\n"
+msgstr "Póstarnir verða sendir frá: %s\n"
Signature · 1 line
1.7.1.248.gb7713.dirty
#17 lore raw

Re: [PATCH/RFC v2 5/6] gettext: Add a Gettext interface for Perl

In reply to Ævar Arnfjörð Bjarmason
Quoted 21 lines · Ævar Arnfjörð Bjarmason
Quoted 20 lines · Jakub Narebski
Quoted 2 lines · Ævar Arnfjörð Bjarmason

Make Git's gettext messages available to Perl programs through Locale::Messages. [...]

This is I think a very good idea [...] using the Locale::Messages module from libintl-perl library. The "On the state of i18n in Perl" (http://rassie.org/archives/247) blog post from 26 April 2009 provides nice counterpoint to Locale::Maketext::TPJ13 / The Perl Journal #13 article[1] from 1999... especially because using gettext is natural for translating git command output and GUI, because git uses it already for Tcl/Tk (gitk and git-gui), and it is natural solution for code in C, which slightly less than half of git code.

Well, we could use Locale::Maketext::Gettext, but it is not in Perl core either, and as http://rassie.org/archives/247 says its '*.po' files are less natural. The gettext documentation (gettext.info) also recommends libintl-perl, or to be more exact Locale::TextDomain from it.

Quoted 7 lines
Quoted 2 lines

[1] http://search.cpan.org/perldoc?Locale::Maketext::TPJ13
http://interglacial.com/~sburke/tpj/as_html/tpj13.html

Locale::Maketext is a less complete and non-standard alternative as the above blogs note. I think the main reason it's used in favor of Gettext in many Perl projects is that it can be compiled stand-alone from the CPAN, i.e. it doesn't depend on libintl.

That, and the fact that some Perl projects / modules on CPAN started using Locale::Maketext before gettext acquired functionality for handling plural forms like ngettext. The mentioned article from The Perl Journal #13 might have also mislead module authors...

On the other hand libintl-perl distribution contains pure-Perl gettext emulation module: Locale::gettext_pp.

Quoted 5 lines

That's comfortable when CPAN is your main distribution channel, but Git's main distribution channel is via OS packages, which can trivially introduce a gettext dependency (for which they doubtless already have a package).

We need gettext for C, for shell, and for Tcl/Tk anyway.

BTW. some projects keep copy of libintl / gettext library in 'intl/' subdirectory, to be used if it is not present in the target system. Perl has 'inc/' and 'use inc::latest' (unfortunately in core only since 5.011002, i.e. 5.12 in practice) to keep private copy of modules to be used / installed if they are not present in system.

Quoted 3 lines

Locale::Maketext has a Gettext emulation layer, but using it would be a potential source of bugs (no emulation is perfect).

OTOH see Locale::gettext_pp from libintl-perl (the distribution containing Locale::Messages and Locale::TextDomain modules).

Quoted 5 lines

That being said the way I wrote Git::Gexttext means any alterante implementation or emulation layer can be seemlessly added later on. We could use (or write) something for Perl, C or Shell that completely bypasses libintl for systems that don't have a gettext C library.

Right.

Besides I think that the base gettext (no plural forms etc.) is the same (would produce the same *.po files) for Locale::Maketext::Gettext and for Locale::Messages / Locale::TextDomain.

Quoted 37 lines
Quoted 22 lines

The question is why not use Locale::TextDomain, the high-level Perl-y framework, wrapper around Locale::Messages from the same libintl-perl library? The gettext documentation (in gettext.info, chapter "13.5.18 Perl") says:

Prerequisite
`use POSIX;'
`use Locale::TextDomain;' (included in the package libintl-perl which is available on the Comprehensive Perl Archive Network CPAN,
http://www.cpan.org/).

This would change

- print "Emails will be sent from: ", $sender, "\n";
+ printf gettext("Emails will be sent from: %s\n"), $sender;

to either

+ print __"Emails will be sent from: ", $sender, "\n";

Quoted 8 lines

or

+ printf __("Emails will be sent from: %s\n"), $sender;

or

+ print __x("Emails will be sent from: {sender}\n",
+ sender => $sender);

I didn't use Locale::TextDomain because it exports a fatter interface by default, and I'm not sure at this point what subset of it it would make sense to support.

This is the default Locale::TextDomain interface:

Quoted 7 lines
   @EXPORT = qw (__ __x __n __nx __xn __p __px __np __npx $__ %__
                 N__ N__n N__p N__np);

My Git::Gettext only exports a single gettext() function now. I think it's better at this point to have a really small interface and decide later if we'd like to expand it, preferably in a way that'll work consistently across C, Perl and Shell programs.

That is not, I think, the problem. You don't need to re-export _all_ of Locale::TextDomain interface (or create and export stubs for all above functions and variables).

Quoted 4 lines

We might want to improve plural support, add msgctxt etc. later. But for an initial implementation I'd rather have something simple & stupid.

That's understandable.

BTW. I wonder if git currently has anywhere mesage that depends on plural form, or does it always use plural / multiform, like for example '1 files changed' from "git diff --summary"...

Quoted 31 lines
Quoted 17 lines
Quoted 17 lines
---
 Makefile            |    4 ++-
 git-send-email.perl |    3 +-
 perl/Git/Gettext.pm |   83 +++++++++++++++++++++++++++++++++++++++++++++++++++
 perl/Makefile.PL    |    5 ++-
 4 files changed, 92 insertions(+), 3 deletions(-)
 create mode 100644 perl/Git/Gettext.pm
Makefile +0 -0
index dce2faa..2101713 100644
@@ -1884,7 +1884,9 @@ cscope:
      $(FIND) . -name '*.[hcS]' -print | xargs cscope -b
 
Quoted 7 lines

Makefile cscope: · line 1888

Quoted 4 lines
Makefile +2 -1
 pot:
-     $(XGETTEXT) -k_ -o po/git.pot $(C_OBJ:o=c) $(SCRIPT_SH)
+     $(XGETTEXT) --keyword=_ --output=po/git.pot --language=C $(C_OBJ:o=c)
+     $(XGETTEXT) --join-existing --output=po/git.pot --language=Shell $(SCRIPT_SH)

Shouldn't this line be in earlier patch, i.e. in "gettext: Add a Gettext interface for shell scripts"?

It needed to be split up into seperate line in the Perl commit because ...

Quoted 4 lines

Makefile cscope: · line 1889

Quoted 1 line
Makefile +1 -0
+     $(XGETTEXT) --join-existing --output=po/git.pot --language=Perl $(SCRIPT_PERL)

From gettext documentation (in gettext.info, chapter "13.5.18 Perl"):

Quoted 8 lines
Quoted 5 lines

Extractor

    `xgettext -k__ -k\$__ -k%__ -k__x -k__n:1,2 -k__nx:1,2 -k__xn:1,2
    -kN__ -k'

Is it equivalent to specifying 'xgettext --language=Perl'?

I'm doing --language=Perl because gettext doesn't recognize .perl as a valid Perl extension. It only knows about pl', PL', pm', cgi'.

All right.

Quoted 13 lines

(As an aside, I haven't found why Git chose to use the quaint .perl extension).

But yeah, using --language=Perl is overshooting it with regards to keyword extraction. From "5.1 Invoking the `xgettext' Program":

To disable the default keyword specifications, the option -k' or --keyword' or `--keyword=', without a KEYWORDSPEC, can be used.

I'll check if I can supply --keyword to all the XGETTEXT invocations.

Quoted 2 lines

Of course the above assumes that you are using Locale::TextDomain, or at least use the same conventions.

In my opinion we should use the common convention for the programming language, like described in chapter 15 "Other Programming Languages" in gettext manual:
http://www.gnu.org/software/gettext/manual/gettext.html#Programming-Languages

 * C:      _("msg")
 * Perl:   __"msg"
 * shell:  $(gettext "abc")

* Tcl/Tk: [_ "msg"]
* Python: _('msg')

On the other hand the only currently traslated part of git, namely gitk and git-gui, both of which are written in Tcl/Tk, do not use recommended gettext shorthand, i.e. [_ "msg"], but the gettext function directly, i.e. [mc "msg"] (in the imported form, and not [::msgcat::mc "msg"]). I guess this is caused by the fact that shorthand is not that shorter here...

Quoted 15 lines
Quoted 15 lines

Makefile if (!defined $sender) { · line 678

Quoted 8 lines
Makefile +1 -1
 Getopt::Long::Configure qw/ pass_through /;
 
@@ -674,7 +675,7 @@ if (!defined $sender) {
      $sender = $repoauthor || $repocommitter || '';
      $sender = ask("Who should the emails appear to be from? [$sender] ",
                    default => $sender);
-     print "Emails will be sent from: ", $sender, "\n";
+     printf gettext("Emails will be sent from: %s\n"), $sender;

As I wrote, this IMHO should be either

+ printf __("Emails will be sent from: %s\n"), $sender;

or

Quoted 7 lines
Quoted 3 lines

+ print __x("Emails will be sent from: {sender}\n", sender => $sender);

(note that parantheses differ in those two examples).

I'd prefer the former argument expansion form (i.e. %s, not {$sender}), just so translators don't have to deal with two different argument forms.

Well, in this case this does not matter (much), because we have only single placeholder.

The Locale::TextDomain manpage says that the reason behind __x() is twofold. First, you would need context to know what placeholder means in

printf __"This is the %s %s.\n", $color, $thing;

as you would have only

msgid "This is the %s %s.\n"

in the PO file. Second, formatting with position (to change order of parameters) is possible with 'printf' only for Perl 5.8.0 or never:

  printf __("This is the %1\$s %2\$s.\n"), $color, $thing;

So that's the reason for introducing

print __x("This is the {color} {thing}.\n",

            color => $color, thing => $thing);
Quoted 11 lines

As for __ or gettext I don't mind. I just picked the former on a whim to match the Shell version. Maybe I should just change C|Perl|Shell to use _?

And we can use _, __ is just used to disambiguate it from the _ filehandle, and Perl's pretty good at disambiguating that already:

    $ perl -E 'sub _ ($) { scalar reverse $_[0] }; say _("moo"); stat
"/etc/hosts"; say ((stat(_))[7])'
    oom
    168

Locale::TextDomain::FAQ says:

Q. Why does Locale::TextDomain use a double underscore? I am used to
a single underscore from C or other languages.

A. Function names that consist of exactly one non-alphanumerical
character make the function automatically global in Perl. Besides, in Perl 6 the concatenation operator will be the underscore instead of the dot.

[jn: actually the string concatenation operator in Perl 6 is '~',
according to http://perlgeek.de/en/article/5-to-6#post_11:
"Perl 5 to 6" Lesson 11 - Changes to Perl 5 Operators]

Although 'gettext-tools/examples/hello-perl/hello-1.pl.in' from gettext sources
http://git.savannah.gnu.org/cgit/gettext.git/tree/gettext-tools/examples/hello-perl/hello-1.pl.in
(hello-1 uses Locale::Messages, hello-2 uses Locale::TextDomain) uses _("msg") shortcut:

sub _ ($) { &gettext; }

Hmmm...

Quoted 12 lines
Quoted 12 lines

perl/Git/Gettext.pm line 1

Quoted 7 lines
perl/Git/Gettext.pm new file +1 -0
new file mode 100644
index 0000000..f434783
@@ -0,0 +1,83 @@
+package Git::Gettext;

Should this package be named Git::Gettext, or other name would be better, perhaps Git::I18N (like e.g. Games::Risk have Games::Risk::I18N), or Git::Locale, or even Git::Translator?

Quoted 4 lines
Quoted 1 line

Not very important.

I really have no opinion on that, but it does seem like a lot of Perl packages on CPAN use the ::I18N suffix.

Also using Git::I18N allows us to change the backend from gettext to something other (like Locale::Maketext lexicon, or something yet another).

Quoted 7 lines
Quoted 7 lines

perl/Git/Gettext.pm line 5

Quoted 4 lines
perl/Git/Gettext.pm new file +4 -0
+use strict;
+use warnings;
+use Exporter;
+use base 'Exporter';

O.K.

Quoted 7 lines
Quoted 3 lines

The alternative would be to use

+use Exporter qw(import);

Not if we want to maintain 5.6 support. The `use Exporter "import"' form was only introduced in 5.8. I use it everywhere where I don't have to care about 5.6 support (which is everywhere but Git).

Oh, all right. Thanks for explanation.

Quoted 6 lines
Quoted 6 lines

perl/Git/Gettext.pm line 12

Quoted 2 lines
perl/Git/Gettext.pm new file +2 -0
+our %EXPORT_TAGS;
+@{ $EXPORT_TAGS{'all'} } = @EXPORT_OK;

Why not simply

+our %EXPORT_TAGS = ('all' => [ @EXPORT_OK ]);

[...]

Quoted 8 lines

Just because it some old code of mine I had around that I copied from. I could rewrite it to a nicer form.

Actually I was considering changing it to just have @EXPORT and nothing else. You're going to use gettext if you use the module anyway, so we might as well just import them all everywhere we use Gettext in Perl.

Right, if we use Git::Gettext / Git::I18N it means that we want to do message traslation, so we would need to import subroutines anyway.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
perl/Git/Gettext.pm new file +7 -0
+
+sub __bootstrap_locale_messages {
+     our $TEXTDOMAIN = 'git';
+
+     # TODO: How do I make the sed replacements in the top level
+     # Makefile reach me here?
+     #our $TEXTDOMAINDIR = q|@@LOCALEDIR@@|;

[...]

Quoted 6 lines
Quoted 6 lines

Make invoked on perl/Makefile, when invoked from main Makefile by '$(MAKE) -C perl' (via QUIET_SUBDIR0) passes 'localedir' to submake; perl/Makefile should probably have something like

localedir ?= $(sharedir)/locale

Quoted 8 lines
Quoted 4 lines

That is assuming that 'localedir' is added to list of exported variables.

But I am not sure how such substitution should be performed.

I'll try to get something like that to work. Actually the main problem seemed to be that it had a hybrid handwritten Makefile and one made by EU::MM.

The problem with EU::MM is that while ExtUtils::MakeMaker was first released as a core module with Perl 5, git requires for generated makefile (well, perl.mak included by perl/Makefile) to be compatibile with DESTDIR mechanism. This requires ExtUtils::MakeMaker version 6.11+, which was released with perl 5.006002 (Perl v5.6.2).

Hmmm... perhaps we can bump requirement from Perl 5.6 to Perl 5.6.2 and get rid of hybrid handwritten Makefile?

Otherwise you would have to either duplicate EU::MM work in handwritten Makefile, or somehow make perl/Makefile to do transformation before perl/perl.mak generated by EU::MM starts working...

Quoted 17 lines
Quoted 4 lines
Quoted 4 lines
perl/Git/Gettext.pm new file +4 -0
+
+BEGIN
+{
+     local ($@, $!);
Quoted 8 lines

perl/Git/Gettext.pm line 44

Quoted 6 lines
perl/Git/Gettext.pm new file +6 -0
+     eval { __bootstrap_locale_messages() };
+     if ($@) {
+             # Oh noes, no Locale::Messages here
+             *gettext = sub ($) { $_[0] };
+     }
+}

Does it need to be in BEGIN block? Probably yes.

I'm pretty sure it needs to all be at BEGIN time. I recall that declaring prototypes at runtime was an error in some older versions, but it works now:

Quoted 5 lines
    $ perl -E '*meh = sub ($) { "foo" }; say prototype "meh"'
    $

Anyway since it's code that's being use'd it's going to always be at BEGIN time anyway. I just wanted to be explicit.

All right, probably better to be safe.

Quoted 10 lines
Quoted 7 lines

perl/Git/Gettext.pm line 70

Quoted 4 lines

+=head1 EXPORTS

perl/Git/Gettext.pm new file +3 -0
+
+Exports are done via L<Exporter>. Invididual functions can be
+exporter, or all of them via the C<:all> export tag.

Shouldn't this be described in less technical way in SYNOPSIS and DESCRIPTION sections instead?

Yeah, maybe. But there's a convention for `=head1 EXPORTS' in perl core / CPAN. So that's what I added at a whim.

Hmmm... I don't recall seeing EXPORTS section often in manpages for Perl modules, at least not for the ones I use...

BTW. I tried to find Perl module / Perl program that uses Locale::TextDomain for l10n, but provides passthrough fallback if it is not installed... but haven't find any.

Signature · 2 lines
Jakub Narebski
Poland
#30 lore raw

Re: [PATCH/RFC v4 1/7] Add infrastructure for translating Git with gettext

In reply to Ævar Arnfjörð Bjarmason

Ævar Arnfjörð Bjarmason:

wt-status.c static void wt_status_print_unmerged_header(struct wt_status *s) · line 63

Quoted 3 lines
wt-status.c +3 -0
+		color_fprintf_ln(s->fp, c, _("#   (use \"git rm --cached <file>...\" to unstage)"));
+	color_fprintf_ln(s->fp, c, _("#   (use \"git add/rm <file>...\" as appropriate to mark resolution)"));
+	color_fprintf_ln(s->fp, c, _("#"));

This is a multi-line string, and should be translated as such.

The trailing "#" should either be part of the translated multi-line string, or be added explicitely, and untranslated, at the end.

Review

Quoted 2 lines
(quoted diff) +2 -0
+		color_fprintf_ln(s->fp, c, _("#   (use \"git rm --cached <file>...\" to unstage)"));
+	color_fprintf_ln(s->fp, c, _("#"));

Determine how to handle the trailing "#" as above.

wt-status.c static void wt_status_print_dirty_header(struct wt_status *s, · line 95

Quoted 2 lines
wt-status.c +2 -0
+		color_fprintf_ln(s->fp, c, _("#   (use \"git add/rm <file>...\" to update what will be committed)"));
+	color_fprintf_ln(s->fp, c, _("#   (use \"git checkout -- <file>...\" to discard changes in working directory)"));

Multi-line.

wt-status.c static void wt_status_print_dirty_header(struct wt_status *s, · line 98

Quoted 2 lines
wt-status.c +2 -0
+		color_fprintf_ln(s->fp, c, _("#   (commit or discard the untracked or modified content in submodules)"));
+	color_fprintf_ln(s->fp, c, _("#"));

Trailing "#".

wt-status.c static void wt_status_print_other_header(struct wt_status *s, · line 110

Quoted 2 lines
wt-status.c +2 -0
+	color_fprintf_ln(s->fp, c, _("#   (use \"git %s <file>...\" to include in what will be committed)"), how);
+	color_fprintf_ln(s->fp, c, _("#"));

Ditto.

wt-status.c static void wt_status_print_unmerged_data(struct wt_status *s, · line 139

Quoted 10 lines
wt-status.c +7 -0
+	case 1: how = _("both deleted:"); break;
+	case 2: how = _("added by us:"); break;
+	case 3: how = _("deleted by them:"); break;
+	case 4: how = _("added by them:"); break;
+	case 5: how = _("deleted by us:"); break;
+	case 6: how = _("both added:"); break;
+	case 7: how = _("both modified:"); break;
	}
wt-status.c +1 -1
-	color_fprintf(s->fp, c, "%-20s%s\n", how, one);
+	color_fprintf(s->fp, c, _("%-20s%s\n"), how, one);

does color_fprintf() gracefully handle cutting text for multi-byte encodings, and text width? Otherwise I can see this bite us for all non-ASCII locales in general (if long translated are needed), and for CJK locales in particular (for variable character widths).

wt-status.c static void wt_status_print_change_data(struct wt_status *s, · line 212

Quoted 2 lines
wt-status.c +1 -1
-		color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "%s", extra.buf);
+		color_fprintf(s->fp, color(WT_STATUS_HEADER, s), _("%s"), extra.buf);

Should not be in _()

wt-status.c static void wt_status_print_change_data(struct wt_status *s, · line 215

Quoted 2 lines
wt-status.c +1 -1
-	fprintf(s->fp, "\n");
+	fprintf(s->fp, _("\n"));

Ditto.

wt-status.c void wt_status_print(struct wt_status *s) · line 640

Quoted 3 lines
wt-status.c +3 -0
+		color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), _("#"));
+		color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), _("# Initial commit"));
+		color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), _("#"));

Either a multi-line string, or untranslate the "#"s.

Signature · 1 line
\\// Peter - http://www.softwolves.pp.se/
#31 lore raw

Re: [PATCH/RFC v4 1/7] Add infrastructure for translating Git with gettext

Quoted 66 lines · Peter Krefting

Ævar Arnfjörð Bjarmason:

Quoted 5 lines

+               color_fprintf_ln(s->fp, c, _("#   (use \"git rm --cached <file>...\" to unstage)"));
+       color_fprintf_ln(s->fp, c, _("#   (use \"git add/rm <file>...\" as appropriate to mark resolution)"));
+       color_fprintf_ln(s->fp, c, _("#"));

This is a multi-line string, and should be translated as such.

The trailing "#" should either be part of the translated multi-line string, or be added explicitely, and untranslated, at the end.

Quoted 3 lines

+               color_fprintf_ln(s->fp, c, _("#   (use \"git rm --cached <file>...\" to unstage)"));
+       color_fprintf_ln(s->fp, c, _("#"));

Determine how to handle the trailing "#" as above.

Quoted 4 lines

+               color_fprintf_ln(s->fp, c, _("#   (use \"git add/rm <file>...\" to update what will be committed)"));
+       color_fprintf_ln(s->fp, c, _("#   (use \"git checkout -- <file>...\" to discard changes in working directory)"));

Multi-line.

Quoted 3 lines

+               color_fprintf_ln(s->fp, c, _("#   (commit or discard the untracked or modified content in submodules)"));
+       color_fprintf_ln(s->fp, c, _("#"));

Trailing "#".

Quoted 3 lines

+       color_fprintf_ln(s->fp, c, _("#   (use \"git %s <file>...\" to include in what will be committed)"), how);
+       color_fprintf_ln(s->fp, c, _("#"));

Ditto.

Quoted 10 lines

+       case 1: how = _("both deleted:"); break;
+       case 2: how = _("added by us:"); break;
+       case 3: how = _("deleted by them:"); break;
+       case 4: how = _("added by them:"); break;
+       case 5: how = _("deleted by us:"); break;
+       case 6: how = _("both added:"); break;
+       case 7: how = _("both modified:"); break; }
-       color_fprintf(s->fp, c, "%-20s%s\n", how, one);
+       color_fprintf(s->fp, c, _("%-20s%s\n"), how, one);

does color_fprintf() gracefully handle cutting text for multi-byte encodings, and text width? Otherwise I can see this bite us for all non-ASCII locales in general (if long translated are needed), and for CJK locales in particular (for variable character widths).

Quoted 4 lines

-               color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "%s", extra.buf);
+               color_fprintf(s->fp, color(WT_STATUS_HEADER, s), _("%s"), extra.buf);

Should not be in _()

Quoted 2 lines

-       fprintf(s->fp, "\n");
+       fprintf(s->fp, _("\n"));

Ditto.

Quoted 8 lines
Quoted 6 lines

+               color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), _("#"));
+               color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), _("# Initial commit"));
+               color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), _("#"));

Either a multi-line string, or untranslate the "#"s.

All of the points you raised are correct. This is a bad way to do things.

It was added in Jeff in his original WIP patch as an example of translation being possible, but I should just remove it. It's not ready to go in for the reasons you cited.

I'll just remove the wt-status.c chunk out of the patch completely in the next submission, and instead translate a few select strings in some C program well.

Making things like wt-status.c translatable is going to be hard to do properly. It uses a lot of lego (sticking strings incrementally together), and due to the coloring of output this'll be particularly hard to convert.

(Also, for reference, here's a general guide on how to translate C programs well):

http://gnu.april.org/software/automake/manual/gettext/Preparing-Strings.html

#32 lore raw

Re: [PATCH/RFC v4 1/7] Add infrastructure for translating Git with gettext

Ævar Arnfjörð Bjarmason:

Quoted 1 line

Making things like wt-status.c translatable is going to be hard to do properly. It uses a lot of lego (sticking strings incrementally together),

However, preparing them for translation is probably going to make them better anyway, as this kind of string building is incredibly brittle, even for English strings.

You also have to look out for pluralisation issues, fortunately Gettext does have support for the various types of plural forms that are used, so it should be possible. The problem is just identifying where they are needed.

Quoted 1 line

and due to the coloring of output this'll be particularly hard to convert.

Is the colouring based on knowing the contents of the actual text, or is it enough to know the markers? I admit not having looked at the colouring code at all...

Signature · 1 line
\\// Peter - http://www.softwolves.pp.se/
#33 lore raw

Re: [PATCH/RFC v4 1/7] Add infrastructure for translating Git with gettext

Quoted 8 lines · Peter Krefting

Ævar Arnfjörð Bjarmason:

Quoted 2 lines

Making things like wt-status.c translatable is going to be hard to do properly. It uses a lot of lego (sticking strings incrementally together),

However, preparing them for translation is probably going to make them better anyway, as this kind of string building is incredibly brittle, even for English strings.

Yeah, but they aren't better as they are now. Personally I'd rather incrementally add translation support correctly than do an incomplete job of it and wait for the complaints (and subsequent fixes) to come in.

But maybe that's counter-productive. Just making the English strings translatable as-is is still going to make most of Git translatable, and it isn't going to be that bad for languages like German and French.

Maybe worse is better :)

Quoted 3 lines

You also have to look out for pluralisation issues, fortunately Gettext does have support for the various types of plural forms that are used, so it should be possible. The problem is just identifying where they are needed.

Yeah. I'm going to support pluralisation (and maybe msgctxt) across the C-Perl-Shell stack when there's a need for it. I haven't found any message in Git yet that requires it, but then again I haven't looked hard either.

It would be useful to have an example of a message that could use pluralization, even better examples in all of C, Perl and Shell.

Quoted 5 lines
Quoted 1 line

and due to the coloring of output this'll be particularly hard to convert.

Is the colouring based on knowing the contents of the actual text, or is it enough to know the markers? I admit not having looked at the colouring code at all...

There's nothing wrong with coloring in particular, it's just that due to the nature of the current implementation code that does coloring ends up being a bad offender in the "assemble the strings a few bytes at a time with strcat()" department.

That can be fixed, it just takes a bit of time and tedium.

#34 lore raw

Re: [PATCH/RFC v4 1/7] Add infrastructure for translating Git with gettext

Ævar Arnfjörð Bjarmason:

Quoted 1 line

But maybe that's counter-productive. Just making the English strings translatable as-is is still going to make most of Git translatable, and it isn't going to be that bad for languages like German and French.

I think this is the best approach. Without actually making *everything* available for translation it is impossible to weed out the problems. Some of the easier "hack" strings (plural word%s, sentence %s%s building, etc) can be fixed during conversion, the rest can be done later as complai^Wcomments come in.

Quoted 1 line

It would be useful to have an example of a message that could use pluralization, even better examples in all of C, Perl and Shell.

There is the "Your branch is ahead of..." messages, they were introduced in commit b0030db331141bedfaf02f34a83f18712c0ae011, and are currently using a "commit%s" form, where the %s either maps to an empty string or "s". Should be fairly trivial to fix. I think there are other examples as well, but that's the first one I came to think of. :-)

Signature · 1 line
\\// Peter - http://www.softwolves.pp.se/
#41 lore raw

v5 cover Add infrastructure for translating Git with gettext

In reply to Ævar Arnfjörð Bjarmason

This is version 5 of the patch series to make Git optionally translatable with GNU gettext.

I split and squashed the whole thing down into just two patches. The first commit adds all the needed core infrastructure, and the second commit contains an initial stab at starting translation for the core tools, along with some tests that could be added as a result.

The changes this time around are:

* Testing testing & more testing. Including testing for xgettext message extraction, that .po files are generated correctly etc.

* There's now a git-sh-i18n library for the shell, so gettext.sh isn't loaded as part of git-sh-setup.

* Shell portability fixes suggested by Johannes Sixt

* Other misc suggestions and fixes Jakub Narebski, Peter Krefting, and Jonathan Nieder pointed out were incorporated.

* I did not change over to Locale::TextDomain for Perl. I wrote a version of Git::I18N in it and found that it was more trouble than it was worth

I think (this time around, really) that this series is ready for inclusion unless some issue is raised that I've missed. But to play devil's advocate this is what might prevent it from being included.

* gettext is on by default. I think that's a feature, but Git won't build by default on e.g. Solaris unless the packager adds NO_GETTEXT=YesPlease to the make arguments. Of course if they use ./configure it'll detect if libintl.h exists and act appropriately.

I think gettext on by default is a feature, it's equivalent to what we do for our other /*/po/ stuff. But pending discussion of this I haven't updated e.g. INSTALL. Comments welcome.

* There isn't documentation on how to use this from a developer and maintainer standpoint. And there's no docs for translators.

Where would the developer/maintainer docs belong? But for most of the things such a documentation would include I think other existing resources would do fine, e.g. the GNU gettext manual.

Ævar Arnfjörð Bjarmason (2):
Add infrastructure for translating Git with gettext Add initial C, Shell and Perl gettext translations

 .gitignore                         |    2 +
 Makefile                           |   44 ++++++++++-
 config.mak.in                      |    1 +
 configure.ac                       |    6 ++
 gettext.c                          |   25 ++++++
 gettext.h                          |   13 +++
 git-pull.sh                        |   16 ++--
 git-send-email.perl                |    3 +-
 git-sh-i18n.sh                     |   33 ++++++++
 git.c                              |    3 +
 perl/Git/I18N.pm                   |   77 +++++++++++++++++++
 perl/Makefile                      |    3 +-
 perl/Makefile.PL                   |   14 +++-
 po/.gitignore                      |    1 +
 po/is.po                           |   71 +++++++++++++++++
 t/t0200-gettext.sh                 |  146 ++++++++++++++++++++++++++++++++++++
 t/t0200-gettext/test.c             |   10 +++
 t/t0200-gettext/test.perl          |   11 +++
 t/t0200-gettext/test.sh            |   14 ++++
 t/t0201-gettext-shell-fallbacks.sh |   40 ++++++++++
 t/test-lib.sh                      |    1 +
 wt-status.c                        |  107 +++++++++++++-------------
 22 files changed, 576 insertions(+), 65 deletions(-)
 create mode 100644 gettext.c
 create mode 100644 gettext.h
 create mode 100644 git-sh-i18n.sh
 create mode 100644 perl/Git/I18N.pm
 create mode 100644 po/.gitignore
 create mode 100644 po/is.po
 create mode 100755 t/t0200-gettext.sh
 create mode 100644 t/t0200-gettext/test.c
 create mode 100644 t/t0200-gettext/test.perl
 create mode 100644 t/t0200-gettext/test.sh
 create mode 100755 t/t0201-gettext-shell-fallbacks.sh
#42 lore raw

PATCH v5 1/2 Add infrastructure for translating Git with gettext

In reply to Ævar Arnfjörð Bjarmason

All of the interface messages in Git core are currently hardcoded in English. Change that by optionally enabling translation of the core C, Shell and Perl programs via GNU gettext. If you set the appropriate LC_* variables Git will speak your language, provided that someone has submitted a translation.

If gettext isn't available, or if Git is compiled with NO_GETTEXT=YesPlease, then Git fall back on its previous behavior of only speaking English.

With NO_GETTEXT=YesPlease gettext support will be #defined away for C programs. For Shell and Perl programs we rely on the git message catalog not being avalalable. That's a reasonable assumption since the *.po files won't be installed on the system during make install.

The gettext wrappers that are provided in the patch are only the bare minimum required to begin translation work. In particular I haven't added wrappers for the gettext functions that enable plural support, or those that provide message context (msgctxt). Those can be added later. The intent is to start with a small subset and see what we need later, not to start with something that's unnecessarily large right away.

Implementation and usage notes:

* General:

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 this is only intended to be used to test Git itself.

* Perl:

Perl code that wants 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.

* Shell:

Shell code that wants to be localized should use the new git-sh-i18n library. It's just a wrapper for the system's gettext.sh.

If gettext.sh isn't available we'll fall back on a dumb printf(1)-powered fall-through wrapper.

I originally tried to detect if the system supported `echo -n' but I found this to be a waste of time. My benchmarks on Linux, Solaris and FreeBSD reveal that printf(1) is fast enough, especially since we aren't calling gettext() from within any tight loops.

This patch is based on work by Jeff Epler <[email protected]> who did the initial Makefile / C work, and a lot of comments from the Git mailing list.

---
 .gitignore                         |    2 +
 Makefile                           |   44 ++++++++++++++-
 config.mak.in                      |    1 +
 configure.ac                       |    6 ++
 gettext.c                          |   25 +++++++++
 gettext.h                          |   13 +++++
 git-sh-i18n.sh                     |   33 +++++++++++
 git.c                              |    3 +
 perl/Git/I18N.pm                   |   77 ++++++++++++++++++++++++++
 perl/Makefile                      |    3 +-
 perl/Makefile.PL                   |   14 +++++-
 po/.gitignore                      |    1 +
 po/is.po                           |   48 ++++++++++++++++
 t/t0200-gettext.sh                 |  104 ++++++++++++++++++++++++++++++++++++
 t/t0200-gettext/test.c             |   11 ++++
 t/t0200-gettext/test.perl          |   11 ++++
 t/t0200-gettext/test.sh            |   14 +++++
 t/t0201-gettext-shell-fallbacks.sh |   40 ++++++++++++++
 t/test-lib.sh                      |    1 +
 19 files changed, 447 insertions(+), 4 deletions(-)
 create mode 100644 gettext.c
 create mode 100644 gettext.h
 create mode 100644 git-sh-i18n.sh
 create mode 100644 perl/Git/I18N.pm
 create mode 100644 po/.gitignore
 create mode 100644 po/is.po
 create mode 100755 t/t0200-gettext.sh
 create mode 100644 t/t0200-gettext/test.c
 create mode 100644 t/t0200-gettext/test.perl
 create mode 100644 t/t0200-gettext/test.sh
 create mode 100755 t/t0201-gettext-shell-fallbacks.sh
.gitignore +2 -0
index 14e2b6b..6c2b193 100644
@@ -125,6 +125,7 @@
 /git-rm
 /git-send-email
 /git-send-pack
+/git-sh-i18n
 /git-sh-setup
 /git-shell
 /git-shortlog
@@ -204,3 +205,4 @@
 *.pdb
 /Debug/
 /Release/
+/share/
Makefile +42 -2

129 lines not on this page · raw message

config.mak.in +1 -0
index 0d4b64d..a15f3c1 100644
@@ -32,6 +32,7 @@ NO_CURL=@NO_CURL@
 NO_EXPAT=@NO_EXPAT@
 NO_LIBGEN_H=@NO_LIBGEN_H@
 HAVE_PATHS_H=@HAVE_PATHS_H@
+NO_GETTEXT=@NO_GETTEXT@
 NEEDS_LIBICONV=@NEEDS_LIBICONV@
 NEEDS_SOCKET=@NEEDS_SOCKET@
 NEEDS_RESOLV=@NEEDS_RESOLV@
configure.ac +6 -0
index 71038fc..7bebfd8 100644
@@ -730,6 +730,12 @@ AC_CHECK_HEADER([paths.h],
 [HAVE_PATHS_H=])
 AC_SUBST(HAVE_PATHS_H)
 #
+# Define NO_GETTEXT if you don't have libintl.h
+AC_CHECK_HEADER([libintl.h],
+[NO_GETTEXT=],
+[NO_GETTEXT=YesPlease])
+AC_SUBST(NO_GETTEXT)
+#
 # Define NO_STRCASESTR if you don't have strcasestr.
 GIT_CHECK_FUNC(strcasestr,
 [NO_STRCASESTR=],
gettext.c new file +25 -0
new file mode 100644
index 0000000..22cdcc1
@@ -0,0 +1,25 @@
+#ifdef NO_GETTEXT
+void git_setup_gettext(void) {}
+#else
+#include "exec_cmd.h"
+#include <libintl.h>
+#include <stdlib.h>
+
+void git_setup_gettext(void) {
+	char *podir;
+	char *envdir = getenv("GIT_TEXTDOMAINDIR");
+
+	if (envdir) {
+		(void)bindtextdomain("git", envdir);
+	} else {
+		podir = (char *)system_path("share/locale");
+		if (!podir) return;
+		(void)bindtextdomain("git", podir);
+		free(podir);
+	}
+
+	(void)setlocale(LC_MESSAGES, "");
+	(void)setlocale(LC_CTYPE, "");
+	(void)textdomain("git");
+}
+#endif
gettext.h new file +13 -0
new file mode 100644
index 0000000..a99da6a
@@ -0,0 +1,13 @@
+#ifndef GETTEXT_H
+#define GETTEXT_H
+
+void git_setup_gettext(void);
+
+#ifdef NO_GETTEXT
+#define _(s) (s)
+#else
+#include <libintl.h>
+#define _(s) gettext(s)
+#endif
+
+#endif
git-sh-i18n.sh new file +33 -0
new file mode 100644
index 0000000..ae1d5cd
@@ -0,0 +1,33 @@
+#!/bin/sh
+#
+# This is what Git uses internally to bootstrap its gettext
+# shellscript interface.
+
+# Try to use libintl's gettext.sh, or fall back to English if we
+# can't.
+. gettext.sh
+
+if test $? -eq 0 && test -z "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS"
+then
+	TEXTDOMAIN=git
+	export TEXTDOMAIN
+	if [ -z "$GIT_TEXTDOMAINDIR" ]
+	then
+		TEXTDOMAINDIR="@@LOCALEDIR@@"
+	else
+		TEXTDOMAINDIR="$GIT_TEXTDOMAINDIR"
+	fi
+	export TEXTDOMAINDIR
+else
+	# Since gettext.sh isn't available we'll have to define our own
+	# dummy pass-through functions.
+
+	gettext () {
+		printf "%s" "$1"
+	}
+
+	eval_gettext () {
+		gettext_eval="printf '%s' \"$1\""
+		printf "%s" "`eval \"$gettext_eval\"`"
+	}
+fi
git.c +3 -0
index 99f0363..d749eab 100644
@@ -3,6 +3,7 @@
 #include "cache.h"
 #include "quote.h"
 #include "run-command.h"
+#include "gettext.h"
 
 const char git_usage_string[] =
 	"git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]\n"
@@ -490,6 +491,8 @@ int main(int argc, const char **argv)
 	if (!cmd)
 		cmd = "git-help";
 
+	git_setup_gettext();
+
 	/*
 	 * "git-xxxx" is the same as "git xxxx", but we obviously:
 	 *
perl/Git/I18N.pm new file +77 -0

77 lines not on this page · raw message

perl/Makefile +2 -1
index 4ab21d6..4e624ff 100644
@@ -5,6 +5,7 @@ makfile:=perl.mak
 
 PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH))
 prefix_SQ = $(subst ','\'',$(prefix))
+localedir_SQ = $(subst ','\'',$(localedir))
 
 ifndef V
 	QUIET = @
@@ -38,7 +39,7 @@ $(makfile): ../GIT-CFLAGS Makefile
 	echo '	echo $(instdir_SQ)' >> $@
 else
 $(makfile): Makefile.PL ../GIT-CFLAGS
-	$(PERL_PATH) $< PREFIX='$(prefix_SQ)'
+	$(PERL_PATH) $< PREFIX='$(prefix_SQ)' --localedir='$(localedir_SQ)'
 endif
 
 # this is just added comfort for calling make directly in perl dir
perl/Makefile.PL +13 -1
index 0b9deca..456d45b 100644
@@ -1,4 +1,12 @@
+use strict;
+use warnings;
 use ExtUtils::MakeMaker;
+use Getopt::Long;
+
+# Sanity: die at first unknown option
+Getopt::Long::Configure qw/ pass_through /;
+
+GetOptions("localedir=s" => \my $localedir);
 
 sub MY::postamble {
 	return <<'MAKE_FRAG';
@@ -16,7 +24,10 @@ endif
 MAKE_FRAG
 }
 
-my %pm = ('Git.pm' => '$(INST_LIBDIR)/Git.pm');
+my %pm = (
+	'Git.pm' => '$(INST_LIBDIR)/Git.pm',
+	'Git/I18N.pm' => '$(INST_LIBDIR)/Git/I18N.pm',
+);
 
 # We come with our own bundled Error.pm. It's not in the set of default
 # Perl modules so install it if it's not available on the system yet.
@@ -33,6 +44,7 @@ WriteMakefile(
 	NAME            => 'Git',
 	VERSION_FROM    => 'Git.pm',
 	PM		=> \%pm,
+	PM_FILTER	=> qq[\$(PERL) -pe "s<\\Q++LOCALEDIR++\\E><$localedir>"],
 	MAKEFILE	=> 'perl.mak',
 	INSTALLSITEMAN3DIR => '$(SITEPREFIX)/share/man/man3'
 );
po/.gitignore new file +1 -0
new file mode 100644
index 0000000..221000e
@@ -0,0 +1 @@
+/*.pot
po/is.po new file +48 -0

48 lines not on this page · raw message

t/t0200-gettext.sh new file +104 -0

104 lines not on this page · raw message

t/t0200-gettext/test.c new file +11 -0
new file mode 100644
index 0000000..9fa4c23
@@ -0,0 +1,11 @@
+/* This is a phony C program that's only here to test xgettext message extraction */
+
+int main(void)
+{
+	/* TRANSLATORS: This is a test. You don't need to translate it. */
+	puts(_("TEST: A C test string"));
+
+	/* TRANSLATORS: This is a test. You don't need to translate it. */
+	printf(_("TEST: A C test string %s"), "variable");
+}
+	
t/t0200-gettext/test.perl new file +11 -0
new file mode 100644
index 0000000..8c50ef0
@@ -0,0 +1,11 @@
+# This is a phony Perl program that's only here to test xgettext
+# message extraction
+
+# TRANSLATORS: This is a test. You don't need to translate it.
+print __("TEST: A Perl test string");
+
+# TRANSLATORS: This is a test. You don't need to translate it.
+printf __("TEST: A Perl test variable %s"), "moo";
+
+# TRANSLATORS: If you see this, Git has a bug
+print _"TEST: A Perl string xgettext will not get";
t/t0200-gettext/test.sh new file +14 -0
new file mode 100644
index 0000000..022d607
@@ -0,0 +1,14 @@
+# This is a phony Shell program that's only here to test xgettext
+# message extraction
+
+# so the above comment won't be folded into the next one by xgettext
+echo
+
+# TRANSLATORS: This is a test. You don't need to translate it.
+gettext "TEST: A Shell test string"
+
+# TRANSLATORS: This is a test. You don't need to translate it.
+eval_gettext "TEST: A Shell test \$variable"
+
+# TRANSLATORS: If you see this, Git has a bug
+_("TEST: A Shell string xgettext won't get")
t/t0201-gettext-shell-fallbacks.sh new file +40 -0
new file mode 100755
index 0000000..827adb2
@@ -0,0 +1,40 @@
+#!/bin/sh
+D=`pwd`
+GIT_TEXTDOMAINDIR="$D/../share/locale"
+GIT_INTERNAL_GETTEXT_TEST_FALLBACKS=YesPlease
+
+export GIT_TEXTDOMAINDIR GIT_INTERNAL_GETTEXT_TEST_FALLBACKS
+
+test_description='Gettext Shell fallbacks'
+. ./test-lib.sh
+. ../../git-sh-i18n
+
+test_expect_success 'sanity: $GIT_INTERNAL_GETTEXT_TEST_FALLBACKS is set' '
+	test_expect_failure test -z "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS"
+'
+
+test_expect_success 'gettext: our gettext() fallback has pass-through semantics' '
+    printf "test" > expect &&
+    gettext "test" > actual &&
+    test_cmp expect actual &&
+    printf "test more words" > expect &&
+    gettext "test more words" > actual &&
+    test_cmp expect actual
+'
+
+test_expect_success 'eval_gettext: our eval_gettext() fallback has pass-through semantics' '
+    printf "test" > expect &&
+    eval_gettext "test" > actual &&
+    test_cmp expect actual &&
+    printf "test more words" > expect &&
+    eval_gettext "test more words" > actual &&
+    test_cmp expect actual
+'
+
+test_expect_success 'eval_gettext: our eval_gettext() fallback can interpolate variables' '
+    printf "test YesPlease" > expect &&
+    eval_gettext "test \$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS" > actual &&
+    test_cmp expect actual
+'
+
+test_done
t/test-lib.sh +1 -0
index 454880a..cb3c9c5 100644
@@ -37,6 +37,7 @@ ORIGINAL_TERM=$TERM
 # For repeatability, reset the environment to known value.
 LANG=C
 LC_ALL=C
+LANGUAGE=C
 PAGER=cat
 TZ=UTC
 TERM=dumb
Signature · 1 line
1.7.1.242.g290e3.dirty
#43 lore raw

PATCH v5 2/2 Add initial C, Shell and Perl gettext translations

In reply to Ævar Arnfjörð Bjarmason

Change the git status, git pull, and git send-email commands to have at least one translatable string. Each command uses a different core language, so this makes a good example of how C, Shell and Perl programs can be translated using gettext.

Since this introduces translation into the real Git tools more tests can be added to check if they translations actually work for real core tools.

---
 git-pull.sh            |   16 ++++---
 git-send-email.perl    |    3 +-
 po/is.po               |   27 +++++++++++-
 t/t0200-gettext.sh     |   42 +++++++++++++++++++
 t/t0200-gettext/test.c |    1 -
 wt-status.c            |  107 ++++++++++++++++++++++++------------------------
 6 files changed, 132 insertions(+), 64 deletions(-)
git-pull.sh +9 -7
index 1a4729f..0d95722 100755
@@ -9,6 +9,7 @@ LONG_USAGE='Fetch one or more remote refs and merge it/them into the current HEA
 SUBDIRECTORY_OK=Yes
 OPTIONS_SPEC=
 . git-sh-setup
+. git-sh-i18n
 set_reflog_action "pull $*"
 require_work_tree
 cd_to_toplevel
@@ -121,8 +122,8 @@ error_on_no_merge_candidates () {
 	do
 		case "$opt" in
 		-t|--t|--ta|--tag|--tags)
-			echo "Fetching tags only, you probably meant:"
-			echo "  git fetch --tags"
+			gettext "Fetching tags only, you probably meant:"; echo
+			gettext "  git fetch --tags"; echo
 			exit 1
 		esac
 	done
@@ -154,11 +155,12 @@ error_on_no_merge_candidates () {
 		echo "a branch. Because this is not the default configured remote"
 		echo "for your current branch, you must specify a branch on the command line."
 	elif [ -z "$curr_branch" ]; then
-		echo "You are not currently on a branch, so I cannot use any"
-		echo "'branch.<branchname>.merge' in your configuration file."
-		echo "Please specify which remote branch you want to use on the command"
-		echo "line and try again (e.g. 'git pull <repository> <refspec>')."
-		echo "See git-pull(1) for details."
+		gettext "You are not currently on a branch, so I cannot use any
+'branch.<branchname>.merge' in your configuration file.
+Please specify which remote branch you want to use on the command
+line and try again (e.g. 'git pull <repository> <refspec>').
+See git-pull(1) for details.";
+		echo
 	elif [ -z "$upstream" ]; then
 		echo "You asked me to pull without telling me which branch you"
 		echo "want to $op_type $op_prep, and 'branch.${curr_branch}.merge' in"
git-send-email.perl +2 -1
index 111c981..4977fdf 100755
@@ -26,6 +26,7 @@ use Term::ANSIColor;
 use File::Temp qw/ tempdir tempfile /;
 use Error qw(:try);
 use Git;
+use Git::I18N;
 
 Getopt::Long::Configure qw/ pass_through /;
 
@@ -674,7 +675,7 @@ if (!defined $sender) {
 	$sender = $repoauthor || $repocommitter || '';
 	$sender = ask("Who should the emails appear to be from? [$sender] ",
 	              default => $sender);
-	print "Emails will be sent from: ", $sender, "\n";
+	printf __("Emails will be sent from: %s\n"), $sender;
 	$prompting++;
 }
 
po/is.po +25 -2
index ac4317b..72437c3 100644
@@ -2,8 +2,8 @@ msgid ""
 msgstr ""
 "Project-Id-Version: Git\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2010-06-02 17:35+0000\n"
-"PO-Revision-Date: 2010-06-02 16:01+0000\n"
+"POT-Creation-Date: 2010-06-02 19:43+0000\n"
+"PO-Revision-Date: 2010-06-02 19:35+0000\n"
 "Last-Translator: Ævar Arnfjörð Bjarmason <[email protected]>\n"
 "Language-Team: Git Mailing List <[email protected]>\n"
 "MIME-Version: 1.0\n"
@@ -12,6 +12,20 @@ msgstr ""
 "X-Poedit-Language: English\n"
 "X-Poedit-SourceCharset: utf-8\n"
 
+#: wt-status.c:63 wt-status.c:79 wt-status.c:98 wt-status.c:110
+#: wt-status.c:622
+msgid "On branch "
+msgstr "Á greininni "
+
+#: wt-status.c:629
+msgid "Not currently on any branch."
+msgstr "Ekki á neinni grein."
+
+#: wt-status.c:663
+#, c-format
+msgid "# No changes\n"
+msgstr "# Engar breytingar\n"
+
 #. TRANSLATORS: This is a test. You don't need to translate it.
 #: t/t0200-gettext/test.c:6
 msgid "TEST: A C test string"
@@ -23,6 +37,10 @@ msgstr "TILRAUN: C tilraunastrengur"
 msgid "TEST: A C test string %s"
 msgstr "TILRAUN: C tilraunastrengur %s"
 
+#: git-pull.sh:124
+msgid "Fetching tags only, you probably meant:"
+msgstr "Næ aðeins í tögg, þú áttir líkast til við:"
+
 #. TRANSLATORS: This is a test. You don't need to translate it.
 #: t/t0200-gettext/test.sh:8
 msgid "TEST: A Shell test string"
@@ -34,6 +52,11 @@ msgstr "TILRAUN: Skeljartilraunastrengur"
 msgid "TEST: A Shell test $variable"
 msgstr "TILRAUN: Skeljartilraunastrengur með breytunni $variable"
 
+#: git-send-email.perl:678
+#, perl-format
+msgid "Emails will be sent from: %s\n"
+msgstr "Póstarnir verða sendir frá: %s\n"
+
 #. This is a phony Perl program that's only here to test xgettext
 #. message extraction
 #. TRANSLATORS: This is a test. You don't need to translate it.
t/t0200-gettext.sh +42 -0

46 lines not on this page · raw message

t/t0200-gettext/test.c +0 -1
index 9fa4c23..171bcc6 100644
@@ -8,4 +8,3 @@ int main(void)
 	/* TRANSLATORS: This is a test. You don't need to translate it. */
 	printf(_("TEST: A C test string %s"), "variable");
 }
-	
wt-status.c +54 -53

241 lines not on this page · raw message

Signature · 1 line
1.7.1.242.g290e3.dirty
#44 lore raw
In reply to Ævar Arnfjörð Bjarmason

Am 6/2/2010 2:11, schrieb Ævar Arnfjörð Bjarmason:

Quoted 1 line

+export GIT_TEXTDOMAINDIR=pwd/../share/locale

This works only in some shells for two reasons:

- 'export foo=bar' syntax is not understood everywhere;

- if it is understood, then some shells still split the expansion in 'export foo=pwd' at white-space.

Use 'foo=bar; export foo', like you did elsewhere.

Quoted 4 lines

test_expect_success 'sanity: $TEXTDOMAINDIR exists' '
- test -d $TEXTDOMAINDIR
+ test -d $TEXTDOMAINDIR &&
+ test $TEXTDOMAINDIR = $GIT_TEXTDOMAINDIR

Double-quotes, double-quotes!

-- Hannes

#47 lore raw

Re: [PATCH/RFC v3 2/7] gettext: Add a Gettext interface for shell scripts

In reply to Ævar Arnfjörð Bjarmason

[When you resend the series in such a manner that you collect a Cc list manually, please do *not* include me. I'm not interested in this series.]

Am 6/2/2010 1:39, schrieb Ævar Arnfjörð Bjarmason:

git-sh-setup.sh case $(uname -s) in · line 236

Quoted 5 lines
git-sh-setup.sh +5 -0
+    # Not everyone has echo -n
+    case $(echo -n) in
+        \-n)    Xn=   ; Xc='\c' ;;
+        *)      Xn=-n ; Xc=
+    esac

Don't use 'echo'; use 'printf %s'.

git-sh-setup.sh case $(uname -s) in · line 245

Quoted 9 lines
git-sh-setup.sh +9 -0
+
+    gettext () {
+        echo $Xn "$1" $Xc
+    }
+
+    eval_gettext () {
+        eval_gettext_var="echo $1"
+        echo $Xn `eval $eval_gettext_var` $Xc
+    }

-- Hannes

#48 lore raw

Re: [PATCH/RFC v3 2/7] gettext: Add a Gettext interface for shell scripts

Quoted 11 lines · Johannes Sixt

[When you resend the series in such a manner that you collect a Cc list manually, please do *not* include me. I'm not interested in this series.]

Am 6/2/2010 1:39, schrieb Ævar Arnfjörð Bjarmason:

Quoted 5 lines

+    # Not everyone has echo -n
+    case $(echo -n) in
+        \-n)    Xn=   ; Xc='\c' ;;
+        *)      Xn=-n ; Xc=
+    esac

Don't use 'echo'; use 'printf %s'.

I didn't write this code (as the comment says) but I /thought/ that the whole point of it was to autodetect if echo -n worked, and if so use it because it'd be faster than printf "%s", otherwise use some evil foo\n\c hack.

That hack doesn't work on bash ('\c' produces a space), maybe it doesn't work anywhere. Do you have a shell that doesn't support echo -n? What does it output there?

I wouldn't be surprised if it did need to be changed to printf "%s". I'm just curious where it broke and how.

#49 lore raw

Re: [PATCH/RFC v3 2/7] gettext: Add a Gettext interface for shell scripts

Am 6/2/2010 10:53, schrieb Ævar Arnfjörð Bjarmason:

Quoted 3 lines

That hack doesn't work on bash ('\c' produces a space), maybe it doesn't work anywhere. Do you have a shell that doesn't support echo -n? What does it output there?

It's not just echo -n. You are dealing with text that is outside your control. There are implementations of echo that interpret backslash in the text (like \t, \n etc.). You are risking that they are treated as escape characters rather than printed as-are.

Quoted 2 lines

I wouldn't be surprised if it did need to be changed to printf "%s". I'm just curious where it broke and how.

Actually, I don't know where -n does not work.

-- Hannes

#54 lore raw

Re: [PATCH/RFC v3 6/7] gettext: Basic sanity tests for Git's Gettext support

In reply to Ævar Arnfjörð Bjarmason

[When you resend the series in such a manner that you collect a Cc list manually, please do *not* include me. I'm not interested in this series.]

Am 6/2/2010 1:39, schrieb Ævar Arnfjörð Bjarmason:

t/t0200-gettext.sh line 17

Quoted 11 lines
t/t0200-gettext.sh new file +11 -0
+test_expect_success 'sanity: $TEXTDOMAIN is git' '
+	test $TEXTDOMAIN = "git"
+'
+
+test_expect_success 'sanity: $TEXTDOMAINDIR exists' '
+	test -d $TEXTDOMAINDIR 
+'
+
+test_expect_success 'sanity: Icelandic locale was compiled' '
+    test -f $TEXTDOMAINDIR/is/LC_MESSAGES/git.mo
+'

3 times: put "$foo" in double-quotes.

t/t0200-gettext.sh line 24

Quoted 6 lines
t/t0200-gettext.sh new file +6 -0
+test_expect_success 'sanity: gettext(unknown) is passed through' '
+    gettext "" > expect &&
+    > actual &&
+    test_cmp expect actual &&
+    printf "This is not a translation string"  > expect
+	gettext "This is not a translation string" > actual &&

Strange indentation and you break the && chain.

-- Hannes