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

Re: [PATCH 2/2] add a Makefile switch to avoid gettext translation in shell scripts

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jan 24, 2012, 00:39 UTC
Message-ID
<CACBZZX66-JsS4zZXwv2squcjYUS8v+9cN0hv23t5nMHA+1k9XQ@mail.gmail.com>
In-Reply-To
<20120123221256.GG20833@burratino>
On Mon, Jan 23, 2012 at 23:12, Jonathan Nieder <jrnieder@gmail.com> wrote:
Show 10 quoted lines
> Junio C Hamano wrote:
>
>>     make USE_GETTEXT_SCHEME=fallthrough
>>
>> This will replace the translation routines with fallthrough versions,
>> that does not use gettext from the platform.
>
> Nice implementation.  I still don't understand why NO_GETTEXT=YesPlease
> should not imply this.  Is it to ensure the GETTEXT_SCHEME=gnu mode
> gets more testing?

I was the only one with an objection to doing that. The main (and I admit, at least slightly irrational) reason being that I simply don't like using fallback functions when the system supplies us with perfectly good functions we can use instead.

It means we're less likely to share code / fixes / eyeballs / cache with other programs. I.e. by using envsubst(1) instead of git-sh-i18n--envsubst--variables(1).

Ironically this is all my fault by naming the option for turning off translations NO_GETTEXT. What it should be called is DO_NOT_TRANSLATE_OUTPUT, but since we *need* shell functions to output anything it might have used a system gettext library to do that, NO_GETTEXT should have been "I don't have any gettext library, please supply some fallbacks".

Which would have meant that for people who simply don't want translated output we'd be using the maintained by upstream envsubst(1) instead of the doomed to bitrot forever hack I ripped out of some old GPL2 version of GNU gettext.

Anyway in the grand scheme of things none of this really matters, these patches can all go in as far as I'm concerned. I can submit patches to improve it once the dust has settled if I still care enough.

Aside from this I think not having the ability to run a pre-processor on the shellscripts results in some really ugly workarounds. This stuff would be much nicer if we could just generate git-sh-i18n.sh at compile time depending on some autoconf tests or Makefile options.

And by hacking up a pre-processor that just searches/replaces all the gettext/eval_gettext calls out of the shell code we could sidestep this whole issue and there wouldn't be any need for fallback functions, ever. This would also result in a real improvement on Windows where exec overhead is much larger.

Like this hack, which doesn't even work, but gives you some idea of what we could do:

    #!/usr/bin/env perl
    BEGIN { $^I = ""; }
    sub unescape {
    	my $str = shift;
    	$str =~ s/\\\$/\$/gs;
    	$str;
    }
    LINE: while (defined($_ = <ARGV>)) {
    	s["\$\(gettext "([^"]+?)"\)"]["$1"]g;
    	s["\$\(eval_gettext "([^"]+?)"\)"]['"' . unescape($1) . '"']eg;
    	s[eval_gettextln "([^"]+?)"]['echo "' . unescape($1) . '"']eg;
    	s[gettext "([^"]+?)"][printf "%s" "$1"]g;
    	s[gettextln "([^"]+?)"][echo "$1"]g;
    #	s[gettextln "([^"]+?)"][echo "$1"]g;
    #	s/foo/bar/;
    	print;
    }
When run:
    for f in $(git grep -l gettext -- *.sh); do perl replace-gettext.pl $f; done
Produces output like:
    @@ -351 +351 @@ split_patches () {
    -                       clean_abort "$(eval_gettext "Patch format
\$patch_format is not supported.")"
    +                       clean_abort "Patch format $patch_format is
not supported."
    @@ -353 +353 @@ split_patches () {
    -                       clean_abort "$(gettext "Patch format
detection failed.")"
    +                       clean_abort "Patch format detection failed."
    @@ -403 +403 @@ do
    -               die "$(gettext "-d option is no longer supported.
Do not use.")"
    +               die "-d option is no longer supported.  Do not use."
    @@ -466 +466 @@ then
    -       die "$(eval_gettext "previous rebase directory \$dotest
still exists but mbox given.")"
    +       die "previous rebase directory $dotest still exists but mbox given."

It would be relatively easy to hack up a basic POSIX shell pre-processor like this that would work on our *.sh files, thus eliminating the need for all of this fallback business.

Previous: Alex RiesenNext: Alex Riesen
Message 37 of 40 in “i18n: disable i18n for shell scripts if NO_GETTEXT defined”
  1. i18n: disable i18n for shell scripts if NO_GETTEXT definedAlex Riesen, Jan 17, 2012
  2. Junio C HamanoJan 17, 2012
  3. Alex RiesenJan 18, 2012
  4. i18n: disable i18n for shell scripts if NO_GETTEXT definedAlex Riesen, Jan 18, 2012
  5. Jonathan NiederJan 19, 2012
  6. Alex RiesenJan 19, 2012
  7. Ævar Arnfjörð BjarmasonJan 18, 2012
  8. Alex RiesenJan 18, 2012
  9. Ævar Arnfjörð BjarmasonJan 18, 2012
  10. Jonathan NiederJan 19, 2012
  11. Junio C HamanoJan 19, 2012
  12. Johannes SixtJan 19, 2012
  13. Junio C HamanoJan 19, 2012
  14. Ævar Arnfjörð BjarmasonJan 20, 2012
  15. Alex RiesenJan 20, 2012
  16. git-sh-i18n: detect and avoid broken gettext(1) implementationÆvar Arnfjörð Bjarmason, Jan 20, 2012
  17. Alex RiesenJan 20, 2012
  18. Junio C HamanoJan 20, 2012
  19. Alex RiesenJan 20, 2012
  20. Junio C HamanoJan 20, 2012
  21. Alex RiesenJan 20, 2012
  22. Junio C HamanoJan 20, 2012
  23. Alex RiesenJan 20, 2012
  24. Junio C HamanoJan 20, 2012
  25. Alex RiesenJan 20, 2012
  26. Alex RiesenJan 19, 2012
  27. Alex RiesenJan 19, 2012
  28. add a Makefile switch to avoid gettext translation in shell scriptsAlex Riesen, Jan 19, 2012
  29. Junio C HamanoJan 23, 2012
  30. 1/2 git-sh-i18n: restructure the logic to compute gettext.sh schemeJunio C Hamano, Jan 23, 2012
  31. 2/2 add a Makefile switch to avoid gettext translation in shell scriptsJunio C Hamano, Jan 23, 2012
  32. Jonathan NiederJan 23, 2012
  33. Junio C HamanoJan 23, 2012
  34. Jonathan NiederJan 23, 2012
  35. 3/2 i18n: do not use gettext.sh by default when NO_GETTEXT is setJonathan Nieder, Jan 24, 2012
  36. Alex RiesenJan 24, 2012
  37. Ævar Arnfjörð BjarmasonJan 24, 2012
  38. Alex RiesenJan 24, 2012
  39. Alex RiesenJan 24, 2012
  40. Junio C HamanoJan 24, 2012

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.