git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH/RFC v7 1/2] Add infrastructure for translating Git with gettext

From
Jakub Narebski <jnareb@gmail.com>
Date
Jun 5, 2010, 13:57 UTC
Message-ID
<m3zkz9pols.fsf@localhost.localdomain>
In-Reply-To
<1275704035-6552-2-git-send-email-avarab@gmail.com>
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
Show 5 quoted lines
> 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.
[...]
> Implementation and usage notes:
[...]
Show 14 quoted lines
>  * 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.
Actually both of those can be set using Locale::TextDomain->import()
call.  See e.g. this answer on StackOverflow:
  http://stackoverflow.com/questions/2965626/examples-of-localization-in-perl-using-gettext-and-localetextdomain-with-fallb/2967872#2967872
>    [...] In any case, this is an issue wholly internal
>    Git::I18N. Its guts can be changed later if that's deemed
>    necessary.
Right.
 
Show 14 quoted lines
> --- a/INSTALL
> +++ b/INSTALL
> @@ -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.
> +

Shouldn't you also add here that you need also "libintl-perl" to have those commands that are written in Perl localized?

Show 16 quoted lines
> diff --git a/Makefile b/Makefile
> index d5d6565..3040000 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -28,6 +28,15 @@ all::
>  # Define NO_EXPAT if you do not have expat installed.  git-http-push is
>  # not built, and you cannot push using http:// and https:// transports.
>  #
> +# Define NO_GETTEXT if you don't want to build with Git with gettext
> +# support. Building it requires GNU libintl, and additionally
> +# libintl-perl at runtime.
> +#
> +# Define NEEDS_LIBINTL if you haven't set NO_GETTEXT and your system
> +# needs to be explicitly linked to -lintl. It's defined automatically
> +# on platforms where we don't expect glibc (Linux, Hurd,
> +# GNU/kFreeBSD), which includes libintl.
[...]
Show 9 quoted lines
> diff --git a/config.mak.in b/config.mak.in
> index 0d4b64d..a15f3c1 100644
> --- a/config.mak.in
> +++ b/config.mak.in
> @@ -32,6 +32,7 @@ NO_CURL=@NO_CURL@
>  NO_EXPAT=@NO_EXPAT@
>  NO_LIBGEN_H=@NO_LIBGEN_H@
>  HAVE_PATHS_H=@HAVE_PATHS_H@
> +NO_GETTEXT=@NO_GETTEXT@
No
  +NEEDS_LIBINTL=@NEEDS_LIBINTL@
(see also below)?
Show 14 quoted lines
> diff --git a/configure.ac b/configure.ac
> index 71038fc..7bebfd8 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -730,6 +730,12 @@ AC_CHECK_HEADER([paths.h],
>  [HAVE_PATHS_H=])
>  AC_SUBST(HAVE_PATHS_H)
>  #
> +# Define NO_GETTEXT if you don't have libintl.h
> +AC_CHECK_HEADER([libintl.h],
> +[NO_GETTEXT=],
> +[NO_GETTEXT=YesPlease])
> +AC_SUBST(NO_GETTEXT)
> +#

No check for NEEDS_LIBINTL? No check that gettext is properly set up with AM_GNU_GETTEXT (protected with m4_ifdef)?

  +# Define NEEDS_LIBINTL if you haven't set NO_GETTEXT and your system
  +# needs to be explicitly linked to -lintl. It's defined automatically
  +# on platforms where we don't expect glibc (Linux, Hurd,
  +# GNU/kFreeBSD), which includes libintl.
  +AC_CHECK_LIB([c], [gettext],
  +[NEEDS_LIBINTL=],
  +[NEEDS_LIBINTL=YesPlease])
  +AC_SUBST(NEEDS_LIBINTL)
  +test -n "$NEEDS_LIBINTL" && LIBS="$LIBS -lintl"

Or something like that (following examples for NEEDS_SOCKET and NEEDS_RESOLV in configure.ac).

Show 12 quoted lines
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index 454880a..ae63316 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -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

This ensures that testsuite is run without translation. It is required because tests often include checking output of git commands against expected output.

But perhaps, in later commit, we should mark those test that check porcelain output format with NO_GETTEXT or LANG_C, and add --gettext or --intl or --localized to run (parts of) testsuite with localized strings, checking if localization didn't broke some scripted command (somewhere command parses output of other git command).

What do you think?
-- 
Jakub Narebski
Poland
ShadeHawk on #git
Previous: Jonathan NiederNext: Ævar Arnfjörð Bjarmason
Message 17 of 19 in “Add infrastructure for translating Git with gettext”
  1. 0/2 Add infrastructure for translating Git with gettextÆvar Arnfjörð Bjarmason, Jun 5, 2010
  2. 1/2 Add infrastructure for translating Git with gettextÆvar Arnfjörð Bjarmason, Jun 5, 2010
  3. Jonathan NiederJun 5, 2010
  4. Ævar Arnfjörð BjarmasonJun 5, 2010
  5. Jonathan NiederJun 5, 2010
  6. Ævar Arnfjörð BjarmasonJun 5, 2010
  7. Jonathan NiederJun 5, 2010
  8. Ævar Arnfjörð BjarmasonJun 5, 2010
  9. Jonathan NiederJun 12, 2010
  10. Jonathan NiederJun 5, 2010
  11. Ævar Arnfjörð BjarmasonJun 5, 2010
  12. Jonathan NiederJun 5, 2010
  13. Ævar Arnfjörð BjarmasonJun 5, 2010
  14. Jonathan NiederJun 5, 2010
  15. Ævar Arnfjörð BjarmasonJun 5, 2010
  16. Inline functions (Re: [PATCH/RFC v7 1/2] Add infrastructure for translating Git with gettext)Jonathan Nieder, Jun 5, 2010
  17. Jakub NarebskiJun 5, 2010
  18. Ævar Arnfjörð BjarmasonJun 5, 2010
  19. 2/2 Add initial C, Shell and Perl gettext translationsÆvar Arnfjörð Bjarmason, Jun 5, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.