Gettext support for Git
cover Gettext support for Git
This patch series implements gettext support for git, making it possible to localize it.
It been through 8 RFC iterations, gathering lots of changes along the way. I think it's now ready to be submitted for inclusion.
This submission is exactly equivalent to the RFC v8, aside from modifying the commit messages.
Ævar Arnfjörð Bjarmason (2):
Add infrastructure for translating Git with gettext Add initial C, Shell and Perl gettext translations
.gitignore | 2 + INSTALL | 8 ++ Makefile | 69 ++++++++++++++++++- config.mak.in | 2 + configure.ac | 12 +++ daemon.c | 3 + fast-import.c | 3 + gettext.c | 21 ++++++ gettext.h | 18 +++++ git-pull.sh | 16 +++-- git-send-email.perl | 3 +- git-sh-i18n.sh | 47 +++++++++++++ git.c | 3 + http-backend.c | 3 + http-fetch.c | 3 + http-push.c | 3 + imap-send.c | 3 + perl/Git/I18N.pm | 91 +++++++++++++++++++++++++ perl/Makefile | 3 +- perl/Makefile.PL | 14 ++++- po/.gitignore | 1 + po/is.po | 70 +++++++++++++++++++ shell.c | 3 + show-index.c | 3 + t/t0200-gettext.sh | 154 ++++++++++++++++++++++++++++++++++++++++++ t/t0200/test.c | 13 ++++ t/t0200/test.perl | 14 ++++ t/t0200/test.sh | 14 ++++ t/t0201-gettext-fallbacks.sh | 42 +++++++++++ t/t0202-gettext-perl.sh | 20 ++++++ t/t0202/test.pl | 104 ++++++++++++++++++++++++++++ t/test-lib.sh | 2 + upload-pack.c | 3 + wt-status.c | 107 +++++++++++++++-------------- 34 files changed, 812 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/test.c create mode 100644 t/t0200/test.perl create mode 100644 t/t0200/test.sh create mode 100755 t/t0201-gettext-fallbacks.sh create mode 100755 t/t0202-gettext-perl.sh create mode 100644 t/t0202/test.pl
PATCH 1/2 Add infrastructure for translating Git with gettext
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. When using ./configure the autoconf script will auto-detect if the gettext libraries are installed and act appropriately.
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 available. That's a reasonable assumption since then the message catalog wont '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:
All the translated Git utilities are translated under the same textdomain(3) ("git"). This means that translators will see all interface messages under one big namespace, as opposed to e.g. one names per core utility.
Gettext .mo files will be installed and looked for in the standard $(prefix)/share/locale path. GIT_TEXTDOMAINDIR can also be set to override that, but that's only intended to be used to test Git itself.
* Perl:
Perl code that 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.
See <[email protected]> for a further elaboration on this topic.
* Shell:
Shell code that's 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) 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, including Jonathan Nieder, Jakub Narebski, Johannes Sixt, Peter Krefting and others.
--- .gitignore | 2 + INSTALL | 8 +++ Makefile | 69 ++++++++++++++++++++++- config.mak.in | 2 + configure.ac | 12 ++++ daemon.c | 3 + fast-import.c | 3 + gettext.c | 21 +++++++ gettext.h | 18 ++++++ git-sh-i18n.sh | 47 ++++++++++++++++ git.c | 3 + http-backend.c | 3 + http-fetch.c | 3 + http-push.c | 3 + imap-send.c | 3 + perl/Git/I18N.pm | 91 ++++++++++++++++++++++++++++++ perl/Makefile | 3 +- perl/Makefile.PL | 14 ++++- po/.gitignore | 1 + po/is.po | 47 ++++++++++++++++ shell.c | 3 + show-index.c | 3 + t/t0200-gettext.sh | 126 ++++++++++++++++++++++++++++++++++++++++++ t/t0200/test.c | 13 ++++ t/t0200/test.perl | 14 +++++ t/t0200/test.sh | 14 +++++ t/t0201-gettext-fallbacks.sh | 42 ++++++++++++++ t/t0202-gettext-perl.sh | 20 +++++++ t/t0202/test.pl | 104 ++++++++++++++++++++++++++++++++++ t/test-lib.sh | 2 + upload-pack.c | 3 + 31 files changed, 696 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/test.c create mode 100644 t/t0200/test.perl create mode 100644 t/t0200/test.sh create mode 100755 t/t0201-gettext-fallbacks.sh create mode 100755 t/t0202-gettext-perl.sh create mode 100644 t/t0202/test.pl
.gitignore +2 -0
@@ -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/
INSTALL +8 -0
@@ -93,6 +93,14 @@ Issues of note: history graphically, and in git-gui. If you don't want gitk or git-gui, you can use NO_TCLTK. + - The GNU "libintl" library is used by default for localizing + Git. It needs a gettext.h on the system for C code, gettext.sh + for shell scripts, and libintl-perl for Perl programs. + + Set NO_GETTEXT to disable localization support and make Git only + use English. Under autoconf the configure script will do this + automatically if it can't find libintl on the system. + - Some platform specific issues are dealt with Makefile rules, but depending on your specific installation, you may not have all the libraries/tools needed, or you may have
Makefile +67 -2
189 lines not on this page · raw message
config.mak.in +2 -0
@@ -32,9 +32,11 @@ 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@ +NEEDS_LIBINTL=@NEEDS_LIBINTL@ NEEDS_LIBGEN=@NEEDS_LIBGEN@ NO_SYS_SELECT_H=@NO_SYS_SELECT_H@ NO_D_INO_IN_DIRENT=@NO_D_INO_IN_DIRENT@
configure.ac +12 -0
@@ -559,6 +559,12 @@ AC_CHECK_LIB([c], [basename], AC_SUBST(NEEDS_LIBGEN) test -n "$NEEDS_LIBGEN" && LIBS="$LIBS -lgen" +AC_CHECK_LIB([c], [gettext], +[NEEDS_LIBINTL=], +[NEEDS_LIBINTL=YesPlease]) +AC_SUBST(NEEDS_LIBINTL) +test -n "$NEEDS_LIBINTL" && LIBS="$LIBS -lintl" + ## Checks for header files. AC_MSG_NOTICE([CHECKS for header files]) #
@@ -730,6 +736,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=],
daemon.c +3 -0
@@ -3,6 +3,7 @@#include "exec_cmd.h" #include "run-command.h" #include "strbuf.h" +#include "gettext.h" #include <syslog.h>
@@ -974,6 +975,8 @@ int main(int argc, char **argv)gid_t gid =0 ;int i; +git_setup_gettext (); +git_extract_argv0_path (argv[0 ]);for (i =1 ; i < argc; i++) {
fast-import.c +3 -0
@@ -156,6 +156,7 @@ Format of STDIN stream:#include "csum-file.h" #include "quote.h" #include "exec_cmd.h" +#include "gettext.h" #define PACK_ID_BITS 16#define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)
@@ -2904,6 +2905,8 @@ int main(int argc, const char **argv)git_extract_argv0_path (argv[0 ]); +git_setup_gettext (); +if (argc ==2 && !strcmp (argv[1 ],"-h" ))usage (fast_import_usage);
gettext.c new file +21 -0
@@ -0,0 +1,21 @@ +#include "exec_cmd.h" +#include <libintl.h> +#include <stdlib.h> + +extern 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" ); +}
gettext.h new file +18 -0
@@ -0,0 +1,18 @@ +#ifndef GETTEXT_H +#define GETTEXT_H + +#ifdef NO_GETTEXT +static inline void git_setup_gettext (void ) {} +#else +extern void git_setup_gettext (void ); +#endif + +#define N_ (s) (s) +#ifdef NO_GETTEXT +#define _ (s) (s) +#else +#include <libintl.h> +#define _ (s) gettext(s) +#endif + +#endif
git-sh-i18n.sh new file +47 -0
47 lines not on this page · raw message
git.c +3 -0
@@ -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: *
http-backend.c +3 -0
@@ -6,6 +6,7 @@#include "exec_cmd.h" #include "run-command.h" #include "string-list.h" +#include "gettext.h" static const char content_type[] ="Content-Type" ;static const char content_length[] ="Content-Length" ;
@@ -605,6 +606,8 @@ int main(int argc, char **argv)char *cmd_arg =NULL ;int i; +git_setup_gettext (); +git_extract_argv0_path (argv[0 ]);set_die_routine (die_webcgi);
http-fetch.c +3 -0
@@ -2,6 +2,7 @@#include "exec_cmd.h" #include "http.h" #include "walker.h" +#include "gettext.h" static const char http_fetch_usage[] ="git http-fetch " "[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url" ;
@@ -24,6 +25,8 @@ int main(int argc, const char **argv)int get_verbosely =0 ;int get_recover =0 ; +git_setup_gettext (); +git_extract_argv0_path (argv[0 ]);while (arg < argc && argv[arg][0 ] =='-' ) {
http-push.c +3 -0
@@ -10,6 +10,7 @@#include "remote.h" #include "list-objects.h" #include "sigchain.h" +#include "gettext.h" #include <expat.h>
@@ -1791,6 +1792,8 @@ int main(int argc, char **argv)struct remote *remote;char *rewritten_url =NULL ; +git_setup_gettext (); +git_extract_argv0_path (argv[0 ]); repo =xcalloc (sizeof (*repo),1 );
imap-send.c +3 -0
@@ -25,6 +25,7 @@#include "cache.h" #include "exec_cmd.h" #include "run-command.h" +#include "gettext.h" #ifdef NO_OPENSSL typedef void *SSL ;#else
@@ -1535,6 +1536,8 @@ int main(int argc, char **argv)git_extract_argv0_path (argv[0 ]); +git_setup_gettext (); +if (argc !=1 )usage (imap_send_usage);
perl/Git/I18N.pm new file +91 -0
91 lines not on this page · raw message
perl/Makefile +2 -1
@@ -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
@@ -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
@@ -0,0 +1 @@ +/*.pot
po/is.po new file +47 -0
47 lines not on this page · raw message
shell.c +3 -0
@@ -2,6 +2,7 @@#include "quote.h" #include "exec_cmd.h" #include "strbuf.h" +#include "gettext.h" static int do_generic_cmd (const char *me,char *arg) {
@@ -51,6 +52,8 @@ int main(int argc, char **argv)struct commands *cmd;int devnull_fd; +git_setup_gettext (); +/* * Always open file descriptors 0/1/2 to avoid clobbering files * in die(). It also avoids not messing up when the pipes are
show-index.c +3 -0
@@ -1,5 +1,6 @@#include "cache.h" #include "pack.h" +#include "gettext.h" static const char show_index_usage[] ="git show-index < <packed archive index>" ;
@@ -11,6 +12,8 @@ int main(int argc, char **argv)unsigned int version;static unsigned int top_index[256 ]; +git_setup_gettext (); +if (argc !=1 )usage (show_index_usage);if (fread (top_index,2 *4 ,1 , stdin) !=1 )
t/t0200-gettext.sh new file +126 -0
126 lines not on this page · raw message
t/t0200/test.c new file +13 -0
@@ -0,0 +1,13 @@ +/* This is a phony C program that's only here to test xgettext message extraction */ + +const char help[] = +N_ ("See 'git help COMMAND' for more information on a specific command." ); + +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/test.perl new file +14 -0
@@ -0,0 +1,14 @@ +# This is a phony Perl program that's only here to test xgettext +# message extraction + +# so the above comment won't be folded into the next one by xgettext +1; + +# 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/test.sh new file +14 -0
@@ -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-fallbacks.sh new file +42 -0
42 lines not on this page · raw message
t/t0202-gettext-perl.sh new file +20 -0
@@ -0,0 +1,20 @@ +#!/bin/sh + +test_description='Perl gettext interface (Git::I18N)' +. ./test-lib.sh + +if ! test_have_prereq PERL; then + say 'skipping perl interface tests, perl not available' + test_done +fi + +"$PERL_PATH" -MTest::More -e 0 2>/dev/null || { + say "Perl Test::More unavailable, skipping test" + test_done +} + +test_external_without_stderr \ + 'Perl Git::I18N API' \ + "$PERL_PATH" "$TEST_DIRECTORY"/t0202/test.pl + +test_done
t/t0202/test.pl new file +104 -0
104 lines not on this page · raw message
t/test-lib.sh +2 -0
@@ -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
@@ -845,6 +846,7 @@ esac test -z "$NO_PERL" && test_set_prereq PERL test -z "$NO_PYTHON" && test_set_prereq PYTHON +test -z "$NO_GETTEXT" && test_set_prereq GETTEXT # test whether the filesystem supports symbolic links ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
upload-pack.c +3 -0
@@ -10,6 +10,7 @@#include "revision.h" #include "list-objects.h" #include "run-command.h" +#include "gettext.h" static const char upload_pack_usage[] ="git upload-pack [--strict] [--timeout=nn] <dir>" ;
@@ -686,6 +687,8 @@ int main(int argc, char **argv)int i;int strict =0 ; +git_setup_gettext (); +git_extract_argv0_path (argv[0 ]); read_replace_refs =0 ;
Signature · 1 line
1.7.1.243.gda92d6.dirty
Re: [PATCH 1/2] Add infrastructure for translating Git with gettext
Quoted 11 lines · Ævar Arnfjörð Bjarmason
INSTALL +0
-0@@ -93,6 +93,14 @@ Issues of note:history graphically, and in git-gui. If you don't want gitk or git-gui, you can use
NO_TCLTK.
+ - The GNU "libintl" library is used by default for localizing + Git. It needs agettext.hon the system for C code,gettext.sh+ for shell scripts, and libintl-perl for Perl programs.
I think this addresses my concern about mentioning libintl-perl.
Signature · 2 lines
Jakub Narebski Poland
Re: [PATCH 1/2] Add infrastructure for translating Git with gettext
In reply to Ævar Arnfjörð BjarmasonI'm excited to see the work you've done on this.
Quoted 1 line · Ævar Arnfjörð Bjarmason
the message catalog wont 't be installed on the system during make
trivial typo
Jeff
PATCH v2 1/2 Add infrastructure for translating Git with gettext
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. When using ./configure the autoconf script will auto-detect if the gettext libraries are installed and act appropriately.
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 then the message catalog 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 that's 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.
See <[email protected]> for a further elaboration on this topic.
* Shell:
Shell code that's 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) 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, including Jonathan Nieder, Jakub Narebski, Johannes Sixt, Peter Krefting and others.
---
Quoted 4 lines · Jeff Epler
Quoted 1 line · Ęvar Arnfjörš Bjarmason
the message catalog wont 't be installed on the system during make
trivial typo
Thanks for reviewing it. Fixed the commit message typo in this version.
.gitignore | 2 + INSTALL | 8 +++ Makefile | 69 ++++++++++++++++++++++- config.mak.in | 2 + configure.ac | 12 ++++ daemon.c | 3 + fast-import.c | 3 + gettext.c | 21 +++++++ gettext.h | 18 ++++++ git-sh-i18n.sh | 47 ++++++++++++++++ git.c | 3 + http-backend.c | 3 + http-fetch.c | 3 + http-push.c | 3 + imap-send.c | 3 + perl/Git/I18N.pm | 91 ++++++++++++++++++++++++++++++ perl/Makefile | 3 +- perl/Makefile.PL | 14 ++++- po/.gitignore | 1 + po/is.po | 47 ++++++++++++++++ shell.c | 3 + show-index.c | 3 + t/t0200-gettext.sh | 126 ++++++++++++++++++++++++++++++++++++++++++ t/t0200/test.c | 13 ++++ t/t0200/test.perl | 14 +++++ t/t0200/test.sh | 14 +++++ t/t0201-gettext-fallbacks.sh | 42 ++++++++++++++ t/t0202-gettext-perl.sh | 20 +++++++ t/t0202/test.pl | 104 ++++++++++++++++++++++++++++++++++ t/test-lib.sh | 2 + upload-pack.c | 3 + 31 files changed, 696 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/test.c create mode 100644 t/t0200/test.perl create mode 100644 t/t0200/test.sh create mode 100755 t/t0201-gettext-fallbacks.sh create mode 100755 t/t0202-gettext-perl.sh create mode 100644 t/t0202/test.pl
.gitignore +2 -0
@@ -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/
INSTALL +8 -0
@@ -93,6 +93,14 @@ Issues of note: history graphically, and in git-gui. If you don't want gitk or git-gui, you can use NO_TCLTK. + - The GNU "libintl" library is used by default for localizing + Git. It needs a gettext.h on the system for C code, gettext.sh + for shell scripts, and libintl-perl for Perl programs. + + Set NO_GETTEXT to disable localization support and make Git only + use English. Under autoconf the configure script will do this + automatically if it can't find libintl on the system. + - Some platform specific issues are dealt with Makefile rules, but depending on your specific installation, you may not have all the libraries/tools needed, or you may have
Makefile +67 -2
189 lines not on this page · raw message
config.mak.in +2 -0
@@ -32,9 +32,11 @@ 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@ +NEEDS_LIBINTL=@NEEDS_LIBINTL@ NEEDS_LIBGEN=@NEEDS_LIBGEN@ NO_SYS_SELECT_H=@NO_SYS_SELECT_H@ NO_D_INO_IN_DIRENT=@NO_D_INO_IN_DIRENT@
configure.ac +12 -0
@@ -559,6 +559,12 @@ AC_CHECK_LIB([c], [basename], AC_SUBST(NEEDS_LIBGEN) test -n "$NEEDS_LIBGEN" && LIBS="$LIBS -lgen" +AC_CHECK_LIB([c], [gettext], +[NEEDS_LIBINTL=], +[NEEDS_LIBINTL=YesPlease]) +AC_SUBST(NEEDS_LIBINTL) +test -n "$NEEDS_LIBINTL" && LIBS="$LIBS -lintl" + ## Checks for header files. AC_MSG_NOTICE([CHECKS for header files]) #
@@ -730,6 +736,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=],
daemon.c +3 -0
@@ -3,6 +3,7 @@#include "exec_cmd.h" #include "run-command.h" #include "strbuf.h" +#include "gettext.h" #include <syslog.h>
@@ -974,6 +975,8 @@ int main(int argc, char **argv)gid_t gid =0 ;int i; +git_setup_gettext (); +git_extract_argv0_path (argv[0 ]);for (i =1 ; i < argc; i++) {
fast-import.c +3 -0
@@ -156,6 +156,7 @@ Format of STDIN stream:#include "csum-file.h" #include "quote.h" #include "exec_cmd.h" +#include "gettext.h" #define PACK_ID_BITS 16#define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)
@@ -2904,6 +2905,8 @@ int main(int argc, const char **argv)git_extract_argv0_path (argv[0 ]); +git_setup_gettext (); +if (argc ==2 && !strcmp (argv[1 ],"-h" ))usage (fast_import_usage);
gettext.c new file +21 -0
@@ -0,0 +1,21 @@ +#include "exec_cmd.h" +#include <libintl.h> +#include <stdlib.h> + +extern 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" ); +}
gettext.h new file +18 -0
@@ -0,0 +1,18 @@ +#ifndef GETTEXT_H +#define GETTEXT_H + +#ifdef NO_GETTEXT +static inline void git_setup_gettext (void ) {} +#else +extern void git_setup_gettext (void ); +#endif + +#define N_ (s) (s) +#ifdef NO_GETTEXT +#define _ (s) (s) +#else +#include <libintl.h> +#define _ (s) gettext(s) +#endif + +#endif
git-sh-i18n.sh new file +47 -0
47 lines not on this page · raw message
git.c +3 -0
@@ -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: *
http-backend.c +3 -0
@@ -6,6 +6,7 @@#include "exec_cmd.h" #include "run-command.h" #include "string-list.h" +#include "gettext.h" static const char content_type[] ="Content-Type" ;static const char content_length[] ="Content-Length" ;
@@ -605,6 +606,8 @@ int main(int argc, char **argv)char *cmd_arg =NULL ;int i; +git_setup_gettext (); +git_extract_argv0_path (argv[0 ]);set_die_routine (die_webcgi);
http-fetch.c +3 -0
@@ -2,6 +2,7 @@#include "exec_cmd.h" #include "http.h" #include "walker.h" +#include "gettext.h" static const char http_fetch_usage[] ="git http-fetch " "[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url" ;
@@ -24,6 +25,8 @@ int main(int argc, const char **argv)int get_verbosely =0 ;int get_recover =0 ; +git_setup_gettext (); +git_extract_argv0_path (argv[0 ]);while (arg < argc && argv[arg][0 ] =='-' ) {
http-push.c +3 -0
@@ -10,6 +10,7 @@#include "remote.h" #include "list-objects.h" #include "sigchain.h" +#include "gettext.h" #include <expat.h>
@@ -1791,6 +1792,8 @@ int main(int argc, char **argv)struct remote *remote;char *rewritten_url =NULL ; +git_setup_gettext (); +git_extract_argv0_path (argv[0 ]); repo =xcalloc (sizeof (*repo),1 );
imap-send.c +3 -0
@@ -25,6 +25,7 @@#include "cache.h" #include "exec_cmd.h" #include "run-command.h" +#include "gettext.h" #ifdef NO_OPENSSL typedef void *SSL ;#else
@@ -1535,6 +1536,8 @@ int main(int argc, char **argv)git_extract_argv0_path (argv[0 ]); +git_setup_gettext (); +if (argc !=1 )usage (imap_send_usage);
perl/Git/I18N.pm new file +91 -0
91 lines not on this page · raw message
perl/Makefile +2 -1
@@ -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
@@ -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
@@ -0,0 +1 @@ +/*.pot
po/is.po new file +47 -0
47 lines not on this page · raw message
shell.c +3 -0
@@ -2,6 +2,7 @@#include "quote.h" #include "exec_cmd.h" #include "strbuf.h" +#include "gettext.h" static int do_generic_cmd (const char *me,char *arg) {
@@ -51,6 +52,8 @@ int main(int argc, char **argv)struct commands *cmd;int devnull_fd; +git_setup_gettext (); +/* * Always open file descriptors 0/1/2 to avoid clobbering files * in die(). It also avoids not messing up when the pipes are
show-index.c +3 -0
@@ -1,5 +1,6 @@#include "cache.h" #include "pack.h" +#include "gettext.h" static const char show_index_usage[] ="git show-index < <packed archive index>" ;
@@ -11,6 +12,8 @@ int main(int argc, char **argv)unsigned int version;static unsigned int top_index[256 ]; +git_setup_gettext (); +if (argc !=1 )usage (show_index_usage);if (fread (top_index,2 *4 ,1 , stdin) !=1 )
t/t0200-gettext.sh new file +126 -0
126 lines not on this page · raw message
t/t0200/test.c new file +13 -0
@@ -0,0 +1,13 @@ +/* This is a phony C program that's only here to test xgettext message extraction */ + +const char help[] = +N_ ("See 'git help COMMAND' for more information on a specific command." ); + +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/test.perl new file +14 -0
@@ -0,0 +1,14 @@ +# This is a phony Perl program that's only here to test xgettext +# message extraction + +# so the above comment won't be folded into the next one by xgettext +1; + +# 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/test.sh new file +14 -0
@@ -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-fallbacks.sh new file +42 -0
42 lines not on this page · raw message
t/t0202-gettext-perl.sh new file +20 -0
@@ -0,0 +1,20 @@ +#!/bin/sh + +test_description='Perl gettext interface (Git::I18N)' +. ./test-lib.sh + +if ! test_have_prereq PERL; then + say 'skipping perl interface tests, perl not available' + test_done +fi + +"$PERL_PATH" -MTest::More -e 0 2>/dev/null || { + say "Perl Test::More unavailable, skipping test" + test_done +} + +test_external_without_stderr \ + 'Perl Git::I18N API' \ + "$PERL_PATH" "$TEST_DIRECTORY"/t0202/test.pl + +test_done
t/t0202/test.pl new file +104 -0
104 lines not on this page · raw message
t/test-lib.sh +2 -0
@@ -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
@@ -845,6 +846,7 @@ esac test -z "$NO_PERL" && test_set_prereq PERL test -z "$NO_PYTHON" && test_set_prereq PYTHON +test -z "$NO_GETTEXT" && test_set_prereq GETTEXT # test whether the filesystem supports symbolic links ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
upload-pack.c +3 -0
@@ -10,6 +10,7 @@#include "revision.h" #include "list-objects.h" #include "run-command.h" +#include "gettext.h" static const char upload_pack_usage[] ="git upload-pack [--strict] [--timeout=nn] <dir>" ;
@@ -686,6 +687,8 @@ int main(int argc, char **argv)int i;int strict =0 ; +git_setup_gettext (); +git_extract_argv0_path (argv[0 ]); read_replace_refs =0 ;
Signature · 1 line
1.7.1.243.gda92d6.dirty
PATCH 2/2 Add initial C, Shell and Perl gettext translations
In reply to Ævar Arnfjörð BjarmasonChange 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 | 23 +++++++++++ t/t0200-gettext.sh | 28 +++++++++++++ wt-status.c | 107 ++++++++++++++++++++++++++------------------------- 5 files changed, 116 insertions(+), 61 deletions(-)
git-pull.sh +9 -7
@@ -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
@@ -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 +23 -0
@@ -13,6 +13,20 @@ msgstr "" msgid "See git help COMMAND for more information on a specific command." msgstr "Sjá git help SKIPUN til að sjá hjálp fyrir tiltekna skipun." +#: 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/test.c:9 msgid "TEST: A C test string"
@@ -24,6 +38,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/test.sh:8 msgid "TEST: A Shell test string"
@@ -35,6 +53,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" + #. TRANSLATORS: This is a test. You don't need to translate it. #: t/t0200/test.perl:8 msgid "TEST: A Perl test string"
t/t0200-gettext.sh +28 -0
@@ -123,4 +123,32 @@ test_expect_success 'xgettext: Perl extraction with %s' ' test_cmp expect actual ' +# Actually execute some C and Shell code that uses Gettext +test_expect_success 'C: git-status reads our message catalog ' ' + test_commit "some-file" && + git checkout -b test/gettext && + LANGUAGE=C LC_ALL=C git status | grep test/gettext > expect && + echo "# On branch test/gettext" > actual && + test_cmp expect actual && + + LANGUAGE=is LC_ALL=is_IS.UTF-8 git status | grep test/gettext > expect && + echo "# Á greininni test/gettext" > actual && + test_cmp expect actual +' + +test_expect_success 'Shell: git-pull reads our message catalog' ' + # Repository for testing + mkdir parent && + (cd parent && git init && + echo one >file && git add file && + git commit -m one) && + + # Actual test + (cd parent && + (LANGUAGE=C LC_ALL=C git pull --tags "../" >out 2>err); + grep "Fetching tags only" err && + (LANGUAGE=is LC_ALL=is_IS.UTF-8 git pull --tags ../ >out 2>err || :) && + grep "Næ aðeins í" err) +' + test_done
wt-status.c +54 -53
241 lines not on this page · raw message
Signature · 1 line
1.7.1.243.gda92d6.dirty
Re: [PATCH v2 1/2] Add infrastructure for translating Git with gettext
In reply to Ævar Arnfjörð BjarmasonQuoted 6 lines · Ævar Arnfjörð Bjarmason
t/t0200-gettext.sh new file +0
-0
t/t0200-gettext.sh line 63
Quoted 10 lines
t/t0200-gettext.sh new file +9
-0@@ -0,0 +1,126 @@ +test_expect_success 'sanity: No gettext("") data for fantasy locale' ' + LANGUAGE=is LC_ALL=tlh_TLH.UTF-8 gettext "" > real-locale && + test_expect_failure test -s real-locale +' + +test_expect_success 'sanity: Some gettext("") data for real locale' ' + LANGUAGE=is LC_ALL=is_IS.UTF-8 gettext "" > fantasy-locale && + test -s fantasy-locale +'
I am getting an empty output in the fantasy-locale file here.
Besides, the tests above look somewhat wrong. "test_expect_failure" is a top-level construct and the 11th test should read like this instead:
test_expect_success 'sanity: No gettext("") data for fantasy locale' '
LANGUAGE=is LC_ALL=tlh_TLH.UTF-8 gettext "" >fantasy-locale && ! test -s fantasy-locale
'
The test label reads "fantasy" but the test files were named "real"; they should be consistent. Also notice that I fixed the redirection style, too, but that is a minor point.
The full error log up to the first failure on my system is shown below...
+ test_description='Gettext support for Git'
+ . ./test-lib.sh
++ case "$GIT_TEST_TEE_STARTED, $* " in
++ ORIGINAL_TERM=screen
++ LANG=C
++ LC_ALL=C
++ LANGUAGE=C
++ PAGER=cat
++ TZ=UTC
++ TERM=dumb
++ export LANG LC_ALL PAGER TERM TZ
++ EDITOR=:
++ unset VISUAL
++ unset GIT_EDITOR
++ unset AUTHOR_DATE
++ unset AUTHOR_EMAIL
++ unset AUTHOR_NAME
++ unset COMMIT_AUTHOR_EMAIL
++ unset COMMIT_AUTHOR_NAME
++ unset EMAIL
++ unset GIT_ALTERNATE_OBJECT_DIRECTORIES
++ unset GIT_AUTHOR_DATE
++ [email protected]
++ GIT_AUTHOR_NAME='A U Thor'
++ unset GIT_COMMITTER_DATE
++ [email protected]
++ GIT_COMMITTER_NAME='C O Mitter'
++ unset GIT_DIFF_OPTS
++ unset GIT_DIR
++ unset GIT_WORK_TREE
++ unset GIT_EXTERNAL_DIFF
++ unset GIT_INDEX_FILE
++ unset GIT_OBJECT_DIRECTORY
++ unset GIT_CEILING_DIRECTORIES
++ unset SHA1_FILE_DIRECTORIES
++ unset SHA1_FILE_DIRECTORY
++ unset GIT_NOTES_REF
++ unset GIT_NOTES_DISPLAY_REF
++ unset GIT_NOTES_REWRITE_REF
++ unset GIT_NOTES_REWRITE_MODE
++ GIT_MERGE_VERBOSITY=5
++ export GIT_MERGE_VERBOSITY
++ export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
++ export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
++ export EDITOR
++ GIT_TEST_CMP='diff -u'
++ unset CDPATH
++ unset GREP_OPTIONS
++ case $(echo $GIT_TRACE |tr "[A-Z]" "[a-z]") in
+++ echo
+++ tr '[A-Z]' '[a-z]'
++ _x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
++ _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]' ++ '[' xscreen '!=' xdumb ']'
++ TERM=screen
++ export TERM
++ '[' -t 1 ']'
++ test 2 -ne 0
++ case "$1" in
++ immediate=t
++ shift
++ test 1 -ne 0
++ case "$1" in
++ verbose=t
++ shift
++ test 0 -ne 0
++ test -n ''
++ test 'Gettext support for Git' '!=' ''
++ test '' = t
++ exec
++ test t = t
++ exec
++ test_failure=0
++ test_count=0
++ test_fixed=0
++ test_broken=0
++ test_success=0
++ GIT_EXIT_OK=
++ trap die EXIT
++ satisfied=' '
+++ pwd
++ TEST_DIRECTORY=/srv/project/git/git.build/t
++ test -n ''
++ test -n ''
++ git_bin_dir=/srv/project/git/git.build/t/../bin-wrappers
++ test -x /srv/project/git/git.build/t/../bin-wrappers/git
++ PATH=/srv/project/git/git.build/t/../bin-wrappers:/home/junio/g/Debian-5.0.4-x86_64/git-active/bin:/home/junio/bin/Debian-5.0.4-x86_64:/home/junio/bin/common:/usr/local/bin:/sbin:/usr/sbin:/usr/bin:/bin:/usr/games
++ GIT_EXEC_PATH=/srv/project/git/git.build/t/..
++ test -n ''
+++ pwd
++ GIT_TEMPLATE_DIR=/srv/project/git/git.build/t/../templates/blt
++ unset GIT_CONFIG
++ GIT_CONFIG_NOSYSTEM=1
++ GIT_CONFIG_NOGLOBAL=1
++ export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_CONFIG_NOGLOBAL
++ . ../GIT-BUILD-OPTIONS
+++ SHELL_PATH=/bin/sh
+++ PERL_PATH=/usr/bin/perl
+++ TAR=tar
+++ NO_CURL=
+++ NO_PERL=
+++ NO_PYTHON=
+++ NO_GETTEXT=
+++ pwd
+++ pwd
++ GITPERLLIB=/srv/project/git/git.build/t/../perl/blib/lib:/srv/project/git/git.build/t/../perl/blib/arch/auto/Git
++ export GITPERLLIB
++ test -d ../templates/blt
++ test -z ''
++ test -z ''
+++ pwd
++ GITPYTHONLIB=/srv/project/git/git.build/t/../git_remote_helpers/build/lib
++ export GITPYTHONLIB
++ test -d ../git_remote_helpers/build
++ test -x ../test-chmtime
+++ basename t0200-gettext.sh .sh
++ test='trash directory.t0200-gettext'
++ test -n ''
++ case "$test" in
++ TRASH_DIRECTORY='/srv/project/git/git.build/t/trash directory.t0200-gettext'
++ test '!' -z ''
++ remove_trash='/srv/project/git/git.build/t/trash directory.t0200-gettext'
++ rm -fr 'trash directory.t0200-gettext'
++ test_create_repo 'trash directory.t0200-gettext'
++ test 1 = 1
+++ pwd
++ owd=/srv/project/git/git.build/t
++ repo='trash directory.t0200-gettext'
++ mkdir -p 'trash directory.t0200-gettext'
++ cd 'trash directory.t0200-gettext'
++ /srv/project/git/git.build/t/../git-init --template=/srv/project/git/git.build/t/../templates/blt/
Initialized empty Git repository in /srv/project/git/git.build/t/trash directory.t0200-gettext/.git/
++ mv .git/hooks .git/hooks-disabled
++ cd /srv/project/git/git.build/t
++ cd -P 'trash directory.t0200-gettext'
++ this_test=t0200-gettext.sh
++ this_test=t0200
++ case $(uname -s) in
+++ uname -s
++ test_set_prereq POSIXPERM
++ satisfied=' POSIXPERM '
++ test_set_prereq BSLASHPSPEC
++ satisfied=' POSIXPERM BSLASHPSPEC '
++ test_set_prereq EXECKEEPSPID
++ satisfied=' POSIXPERM BSLASHPSPEC EXECKEEPSPID '
++ test -z ''
++ test_set_prereq PERL
++ satisfied=' POSIXPERM BSLASHPSPEC EXECKEEPSPID PERL '
++ test -z ''
++ test_set_prereq PYTHON
++ satisfied=' POSIXPERM BSLASHPSPEC EXECKEEPSPID PERL PYTHON '
++ test -z ''
++ test_set_prereq GETTEXT
++ satisfied=' POSIXPERM BSLASHPSPEC EXECKEEPSPID PERL PYTHON GETTEXT '
++ ln -s x y
++ test -h y
++ test_set_prereq SYMLINKS
++ satisfied=' POSIXPERM BSLASHPSPEC EXECKEEPSPID PERL PYTHON GETTEXT SYMLINKS '
++ rm -f y
+ GIT_TEXTDOMAINDIR=/srv/project/git/git.build/t/../share/locale
+ GIT_PO_PATH=/srv/project/git/git.build/t/../po
+ export GIT_TEXTDOMAINDIR GIT_PO_PATH
+ . /srv/project/git/git.build/t/../git-sh-i18n
++ . gettext.sh
+++ test 'X\t' = 'X\t'
+++ echo=echo
+++ test -z ''
+++ case "$0" in
++ test 0 -eq 0
++ test -z ''
++ TEXTDOMAIN=git
++ export TEXTDOMAIN
++ '[' -z /srv/project/git/git.build/t/../share/locale ']'
++ TEXTDOMAINDIR=/srv/project/git/git.build/t/../share/locale
++ export TEXTDOMAINDIR
+ test_expect_success 'sanity: $TEXTDOMAIN is git' '
test $TEXTDOMAIN = "git"
'
+ test 2 = 3
+ prereq=
+ test 2 = 2
+ test_skip 'sanity: $TEXTDOMAIN is git' '
test $TEXTDOMAIN = "git"
'
+ test_count=1
+ to_skip=
+ test -z ''
+ test -n ''
+ case "$to_skip" in
+ false
+ say 'expecting success:
test $TEXTDOMAIN = "git"
'
+ say_color info 'expecting success:
test $TEXTDOMAIN = "git"
'
+ test -z info
+ shift
+ echo '* expecting success:
test $TEXTDOMAIN = "git"
'
* expecting success:
test $TEXTDOMAIN = "git"
+ test_run_ '
test $TEXTDOMAIN = "git"
'
+ test_cleanup=:
+ eval '
test $TEXTDOMAIN = "git"
'
++ test git = git
+ eval_ret=0
+ eval :
++ :
+ return 0
+ '[' 0 = 0 -a 0 = 0 ']'
+ test_ok_ 'sanity: $TEXTDOMAIN is git'
+ test_success=1
+ say_color '' ' ok 1: sanity: $TEXTDOMAIN is git'
+ test -z ''
+ test -n ''
+ shift
+ echo '* ok 1: sanity: $TEXTDOMAIN is git'
* ok 1: sanity: $TEXTDOMAIN is git
+ echo ''
+ test_have_prereq GETTEXT
+ case $satisfied in
+ : yes, have it
+ test_expect_success 'sanity: $TEXTDOMAINDIR exists without NO_GETTEXT=YesPlease' ' test -d "$TEXTDOMAINDIR" &&
test "$TEXTDOMAINDIR" = "$GIT_TEXTDOMAINDIR"
'
+ test 2 = 3
+ prereq=
+ test 2 = 2
+ test_skip 'sanity: $TEXTDOMAINDIR exists without NO_GETTEXT=YesPlease' ' test -d "$TEXTDOMAINDIR" &&
test "$TEXTDOMAINDIR" = "$GIT_TEXTDOMAINDIR"
'
+ test_count=2
+ to_skip=
+ test -z ''
+ test -n ''
+ case "$to_skip" in
+ false
+ say 'expecting success:
test -d "$TEXTDOMAINDIR" &&
test "$TEXTDOMAINDIR" = "$GIT_TEXTDOMAINDIR"
'
+ say_color info 'expecting success:
test -d "$TEXTDOMAINDIR" &&
test "$TEXTDOMAINDIR" = "$GIT_TEXTDOMAINDIR"
'
+ test -z info
+ shift
+ echo '* expecting success:
test -d "$TEXTDOMAINDIR" &&
test "$TEXTDOMAINDIR" = "$GIT_TEXTDOMAINDIR"
'
* expecting success:
test -d "$TEXTDOMAINDIR" &&
test "$TEXTDOMAINDIR" = "$GIT_TEXTDOMAINDIR"
+ test_run_ '
test -d "$TEXTDOMAINDIR" &&
test "$TEXTDOMAINDIR" = "$GIT_TEXTDOMAINDIR"
'
+ test_cleanup=:
+ eval '
test -d "$TEXTDOMAINDIR" &&
test "$TEXTDOMAINDIR" = "$GIT_TEXTDOMAINDIR"
'
++ test -d /srv/project/git/git.build/t/../share/locale
++ test /srv/project/git/git.build/t/../share/locale = /srv/project/git/git.build/t/../share/locale
+ eval_ret=0
+ eval :
++ :
+ return 0
+ '[' 0 = 0 -a 0 = 0 ']'
+ test_ok_ 'sanity: $TEXTDOMAINDIR exists without NO_GETTEXT=YesPlease'
+ test_success=2
+ say_color '' ' ok 2: sanity: $TEXTDOMAINDIR exists without NO_GETTEXT=YesPlease'
+ test -z ''
+ test -n ''
+ shift
+ echo '* ok 2: sanity: $TEXTDOMAINDIR exists without NO_GETTEXT=YesPlease'
* ok 2: sanity: $TEXTDOMAINDIR exists without NO_GETTEXT=YesPlease
+ echo ''
+ test_expect_success 'sanity: Icelandic locale was compiled' ' test -f "$TEXTDOMAINDIR/is/LC_MESSAGES/git.mo"
'
+ test 2 = 3
+ prereq=
+ test 2 = 2
+ test_skip 'sanity: Icelandic locale was compiled' ' test -f "$TEXTDOMAINDIR/is/LC_MESSAGES/git.mo"
'
+ test_count=3
+ to_skip=
+ test -z ''
+ test -n ''
+ case "$to_skip" in
+ false
+ say 'expecting success:
test -f "$TEXTDOMAINDIR/is/LC_MESSAGES/git.mo"
'
+ say_color info 'expecting success:
test -f "$TEXTDOMAINDIR/is/LC_MESSAGES/git.mo"
'
+ test -z info
+ shift
+ echo '* expecting success:
test -f "$TEXTDOMAINDIR/is/LC_MESSAGES/git.mo"
'
* expecting success:
test -f "$TEXTDOMAINDIR/is/LC_MESSAGES/git.mo"
+ test_run_ '
test -f "$TEXTDOMAINDIR/is/LC_MESSAGES/git.mo"
'
+ test_cleanup=:
+ eval '
test -f "$TEXTDOMAINDIR/is/LC_MESSAGES/git.mo"
'
++ test -f /srv/project/git/git.build/t/../share/locale/is/LC_MESSAGES/git.mo
+ eval_ret=0
+ eval :
++ :
+ return 0
+ '[' 0 = 0 -a 0 = 0 ']'
+ test_ok_ 'sanity: Icelandic locale was compiled'
+ test_success=3
+ say_color '' ' ok 3: sanity: Icelandic locale was compiled'
+ test -z ''
+ test -n ''
+ shift
+ echo '* ok 3: sanity: Icelandic locale was compiled'
* ok 3: sanity: Icelandic locale was compiled
+ echo ''
+ test_expect_success 'xgettext: Perl _() strings are not extracted' ' test_expect_failure grep "A Perl string xgettext will not get" "$GIT_PO_PATH"/is.po
'
+ test 2 = 3
+ prereq=
+ test 2 = 2
+ test_skip 'xgettext: Perl _() strings are not extracted' ' test_expect_failure grep "A Perl string xgettext will not get" "$GIT_PO_PATH"/is.po
'
+ test_count=4
+ to_skip=
+ test -z ''
+ test -n ''
+ case "$to_skip" in
+ false
+ say 'expecting success:
test_expect_failure grep "A Perl string xgettext will not get" "$GIT_PO_PATH"/is.po
'
+ say_color info 'expecting success:
test_expect_failure grep "A Perl string xgettext will not get" "$GIT_PO_PATH"/is.po
'
+ test -z info
+ shift
+ echo '* expecting success:
test_expect_failure grep "A Perl string xgettext will not get" "$GIT_PO_PATH"/is.po
'
* expecting success:
test_expect_failure grep "A Perl string xgettext will not get" "$GIT_PO_PATH"/is.po
+ test_run_ '
test_expect_failure grep "A Perl string xgettext will not get" "$GIT_PO_PATH"/is.po
'
+ test_cleanup=:
+ eval '
test_expect_failure grep "A Perl string xgettext will not get" "$GIT_PO_PATH"/is.po
'
++ test_expect_failure grep 'A Perl string xgettext will not get' /srv/project/git/git.build/t/../po/is.po ++ test 3 = 3
++ prereq=grep
++ shift
++ test 2 = 2
++ test_skip 'A Perl string xgettext will not get' /srv/project/git/git.build/t/../po/is.po ++ test_count=5
++ to_skip=
++ test -z ''
++ test -n grep
++ test_have_prereq grep
++ case $satisfied in
++ : nope
++ to_skip=t
++ case "$to_skip" in
++ say_color skip 'skipping test: A Perl string xgettext will not get' /srv/project/git/git.build/t/../po/is.po ++ test -z skip
++ shift
++ echo '* skipping test: A Perl string xgettext will not get /srv/project/git/git.build/t/../po/is.po'
* skipping test: A Perl string xgettext will not get /srv/project/git/git.build/t/../po/is.po ++ say_color skip 'skip 5: A Perl string xgettext will not get'
++ test -z skip
++ shift
++ echo '* skip 5: A Perl string xgettext will not get'
* skip 5: A Perl string xgettext will not get
++ : true
++ echo ''
+ eval_ret=0
+ eval :
++ :
+ return 0
+ '[' 0 = 0 -a 0 = 0 ']'
+ test_ok_ 'xgettext: Perl _() strings are not extracted'
+ test_success=4
+ say_color '' ' ok 5: xgettext: Perl _() strings are not extracted'
+ test -z ''
+ test -n ''
+ shift
+ echo '* ok 5: xgettext: Perl _() strings are not extracted'
* ok 5: xgettext: Perl _() strings are not extracted
+ echo ''
+ test_expect_success 'xgettext: Comment extraction with --add-comments' '
grep "TRANSLATORS: This is a test" "$TEST_DIRECTORY"/t0200/* | wc -l > expect &&
grep "TRANSLATORS: This is a test" "$GIT_PO_PATH"/is.po | wc -l > actual &&
test_cmp expect actual'
+ test 2 = 3
+ prereq=
+ test 2 = 2
+ test_skip 'xgettext: Comment extraction with --add-comments' '
grep "TRANSLATORS: This is a test" "$TEST_DIRECTORY"/t0200/* | wc -l > expect &&
grep "TRANSLATORS: This is a test" "$GIT_PO_PATH"/is.po | wc -l > actual &&
test_cmp expect actual'
+ test_count=6
+ to_skip=
+ test -z ''
+ test -n ''
+ case "$to_skip" in
+ false
+ say 'expecting success:
grep "TRANSLATORS: This is a test" "$TEST_DIRECTORY"/t0200/* | wc -l > expect &&
grep "TRANSLATORS: This is a test" "$GIT_PO_PATH"/is.po | wc -l > actual &&
test_cmp expect actual
'
+ say_color info 'expecting success:
grep "TRANSLATORS: This is a test" "$TEST_DIRECTORY"/t0200/* | wc -l > expect &&
grep "TRANSLATORS: This is a test" "$GIT_PO_PATH"/is.po | wc -l > actual &&
test_cmp expect actual'
+ test -z info
+ shift
+ echo '* expecting success:
grep "TRANSLATORS: This is a test" "$TEST_DIRECTORY"/t0200/* | wc -l > expect &&
grep "TRANSLATORS: This is a test" "$GIT_PO_PATH"/is.po | wc -l > actual &&
test_cmp expect actual
'
* expecting success:
grep "TRANSLATORS: This is a test" "$TEST_DIRECTORY"/t0200/* | wc -l > expect &&
grep "TRANSLATORS: This is a test" "$GIT_PO_PATH"/is.po | wc -l > actual &&
test_cmp expect actual+ test_run_ '
grep "TRANSLATORS: This is a test" "$TEST_DIRECTORY"/t0200/* | wc -l > expect &&
grep "TRANSLATORS: This is a test" "$GIT_PO_PATH"/is.po | wc -l > actual &&
test_cmp expect actual
'
+ test_cleanup=:
+ eval '
grep "TRANSLATORS: This is a test" "$TEST_DIRECTORY"/t0200/* | wc -l > expect &&
grep "TRANSLATORS: This is a test" "$GIT_PO_PATH"/is.po | wc -l > actual &&
test_cmp expect actual'
++ wc -l
++ grep 'TRANSLATORS: This is a test' /srv/project/git/git.build/t/t0200/test.c /srv/project/git/git.build/t/t0200/test.perl /srv/project/git/git.build/t/t0200/test.sh ++ grep 'TRANSLATORS: This is a test' /srv/project/git/git.build/t/../po/is.po
++ wc -l
++ test_cmp expect actual
++ diff -u expect actual
+ eval_ret=0
+ eval :
++ :
+ return 0
+ '[' 0 = 0 -a 0 = 0 ']'
+ test_ok_ 'xgettext: Comment extraction with --add-comments'
+ test_success=5
+ say_color '' ' ok 6: xgettext: Comment extraction with --add-comments'
+ test -z ''
+ test -n ''
+ shift
+ echo '* ok 6: xgettext: Comment extraction with --add-comments'
* ok 6: xgettext: Comment extraction with --add-comments
+ echo ''
+ test_expect_success 'xgettext: Comment extraction with --add-comments stops at statements' ' test_expect_failure grep "This is a phony" "$GIT_PO_PATH"/is.po && test_expect_failure grep "the above comment" "$GIT_PO_PATH"/is.po
'
+ test 2 = 3
+ prereq=
+ test 2 = 2
+ test_skip 'xgettext: Comment extraction with --add-comments stops at statements' ' test_expect_failure grep "This is a phony" "$GIT_PO_PATH"/is.po && test_expect_failure grep "the above comment" "$GIT_PO_PATH"/is.po
'
+ test_count=7
+ to_skip=
+ test -z ''
+ test -n ''
+ case "$to_skip" in
+ false
+ say 'expecting success:
test_expect_failure grep "This is a phony" "$GIT_PO_PATH"/is.po && test_expect_failure grep "the above comment" "$GIT_PO_PATH"/is.po
'
+ say_color info 'expecting success:
test_expect_failure grep "This is a phony" "$GIT_PO_PATH"/is.po && test_expect_failure grep "the above comment" "$GIT_PO_PATH"/is.po
'
+ test -z info
+ shift
+ echo '* expecting success:
test_expect_failure grep "This is a phony" "$GIT_PO_PATH"/is.po && test_expect_failure grep "the above comment" "$GIT_PO_PATH"/is.po
'
* expecting success:
test_expect_failure grep "This is a phony" "$GIT_PO_PATH"/is.po && test_expect_failure grep "the above comment" "$GIT_PO_PATH"/is.po
+ test_run_ '
test_expect_failure grep "This is a phony" "$GIT_PO_PATH"/is.po && test_expect_failure grep "the above comment" "$GIT_PO_PATH"/is.po
'
+ test_cleanup=:
+ eval '
test_expect_failure grep "This is a phony" "$GIT_PO_PATH"/is.po && test_expect_failure grep "the above comment" "$GIT_PO_PATH"/is.po
'
++ test_expect_failure grep 'This is a phony' /srv/project/git/git.build/t/../po/is.po ++ test 3 = 3
++ prereq=grep
++ shift
++ test 2 = 2
++ test_skip 'This is a phony' /srv/project/git/git.build/t/../po/is.po
++ test_count=8
++ to_skip=
++ test -z ''
++ test -n grep
++ test_have_prereq grep
++ case $satisfied in
++ : nope
++ to_skip=t
++ case "$to_skip" in
++ say_color skip 'skipping test: This is a phony' /srv/project/git/git.build/t/../po/is.po ++ test -z skip
++ shift
++ echo '* skipping test: This is a phony /srv/project/git/git.build/t/../po/is.po'
* skipping test: This is a phony /srv/project/git/git.build/t/../po/is.po
++ say_color skip 'skip 8: This is a phony'
++ test -z skip
++ shift
++ echo '* skip 8: This is a phony'
* skip 8: This is a phony
++ : true
++ echo ''
++ test_expect_failure grep 'the above comment' /srv/project/git/git.build/t/../po/is.po ++ test 3 = 3
++ prereq=grep
++ shift
++ test 2 = 2
++ test_skip 'the above comment' /srv/project/git/git.build/t/../po/is.po
++ test_count=9
++ to_skip=
++ test -z ''
++ test -n grep
++ test_have_prereq grep
++ case $satisfied in
++ : nope
++ to_skip=t
++ case "$to_skip" in
++ say_color skip 'skipping test: the above comment' /srv/project/git/git.build/t/../po/is.po ++ test -z skip
++ shift
++ echo '* skipping test: the above comment /srv/project/git/git.build/t/../po/is.po'
* skipping test: the above comment /srv/project/git/git.build/t/../po/is.po
++ say_color skip 'skip 9: the above comment'
++ test -z skip
++ shift
++ echo '* skip 9: the above comment'
* skip 9: the above comment
++ : true
++ echo ''
+ eval_ret=0
+ eval :
++ :
+ return 0
+ '[' 0 = 0 -a 0 = 0 ']'
+ test_ok_ 'xgettext: Comment extraction with --add-comments stops at statements'
+ test_success=6
+ say_color '' ' ok 9: xgettext: Comment extraction with --add-comments stops at statements'
+ test -z ''
+ test -n ''
+ shift
+ echo '* ok 9: xgettext: Comment extraction with --add-comments stops at statements'
* ok 9: xgettext: Comment extraction with --add-comments stops at statements
+ echo ''
+ test_have_prereq GETTEXT
+ case $satisfied in
+ : yes, have it
+ test_expect_success 'sanity: No gettext("") data for fantasy locale' ' LANGUAGE=is LC_ALL=tlh_TLH.UTF-8 gettext "" > real-locale && test_expect_failure test -s real-locale
'
+ test 2 = 3
+ prereq=
+ test 2 = 2
+ test_skip 'sanity: No gettext("") data for fantasy locale' ' LANGUAGE=is LC_ALL=tlh_TLH.UTF-8 gettext "" > real-locale && test_expect_failure test -s real-locale
'
+ test_count=10
+ to_skip=
+ test -z ''
+ test -n ''
+ case "$to_skip" in
+ false
+ say 'expecting success:
LANGUAGE=is LC_ALL=tlh_TLH.UTF-8 gettext "" > real-locale && test_expect_failure test -s real-locale
'
+ say_color info 'expecting success:
LANGUAGE=is LC_ALL=tlh_TLH.UTF-8 gettext "" > real-locale && test_expect_failure test -s real-locale
'
+ test -z info
+ shift
+ echo '* expecting success:
LANGUAGE=is LC_ALL=tlh_TLH.UTF-8 gettext "" > real-locale && test_expect_failure test -s real-locale
'
* expecting success:
LANGUAGE=is LC_ALL=tlh_TLH.UTF-8 gettext "" > real-locale && test_expect_failure test -s real-locale
+ test_run_ '
LANGUAGE=is LC_ALL=tlh_TLH.UTF-8 gettext "" > real-locale && test_expect_failure test -s real-locale
'
+ test_cleanup=:
+ eval '
LANGUAGE=is LC_ALL=tlh_TLH.UTF-8 gettext "" > real-locale && test_expect_failure test -s real-locale
'
++ LANGUAGE=is
++ LC_ALL=tlh_TLH.UTF-8
++ gettext ''
++ test_expect_failure test -s real-locale
++ test 3 = 3
++ prereq=test
++ shift
++ test 2 = 2
++ test_skip -s real-locale
++ test_count=11
++ to_skip=
++ test -z ''
++ test -n test
++ test_have_prereq test
++ case $satisfied in
++ : nope
++ to_skip=t
++ case "$to_skip" in
++ say_color skip 'skipping test: -s' real-locale
++ test -z skip
++ shift
++ echo '* skipping test: -s real-locale'
* skipping test: -s real-locale
++ say_color skip 'skip 11: -s'
++ test -z skip
++ shift
++ echo '* skip 11: -s'
* skip 11: -s
++ : true
++ echo ''
+ eval_ret=0
+ eval :
++ :
+ return 0
+ '[' 0 = 0 -a 0 = 0 ']'
+ test_ok_ 'sanity: No gettext("") data for fantasy locale'
+ test_success=7
+ say_color '' ' ok 11: sanity: No gettext("") data for fantasy locale'
+ test -z ''
+ test -n ''
+ shift
+ echo '* ok 11: sanity: No gettext("") data for fantasy locale'
* ok 11: sanity: No gettext("") data for fantasy locale
+ echo ''
+ test_expect_success 'sanity: Some gettext("") data for real locale' ' LANGUAGE=is LC_ALL=is_IS.UTF-8 gettext "" > fantasy-locale && test -s fantasy-locale
'
+ test 2 = 3
+ prereq=
+ test 2 = 2
+ test_skip 'sanity: Some gettext("") data for real locale' ' LANGUAGE=is LC_ALL=is_IS.UTF-8 gettext "" > fantasy-locale && test -s fantasy-locale
'
+ test_count=12
+ to_skip=
+ test -z ''
+ test -n ''
+ case "$to_skip" in
+ false
+ say 'expecting success:
LANGUAGE=is LC_ALL=is_IS.UTF-8 gettext "" > fantasy-locale && test -s fantasy-locale
'
+ say_color info 'expecting success:
LANGUAGE=is LC_ALL=is_IS.UTF-8 gettext "" > fantasy-locale && test -s fantasy-locale
'
+ test -z info
+ shift
+ echo '* expecting success:
LANGUAGE=is LC_ALL=is_IS.UTF-8 gettext "" > fantasy-locale && test -s fantasy-locale
'
* expecting success:
LANGUAGE=is LC_ALL=is_IS.UTF-8 gettext "" > fantasy-locale && test -s fantasy-locale
+ test_run_ '
LANGUAGE=is LC_ALL=is_IS.UTF-8 gettext "" > fantasy-locale && test -s fantasy-locale
'
+ test_cleanup=:
+ eval '
LANGUAGE=is LC_ALL=is_IS.UTF-8 gettext "" > fantasy-locale && test -s fantasy-locale
'
++ LANGUAGE=is
++ LC_ALL=is_IS.UTF-8
++ gettext ''
++ test -s fantasy-locale
+ eval_ret=1
+ eval :
++ :
+ return 0
+ '[' 0 = 0 -a 1 = 0 ']'
+ test_failure_ 'sanity: Some gettext("") data for real locale' ' LANGUAGE=is LC_ALL=is_IS.UTF-8 gettext "" > fantasy-locale && test -s fantasy-locale
'
+ test_failure=1
+ say_color error 'FAIL 12: sanity: Some gettext("") data for real locale'
+ test -z error
+ shift
+ echo '* FAIL 12: sanity: Some gettext("") data for real locale'
* FAIL 12: sanity: Some gettext("") data for real locale
+ shift
+ echo '
LANGUAGE=is LC_ALL=is_IS.UTF-8 gettext "" > fantasy-locale && test -s fantasy-locale
'
+ sed -e 's/^/ /'
LANGUAGE=is LC_ALL=is_IS.UTF-8 gettext "" > fantasy-locale && test -s fantasy-locale
+ test t = ''
+ GIT_EXIT_OK=t
+ exit 1
+ die
+ code=1
+ test -n t
+ exit 1
v3 cover Gettext support for Git
This patch series implements gettext support for git, making it possible to localize it. This should really be v2, but PATCH 1/2 had a trivial typo fix as v2, so I'm bumping the version of the whole series to v3 to avoid dual v3/v2 confusion.
Changes since v1:
* Fixed all the things that Junio pointed out:
- Tests that are too fragile to run everywhere (depend on locale/OS/implementation combinations) are now skipped unless TEST_GIT_GETTEXT_EXHAUSTIVE=1 is set.
- fantasy-locale / real-locale filenames now make sense with respect to their tests.
- Use ! test' instead of test_expect_failure test`
- Use the >foo' redirection style instead of > foo'.
* Don't use . gettext.sh' but type gettext.sh && . gettext.sh'.
The former failed on dash and Solaris's ksh.
* Now compatible with the SunOS gettext implmentation, this needed:
- #include <locale.h> in gettext.c, which is a good idea anyway. GNU libintl.h included it indirectly.
- Define a Shell fallback that uses gettext(1). SunOS doesn't have gettext.sh, but it has a gettext command that shellscipts should use. It also needed a custom eval_gettext() wrapper.
- Updating of INSTALL and Makefile docs to mention this.
* The Perl tests can now be run with TEST_GIT_GETTEXT_EXHAUSTIVE=1 through the t0202-gettext-perl.sh wrapper. The original patch didn't set GIT_TEXTDOMAINDIR, and I always ran the test.pl script manually.
* Updated commit messages to reflect the changes above, and fixed a typo or two.
The changes since v1 in diff -w --stat format:
INSTALL | 10 ++++-- Makefile | 4 +- gettext.c | 1 + git-sh-i18n.sh | 36 ++++++++++++++++++---- t/t0200-gettext.sh | 68 ++++++++++++++++++++++++----------------- t/t0201-gettext-fallbacks.sh | 10 +++++- t/t0202-gettext-perl.sh | 3 ++ t/t0202/test.pl | 4 +- 8 files changed, 94 insertions(+), 42 deletions(-)
Ævar Arnfjörð Bjarmason (2):
Add infrastructure for translating Git with gettext Add initial C, Shell and Perl gettext translations
.gitignore | 2 + INSTALL | 8 ++ Makefile | 69 +++++++++++++++++- config.mak.in | 2 + configure.ac | 12 +++ daemon.c | 3 + fast-import.c | 3 + gettext.c | 22 ++++++ gettext.h | 18 +++++ git-pull.sh | 16 ++-- git-send-email.perl | 3 +- git-sh-i18n.sh | 71 ++++++++++++++++++ git.c | 3 + http-backend.c | 3 + http-fetch.c | 3 + http-push.c | 3 + imap-send.c | 3 + perl/Git/I18N.pm | 91 +++++++++++++++++++++++ perl/Makefile | 3 +- perl/Makefile.PL | 14 +++- po/.gitignore | 1 + po/is.po | 70 ++++++++++++++++++ shell.c | 3 + show-index.c | 3 + t/t0200-gettext.sh | 166 ++++++++++++++++++++++++++++++++++++++++++ t/t0200/test.c | 13 +++ t/t0200/test.perl | 14 ++++ t/t0200/test.sh | 14 ++++ t/t0201-gettext-fallbacks.sh | 50 +++++++++++++ t/t0202-gettext-perl.sh | 23 ++++++ t/t0202/test.pl | 104 ++++++++++++++++++++++++++ t/test-lib.sh | 2 + upload-pack.c | 3 + wt-status.c | 107 ++++++++++++++------------- 34 files changed, 860 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/test.c create mode 100644 t/t0200/test.perl create mode 100644 t/t0200/test.sh create mode 100755 t/t0201-gettext-fallbacks.sh create mode 100755 t/t0202-gettext-perl.sh create mode 100644 t/t0202/test.pl
PATCH v3 1/2 Add infrastructure for translating Git with gettext
In reply to Junio C HamanoAll 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 or SunOS 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. When using ./configure the autoconf script will auto-detect if the gettext libraries are installed and act appropriately.
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 available. That's a reasonable assumption since then the message catalog 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 that's 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.
See <[email protected]> for a further elaboration on this topic.
* Shell:
Shell code that's 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 gettext(1) if it's available. The latter is available without the former on Solaris, which has its own non-GNU gettext implementation. We also need to emulate eval_gettext() there.
If neither are present we'll use a dumb printf(1) fall-through wrapper.
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, and unlikely to ever do so.
This series has been tested by me on Ubuntu 10.04, Debian testing, FreeBSD 8.1 and SunOS 5.10, and by others on Mac OS X 10.6.3 (with Xcode 3.2.2) and openSUSE Factory (11.3, milestone 7).
SunOS has its own non-GNU gettext implementation which this patch supports, although that may change in the future if it turns out that we need some GNU libintl features that SunOS doesn't provide.
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, including Jonathan Nieder, Jakub Narebski, Johannes Sixt, Peter Krefting, Junio C Hamano, Thomas Rast and others.
--- .gitignore | 2 + INSTALL | 12 ++++ Makefile | 69 ++++++++++++++++++++- config.mak.in | 2 + configure.ac | 12 ++++ daemon.c | 3 + fast-import.c | 3 + gettext.c | 22 +++++++ gettext.h | 18 ++++++ git-sh-i18n.sh | 71 ++++++++++++++++++++++ git.c | 3 + http-backend.c | 3 + http-fetch.c | 3 + http-push.c | 3 + imap-send.c | 3 + perl/Git/I18N.pm | 91 ++++++++++++++++++++++++++++ perl/Makefile | 3 +- perl/Makefile.PL | 14 ++++- po/.gitignore | 1 + po/is.po | 47 ++++++++++++++ shell.c | 3 + show-index.c | 3 + t/t0200-gettext.sh | 137 ++++++++++++++++++++++++++++++++++++++++++ t/t0200/test.c | 13 ++++ t/t0200/test.perl | 14 ++++ t/t0200/test.sh | 14 ++++ t/t0201-gettext-fallbacks.sh | 50 +++++++++++++++ t/t0202-gettext-perl.sh | 23 +++++++ t/t0202/test.pl | 104 ++++++++++++++++++++++++++++++++ t/test-lib.sh | 2 + upload-pack.c | 3 + 31 files changed, 747 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/test.c create mode 100644 t/t0200/test.perl create mode 100644 t/t0200/test.sh create mode 100755 t/t0201-gettext-fallbacks.sh create mode 100755 t/t0202-gettext-perl.sh create mode 100644 t/t0202/test.pl
.gitignore +2 -0
@@ -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/
INSTALL +12 -0
@@ -93,6 +93,18 @@ Issues of note: history graphically, and in git-gui. If you don't want gitk or git-gui, you can use NO_TCLTK. + - A gettext library is used by default for localizing Git. The + primary target is GNU libintl, but the Solaris gettext + implementation also works. + + We need a gettext.h on the system for C code, gettext.sh (or + Solaris gettext(1)) for shell scripts, and libintl-perl for Perl + programs. + + Set NO_GETTEXT to disable localization support and make Git only + use English. Under autoconf the configure script will do this + automatically if it can't find libintl on the system. + - Some platform specific issues are dealt with Makefile rules, but depending on your specific installation, you may not have all the libraries/tools needed, or you may have
Makefile +67 -2
189 lines not on this page · raw message
config.mak.in +2 -0
@@ -32,9 +32,11 @@ 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@ +NEEDS_LIBINTL=@NEEDS_LIBINTL@ NEEDS_LIBGEN=@NEEDS_LIBGEN@ NO_SYS_SELECT_H=@NO_SYS_SELECT_H@ NO_D_INO_IN_DIRENT=@NO_D_INO_IN_DIRENT@
configure.ac +12 -0
@@ -559,6 +559,12 @@ AC_CHECK_LIB([c], [basename], AC_SUBST(NEEDS_LIBGEN) test -n "$NEEDS_LIBGEN" && LIBS="$LIBS -lgen" +AC_CHECK_LIB([c], [gettext], +[NEEDS_LIBINTL=], +[NEEDS_LIBINTL=YesPlease]) +AC_SUBST(NEEDS_LIBINTL) +test -n "$NEEDS_LIBINTL" && LIBS="$LIBS -lintl" + ## Checks for header files. AC_MSG_NOTICE([CHECKS for header files]) #
@@ -730,6 +736,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=],
daemon.c +3 -0
@@ -3,6 +3,7 @@#include "exec_cmd.h" #include "run-command.h" #include "strbuf.h" +#include "gettext.h" #include <syslog.h>
@@ -974,6 +975,8 @@ int main(int argc, char **argv)gid_t gid =0 ;int i; +git_setup_gettext (); +git_extract_argv0_path (argv[0 ]);for (i =1 ; i < argc; i++) {
fast-import.c +3 -0
@@ -156,6 +156,7 @@ Format of STDIN stream:#include "csum-file.h" #include "quote.h" #include "exec_cmd.h" +#include "gettext.h" #define PACK_ID_BITS 16#define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)
@@ -2904,6 +2905,8 @@ int main(int argc, const char **argv)git_extract_argv0_path (argv[0 ]); +git_setup_gettext (); +if (argc ==2 && !strcmp (argv[1 ],"-h" ))usage (fast_import_usage);
gettext.c new file +22 -0
@@ -0,0 +1,22 @@ +#include "exec_cmd.h" +#include <locale.h> +#include <libintl.h> +#include <stdlib.h> + +extern 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" ); +}
gettext.h new file +18 -0
@@ -0,0 +1,18 @@ +#ifndef GETTEXT_H +#define GETTEXT_H + +#ifdef NO_GETTEXT +static inline void git_setup_gettext (void ) {} +#else +extern void git_setup_gettext (void ); +#endif + +#define N_ (s) (s) +#ifdef NO_GETTEXT +#define _ (s) (s) +#else +#include <libintl.h> +#define _ (s) gettext(s) +#endif + +#endif
git-sh-i18n.sh new file +71 -0
71 lines not on this page · raw message
git.c +3 -0
@@ -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: *
http-backend.c +3 -0
@@ -6,6 +6,7 @@#include "exec_cmd.h" #include "run-command.h" #include "string-list.h" +#include "gettext.h" static const char content_type[] ="Content-Type" ;static const char content_length[] ="Content-Length" ;
@@ -605,6 +606,8 @@ int main(int argc, char **argv)char *cmd_arg =NULL ;int i; +git_setup_gettext (); +git_extract_argv0_path (argv[0 ]);set_die_routine (die_webcgi);
http-fetch.c +3 -0
@@ -2,6 +2,7 @@#include "exec_cmd.h" #include "http.h" #include "walker.h" +#include "gettext.h" static const char http_fetch_usage[] ="git http-fetch " "[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url" ;
@@ -24,6 +25,8 @@ int main(int argc, const char **argv)int get_verbosely =0 ;int get_recover =0 ; +git_setup_gettext (); +git_extract_argv0_path (argv[0 ]);while (arg < argc && argv[arg][0 ] =='-' ) {
http-push.c +3 -0
@@ -10,6 +10,7 @@#include "remote.h" #include "list-objects.h" #include "sigchain.h" +#include "gettext.h" #include <expat.h>
@@ -1791,6 +1792,8 @@ int main(int argc, char **argv)struct remote *remote;char *rewritten_url =NULL ; +git_setup_gettext (); +git_extract_argv0_path (argv[0 ]); repo =xcalloc (sizeof (*repo),1 );
imap-send.c +3 -0
@@ -25,6 +25,7 @@#include "cache.h" #include "exec_cmd.h" #include "run-command.h" +#include "gettext.h" #ifdef NO_OPENSSL typedef void *SSL ;#else
@@ -1535,6 +1536,8 @@ int main(int argc, char **argv)git_extract_argv0_path (argv[0 ]); +git_setup_gettext (); +if (argc !=1 )usage (imap_send_usage);
perl/Git/I18N.pm new file +91 -0
91 lines not on this page · raw message
perl/Makefile +2 -1
@@ -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
@@ -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
@@ -0,0 +1 @@ +/*.pot
po/is.po new file +47 -0
47 lines not on this page · raw message
shell.c +3 -0
@@ -2,6 +2,7 @@#include "quote.h" #include "exec_cmd.h" #include "strbuf.h" +#include "gettext.h" static int do_generic_cmd (const char *me,char *arg) {
@@ -51,6 +52,8 @@ int main(int argc, char **argv)struct commands *cmd;int devnull_fd; +git_setup_gettext (); +/* * Always open file descriptors 0/1/2 to avoid clobbering files * in die(). It also avoids not messing up when the pipes are
show-index.c +3 -0
@@ -1,5 +1,6 @@#include "cache.h" #include "pack.h" +#include "gettext.h" static const char show_index_usage[] ="git show-index < <packed archive index>" ;
@@ -11,6 +12,8 @@ int main(int argc, char **argv)unsigned int version;static unsigned int top_index[256 ]; +git_setup_gettext (); +if (argc !=1 )usage (show_index_usage);if (fread (top_index,2 *4 ,1 , stdin) !=1 )
t/t0200-gettext.sh new file +137 -0
137 lines not on this page · raw message
t/t0200/test.c new file +13 -0
@@ -0,0 +1,13 @@ +/* This is a phony C program that's only here to test xgettext message extraction */ + +const char help[] = +N_ ("See 'git help COMMAND' for more information on a specific command." ); + +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/test.perl new file +14 -0
@@ -0,0 +1,14 @@ +# This is a phony Perl program that's only here to test xgettext +# message extraction + +# so the above comment won't be folded into the next one by xgettext +1; + +# 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/test.sh new file +14 -0
@@ -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-fallbacks.sh new file +50 -0
50 lines not on this page · raw message
t/t0202-gettext-perl.sh new file +23 -0
@@ -0,0 +1,23 @@ +#!/bin/sh + +test_description='Perl gettext interface (Git::I18N)' +. ./test-lib.sh + +GIT_TEXTDOMAINDIR="$GIT_EXEC_PATH/share/locale" +export GIT_TEXTDOMAINDIR + +if ! test_have_prereq PERL; then + say 'skipping perl interface tests, perl not available' + test_done +fi + +"$PERL_PATH" -MTest::More -e 0 2>/dev/null || { + say "Perl Test::More unavailable, skipping test" + test_done +} + +test_external_without_stderr \ + 'Perl Git::I18N API' \ + "$PERL_PATH" "$TEST_DIRECTORY"/t0202/test.pl + +test_done
t/t0202/test.pl new file +104 -0
104 lines not on this page · raw message
t/test-lib.sh +2 -0
@@ -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
@@ -845,6 +846,7 @@ esac test -z "$NO_PERL" && test_set_prereq PERL test -z "$NO_PYTHON" && test_set_prereq PYTHON +test -z "$NO_GETTEXT" && test_set_prereq GETTEXT # test whether the filesystem supports symbolic links ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
upload-pack.c +3 -0
@@ -10,6 +10,7 @@#include "revision.h" #include "list-objects.h" #include "run-command.h" +#include "gettext.h" static const char upload_pack_usage[] ="git upload-pack [--strict] [--timeout=nn] <dir>" ;
@@ -686,6 +687,8 @@ int main(int argc, char **argv)int i;int strict =0 ; +git_setup_gettext (); +git_extract_argv0_path (argv[0 ]); read_replace_refs =0 ;
Signature · 1 line
1.7.1.251.g92a7
PATCH v3 2/2 Add initial C, Shell and Perl gettext translations
In reply to Junio C HamanoChange 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.
The new tests are only run under TEST_GIT_I18N_EXHAUSTIVE=1, since they might fail if the host OS doesn't provide the relevant locale files.
--- git-pull.sh | 16 ++++--- git-send-email.perl | 3 +- po/is.po | 23 +++++++++++ t/t0200-gettext.sh | 29 ++++++++++++++ wt-status.c | 107 ++++++++++++++++++++++++++------------------------- 5 files changed, 117 insertions(+), 61 deletions(-)
git-pull.sh +9 -7
@@ -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
@@ -125,8 +126,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
@@ -158,11 +159,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
@@ -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 +23 -0
@@ -13,6 +13,20 @@ msgstr "" msgid "See git help COMMAND for more information on a specific command." msgstr "Sjá git help SKIPUN til að sjá hjálp fyrir tiltekna skipun." +#: 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/test.c:9 msgid "TEST: A C test string"
@@ -24,6 +38,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/test.sh:8 msgid "TEST: A Shell test string"
@@ -35,6 +53,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" + #. TRANSLATORS: This is a test. You don't need to translate it. #: t/t0200/test.perl:8 msgid "TEST: A Perl test string"
t/t0200-gettext.sh +29 -0
@@ -130,6 +130,35 @@ then LANGUAGE=is LC_ALL=is_IS.UTF-8 gettext "" >real-locale && test -s real-locale ' + + # Actually execute some C and Shell code that uses Gettext + test_expect_success 'C: git-status reads our message catalog ' ' + test_commit "some-file" && + git checkout -b test/gettext && + LANGUAGE=C LC_ALL=C git status | grep test/gettext > expect && + echo "# On branch test/gettext" > actual && + test_cmp expect actual && + + LANGUAGE=is LC_ALL=is_IS.UTF-8 git status | grep test/gettext > expect && + echo "# Á greininni test/gettext" > actual && + test_cmp expect actual + ' + + test_expect_success 'Shell: git-pull reads our message catalog' ' + # Repository for testing + mkdir parent && + (cd parent && git init && + echo one >file && git add file && + git commit -m one) && + + # Actual test + (cd parent && + (LANGUAGE=C LC_ALL=C git pull --tags "../" >out 2>err); + grep "Fetching tags only" err && + (LANGUAGE=is LC_ALL=is_IS.UTF-8 git pull --tags ../ >out 2>err || :) && + grep "Næ aðeins í" err) + ' + test_done else say 'Skipping unportable gettext("") tests, set TEST_GIT_GETTEXT_EXHAUSTIVE=1 to enable'
wt-status.c +54 -53
241 lines not on this page · raw message
Signature · 1 line
1.7.1.251.g92a7
v4 cover Gettext support for Git
In reply to Junio C HamanoThis patch series implements gettext support for git, making it possible to localize it.
Changes since v3:
* Skip tests that depend on is_IS locale unless
TEST_GIT_GETTEXT_EXHAUSTIVE=1 is set.
All the systems I'd tested on previously (FreeBSD, Solaris, Mac OS X, openSUSE, Debian, Ubuntu) had an Icelandic locale installed. Skip tests that depend on being able to set the locale.
I've now added a bare-bones Debian system to my test setup. It failed on the same tests that Junio failed on.
Here's the git diff -w --stat since v3:
t/t0200-gettext.sh | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)Ævar Arnfjörð Bjarmason (2):
Add infrastructure for translating Git with gettext Add initial C, Shell and Perl gettext translations
.gitignore | 2 + INSTALL | 12 +++ Makefile | 69 +++++++++++++++++- config.mak.in | 2 + configure.ac | 12 +++ daemon.c | 3 + fast-import.c | 3 + gettext.c | 22 ++++++ gettext.h | 18 +++++ git-pull.sh | 16 ++-- git-send-email.perl | 3 +- git-sh-i18n.sh | 71 ++++++++++++++++++ git.c | 3 + http-backend.c | 3 + http-fetch.c | 3 + http-push.c | 3 + imap-send.c | 3 + perl/Git/I18N.pm | 91 +++++++++++++++++++++++ perl/Makefile | 3 +- perl/Makefile.PL | 14 +++- po/.gitignore | 1 + po/is.po | 70 ++++++++++++++++++ shell.c | 3 + show-index.c | 3 + t/t0200-gettext.sh | 166 ++++++++++++++++++++++++++++++++++++++++++ t/t0200/test.c | 13 +++ t/t0200/test.perl | 14 ++++ t/t0200/test.sh | 14 ++++ t/t0201-gettext-fallbacks.sh | 50 +++++++++++++ t/t0202-gettext-perl.sh | 23 ++++++ t/t0202/test.pl | 104 ++++++++++++++++++++++++++ t/test-lib.sh | 2 + upload-pack.c | 3 + wt-status.c | 107 ++++++++++++++------------- 34 files changed, 864 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/test.c create mode 100644 t/t0200/test.perl create mode 100644 t/t0200/test.sh create mode 100755 t/t0201-gettext-fallbacks.sh create mode 100755 t/t0202-gettext-perl.sh create mode 100644 t/t0202/test.pl
PATCH v4 1/2 Add infrastructure for translating Git with gettext
In reply to Junio C HamanoAll 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 or SunOS 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. When using ./configure the autoconf script will auto-detect if the gettext libraries are installed and act appropriately.
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 available. That's a reasonable assumption since then the message catalog 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 that's 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.
See <[email protected]> for a further elaboration on this topic.
* Shell:
Shell code that's 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 gettext(1) if it's available. The latter is available without the former on Solaris, which has its own non-GNU gettext implementation. We also need to emulate eval_gettext() there.
If neither are present we'll use a dumb printf(1) fall-through wrapper.
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, and unlikely to ever do so.
This series has been tested by me on Ubuntu 10.04, Debian testing, FreeBSD 8.1 and SunOS 5.10, and by others on Mac OS X 10.6.3 (with Xcode 3.2.2) and openSUSE Factory (11.3, milestone 7).
SunOS has its own non-GNU gettext implementation which this patch supports, although that may change in the future if it turns out that we need some GNU libintl features that SunOS doesn't provide.
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, including Jonathan Nieder, Jakub Narebski, Johannes Sixt, Peter Krefting, Junio C Hamano, Thomas Rast and others.
--- .gitignore | 2 + INSTALL | 12 ++++ Makefile | 69 ++++++++++++++++++++- config.mak.in | 2 + configure.ac | 12 ++++ daemon.c | 3 + fast-import.c | 3 + gettext.c | 22 +++++++ gettext.h | 18 ++++++ git-sh-i18n.sh | 71 +++++++++++++++++++++ git.c | 3 + http-backend.c | 3 + http-fetch.c | 3 + http-push.c | 3 + imap-send.c | 3 + perl/Git/I18N.pm | 91 +++++++++++++++++++++++++++ perl/Makefile | 3 +- perl/Makefile.PL | 14 ++++- po/.gitignore | 1 + po/is.po | 47 ++++++++++++++ shell.c | 3 + show-index.c | 3 + t/t0200-gettext.sh | 138 ++++++++++++++++++++++++++++++++++++++++++ t/t0200/test.c | 13 ++++ t/t0200/test.perl | 14 ++++ t/t0200/test.sh | 14 ++++ t/t0201-gettext-fallbacks.sh | 50 +++++++++++++++ t/t0202-gettext-perl.sh | 23 +++++++ t/t0202/test.pl | 104 +++++++++++++++++++++++++++++++ t/test-lib.sh | 2 + upload-pack.c | 3 + 31 files changed, 748 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/test.c create mode 100644 t/t0200/test.perl create mode 100644 t/t0200/test.sh create mode 100755 t/t0201-gettext-fallbacks.sh create mode 100755 t/t0202-gettext-perl.sh create mode 100644 t/t0202/test.pl
.gitignore +2 -0
@@ -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/
INSTALL +12 -0
@@ -93,6 +93,18 @@ Issues of note: history graphically, and in git-gui. If you don't want gitk or git-gui, you can use NO_TCLTK. + - A gettext library is used by default for localizing Git. The + primary target is GNU libintl, but the Solaris gettext + implementation also works. + + We need a gettext.h on the system for C code, gettext.sh (or + Solaris gettext(1)) for shell scripts, and libintl-perl for Perl + programs. + + Set NO_GETTEXT to disable localization support and make Git only + use English. Under autoconf the configure script will do this + automatically if it can't find libintl on the system. + - Some platform specific issues are dealt with Makefile rules, but depending on your specific installation, you may not have all the libraries/tools needed, or you may have
Makefile +67 -2
189 lines not on this page · raw message
config.mak.in +2 -0
@@ -32,9 +32,11 @@ 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@ +NEEDS_LIBINTL=@NEEDS_LIBINTL@ NEEDS_LIBGEN=@NEEDS_LIBGEN@ NO_SYS_SELECT_H=@NO_SYS_SELECT_H@ NO_D_INO_IN_DIRENT=@NO_D_INO_IN_DIRENT@
configure.ac +12 -0
@@ -559,6 +559,12 @@ AC_CHECK_LIB([c], [basename], AC_SUBST(NEEDS_LIBGEN) test -n "$NEEDS_LIBGEN" && LIBS="$LIBS -lgen" +AC_CHECK_LIB([c], [gettext], +[NEEDS_LIBINTL=], +[NEEDS_LIBINTL=YesPlease]) +AC_SUBST(NEEDS_LIBINTL) +test -n "$NEEDS_LIBINTL" && LIBS="$LIBS -lintl" + ## Checks for header files. AC_MSG_NOTICE([CHECKS for header files]) #
@@ -730,6 +736,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=],
daemon.c +3 -0
@@ -3,6 +3,7 @@#include "exec_cmd.h" #include "run-command.h" #include "strbuf.h" +#include "gettext.h" #include <syslog.h>
@@ -974,6 +975,8 @@ int main(int argc, char **argv)gid_t gid =0 ;int i; +git_setup_gettext (); +git_extract_argv0_path (argv[0 ]);for (i =1 ; i < argc; i++) {
fast-import.c +3 -0
@@ -156,6 +156,7 @@ Format of STDIN stream:#include "csum-file.h" #include "quote.h" #include "exec_cmd.h" +#include "gettext.h" #define PACK_ID_BITS 16#define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)
@@ -2904,6 +2905,8 @@ int main(int argc, const char **argv)git_extract_argv0_path (argv[0 ]); +git_setup_gettext (); +if (argc ==2 && !strcmp (argv[1 ],"-h" ))usage (fast_import_usage);
gettext.c new file +22 -0
@@ -0,0 +1,22 @@ +#include "exec_cmd.h" +#include <locale.h> +#include <libintl.h> +#include <stdlib.h> + +extern 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" ); +}
gettext.h new file +18 -0
@@ -0,0 +1,18 @@ +#ifndef GETTEXT_H +#define GETTEXT_H + +#ifdef NO_GETTEXT +static inline void git_setup_gettext (void ) {} +#else +extern void git_setup_gettext (void ); +#endif + +#define N_ (s) (s) +#ifdef NO_GETTEXT +#define _ (s) (s) +#else +#include <libintl.h> +#define _ (s) gettext(s) +#endif + +#endif
git-sh-i18n.sh new file +71 -0
71 lines not on this page · raw message
git.c +3 -0
@@ -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: *
http-backend.c +3 -0
@@ -6,6 +6,7 @@#include "exec_cmd.h" #include "run-command.h" #include "string-list.h" +#include "gettext.h" static const char content_type[] ="Content-Type" ;static const char content_length[] ="Content-Length" ;
@@ -605,6 +606,8 @@ int main(int argc, char **argv)char *cmd_arg =NULL ;int i; +git_setup_gettext (); +git_extract_argv0_path (argv[0 ]);set_die_routine (die_webcgi);
http-fetch.c +3 -0
@@ -2,6 +2,7 @@#include "exec_cmd.h" #include "http.h" #include "walker.h" +#include "gettext.h" static const char http_fetch_usage[] ="git http-fetch " "[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url" ;
@@ -24,6 +25,8 @@ int main(int argc, const char **argv)int get_verbosely =0 ;int get_recover =0 ; +git_setup_gettext (); +git_extract_argv0_path (argv[0 ]);while (arg < argc && argv[arg][0 ] =='-' ) {
http-push.c +3 -0
@@ -10,6 +10,7 @@#include "remote.h" #include "list-objects.h" #include "sigchain.h" +#include "gettext.h" #include <expat.h>
@@ -1791,6 +1792,8 @@ int main(int argc, char **argv)struct remote *remote;char *rewritten_url =NULL ; +git_setup_gettext (); +git_extract_argv0_path (argv[0 ]); repo =xcalloc (sizeof (*repo),1 );
imap-send.c +3 -0
@@ -25,6 +25,7 @@#include "cache.h" #include "exec_cmd.h" #include "run-command.h" +#include "gettext.h" #ifdef NO_OPENSSL typedef void *SSL ;#else
@@ -1535,6 +1536,8 @@ int main(int argc, char **argv)git_extract_argv0_path (argv[0 ]); +git_setup_gettext (); +if (argc !=1 )usage (imap_send_usage);
perl/Git/I18N.pm new file +91 -0
91 lines not on this page · raw message
perl/Makefile +2 -1
@@ -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
@@ -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
@@ -0,0 +1 @@ +/*.pot
po/is.po new file +47 -0
47 lines not on this page · raw message
shell.c +3 -0
@@ -2,6 +2,7 @@#include "quote.h" #include "exec_cmd.h" #include "strbuf.h" +#include "gettext.h" static int do_generic_cmd (const char *me,char *arg) {
@@ -51,6 +52,8 @@ int main(int argc, char **argv)struct commands *cmd;int devnull_fd; +git_setup_gettext (); +/* * Always open file descriptors 0/1/2 to avoid clobbering files * in die(). It also avoids not messing up when the pipes are
show-index.c +3 -0
@@ -1,5 +1,6 @@#include "cache.h" #include "pack.h" +#include "gettext.h" static const char show_index_usage[] ="git show-index < <packed archive index>" ;
@@ -11,6 +12,8 @@ int main(int argc, char **argv)unsigned int version;static unsigned int top_index[256 ]; +git_setup_gettext (); +if (argc !=1 )usage (show_index_usage);if (fread (top_index,2 *4 ,1 , stdin) !=1 )
t/t0200-gettext.sh new file +138 -0
138 lines not on this page · raw message
t/t0200/test.c new file +13 -0
@@ -0,0 +1,13 @@ +/* This is a phony C program that's only here to test xgettext message extraction */ + +const char help[] = +N_ ("See 'git help COMMAND' for more information on a specific command." ); + +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/test.perl new file +14 -0
@@ -0,0 +1,14 @@ +# This is a phony Perl program that's only here to test xgettext +# message extraction + +# so the above comment won't be folded into the next one by xgettext +1; + +# 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/test.sh new file +14 -0
@@ -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-fallbacks.sh new file +50 -0
50 lines not on this page · raw message
t/t0202-gettext-perl.sh new file +23 -0
@@ -0,0 +1,23 @@ +#!/bin/sh + +test_description='Perl gettext interface (Git::I18N)' +. ./test-lib.sh + +GIT_TEXTDOMAINDIR="$GIT_EXEC_PATH/share/locale" +export GIT_TEXTDOMAINDIR + +if ! test_have_prereq PERL; then + say 'skipping perl interface tests, perl not available' + test_done +fi + +"$PERL_PATH" -MTest::More -e 0 2>/dev/null || { + say "Perl Test::More unavailable, skipping test" + test_done +} + +test_external_without_stderr \ + 'Perl Git::I18N API' \ + "$PERL_PATH" "$TEST_DIRECTORY"/t0202/test.pl + +test_done
t/t0202/test.pl new file +104 -0
104 lines not on this page · raw message
t/test-lib.sh +2 -0
@@ -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
@@ -845,6 +846,7 @@ esac test -z "$NO_PERL" && test_set_prereq PERL test -z "$NO_PYTHON" && test_set_prereq PYTHON +test -z "$NO_GETTEXT" && test_set_prereq GETTEXT # test whether the filesystem supports symbolic links ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
upload-pack.c +3 -0
@@ -10,6 +10,7 @@#include "revision.h" #include "list-objects.h" #include "run-command.h" +#include "gettext.h" static const char upload_pack_usage[] ="git upload-pack [--strict] [--timeout=nn] <dir>" ;
@@ -686,6 +687,8 @@ int main(int argc, char **argv)int i;int strict =0 ; +git_setup_gettext (); +git_extract_argv0_path (argv[0 ]); read_replace_refs =0 ;
Signature · 1 line
1.7.1.251.g92a7
PATCH v4 2/2 Add initial C, Shell and Perl gettext translations
In reply to Junio C HamanoChange 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.
The new tests are only run under TEST_GIT_I18N_EXHAUSTIVE=1, since they might fail if the host OS doesn't provide the relevant locale files.
--- git-pull.sh | 16 ++++--- git-send-email.perl | 3 +- po/is.po | 23 +++++++++++ t/t0200-gettext.sh | 28 +++++++++++++ wt-status.c | 107 ++++++++++++++++++++++++++------------------------- 5 files changed, 116 insertions(+), 61 deletions(-)
git-pull.sh +9 -7
@@ -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
@@ -125,8 +126,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
@@ -158,11 +159,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
@@ -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 +23 -0
@@ -13,6 +13,20 @@ msgstr "" msgid "See git help COMMAND for more information on a specific command." msgstr "Sjá git help SKIPUN til að sjá hjálp fyrir tiltekna skipun." +#: 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/test.c:9 msgid "TEST: A C test string"
@@ -24,6 +38,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/test.sh:8 msgid "TEST: A Shell test string"
@@ -35,6 +53,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" + #. TRANSLATORS: This is a test. You don't need to translate it. #: t/t0200/test.perl:8 msgid "TEST: A Perl test string"
t/t0200-gettext.sh +28 -0
@@ -135,4 +135,32 @@ test_expect_success 'sanity: Some gettext("") data for real locale' ' test -s real-locale ' +# Actually execute some C and Shell code that uses Gettext +test_expect_success 'C: git-status reads our message catalog ' ' + test_commit "some-file" && + git checkout -b test/gettext && + LANGUAGE=C LC_ALL=C git status | grep test/gettext > expect && + echo "# On branch test/gettext" > actual && + test_cmp expect actual && + + LANGUAGE=is LC_ALL=is_IS.UTF-8 git status | grep test/gettext > expect && + echo "# Á greininni test/gettext" > actual && + test_cmp expect actual +' + +test_expect_success 'Shell: git-pull reads our message catalog' ' + # Repository for testing + mkdir parent && + (cd parent && git init && + echo one >file && git add file && + git commit -m one) && + + # Actual test + (cd parent && + (LANGUAGE=C LC_ALL=C git pull --tags "../" >out 2>err); + grep "Fetching tags only" err && + (LANGUAGE=is LC_ALL=is_IS.UTF-8 git pull --tags ../ >out 2>err || :) && + grep "Næ aðeins í" err) +' + test_done
wt-status.c +54 -53
241 lines not on this page · raw message
Signature · 1 line
1.7.1.251.g92a7
Re: [PATCH 1/2] Add infrastructure for translating Git with gettext
In reply to Ævar Arnfjörð Bjarmasongit-sh-i18n.sh line 25
Quoted 6 lines · Ævar Arnfjörð Bjarmason
git-sh-i18n.sh new file +6
-0+# 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
It turns out that this doesn't actually work, and I can't find a workaround. In Bash and Solaris's /bin/sh this executes until "dies here". The problem is that I can't use the subshell trick, since the gettext.sh inclusion has to be done in the current shell (I checked, tests will fail).
#!/bin/sh
(. does-not-exist.sh)
echo "A subshell made it! ret = $?"
. does-not-exist.sh
# dies here
echo "A real shell made it! ret = $?"Is there some clever shellscript trick that I'm missing, or will I have to resort to modifying the file at `make' time for this to work everywhere?
Re: [PATCH 1/2] Add infrastructure for translating Git with gettext
Quoted 13 lines · Ævar Arnfjörð Bjarmason
It turns out that this doesn't actually work, and I can't find a workaround. In Bash and Solaris's
/bin/shthis executes until "dies here". The problem is that I can't use the subshell trick, since thegettext.shinclusion has to be done in the current shell (I checked, tests will fail).#!/bin/sh (. does-not-exist.sh) echo "A subshell made it! ret = $?" . does-not-exist.sh # dies here echo "A real shell made it! ret = $?"
Quoted 3 lines
Is there some clever shellscript trick that I'm missing, or will I have to resort to modifying the file at `make' time for this to work everywhere?
Works for me in bash (4.0.35), but fails the way you say in dash (if only I could figure out the option that tells me the version!).
This works however:
type does-not-exist.sh 2>/dev/null && . does-not-exist.sh
I suspect it only works if the script is executable, as otherwise type would not find it (but . would). But at least on my system, it is.
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chRe: [PATCH 1/2] Add infrastructure for translating Git with gettext
Quoted 18 lines · Thomas Rast
Quoted 10 lines · Ævar Arnfjörð Bjarmason
It turns out that this doesn't actually work, and I can't find a workaround. In Bash and Solaris's
/bin/shthis executes until "dies here". The problem is that I can't use the subshell trick, since thegettext.shinclusion has to be done in the current shell (I checked, tests will fail).#!/bin/sh
(.does-not-exist.sh)
echo "A subshell made it! ret = $?"
.does-not-exist.shQuoted 6 lines
# dies here echo "A real shell made it! ret = $?"Is there some clever shellscript trick that I'm missing, or will I have to resort to modifying the file at `make' time for this to work everywhere?
Quoted 6 lines
Works for me in bash (4.0.35), but fails the way you say in dash (if only I could figure out the option that tells me the version!).
This works however:
type
does-not-exist.sh2>/dev/null && .does-not-exist.sh
Thanks. That works, I've tested the following script:
#!/bin/sh
type meh.sh >/dev/null 2>&1 && . meh.sh && echo "Included meh.sh"|| echo "Didn't include meh.sh"
echo "I've made it!"
type gettext.sh >/dev/null 2>&1 && . gettext.sh && echo "Includedgettext.sh" || echo "Didn't include gettext.sh"
echo "I've made it!"
On the following:
FreeBSD: /bin/sh, bash
Solaris: /bin/sh, /usr/bin/ksh, bash,
Debian: dash, bash
They all make it to the last "I've made it!".
Quoted 2 lines
I suspect it only works if the script is executable, as otherwise type would not find it (but . would). But at least on my system, it is.
With gettext.sh the assumption that it's +x seems valid, the installation script for GNU gettext always gives it an executable bit.