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

Re: [PATCH] i18n: disable i18n for shell scripts if NO_GETTEXT defined

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jan 18, 2012, 23:18 UTC
Message-ID
<CACBZZX4tB6DGV-1tiuOamq7ACPk0a-=1Pb9Vk1SgyDqAq-EFOw@mail.gmail.com>
In-Reply-To
<CALxABCadHdvR02Br9e6STy0w+EPoycUKr62RiSUSP_EPF-TH3g@mail.gmail.com>
On Wed, Jan 18, 2012 at 19:57, Alex Riesen <raa.lkml@gmail.com> wrote:
Show 23 quoted lines
> On Wed, Jan 18, 2012 at 16:22, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
>> On Tue, Jan 17, 2012 at 14:42, Alex Riesen <raa.lkml@gmail.com> wrote:
>>> Otherwise the i18n is used in the scripts even with NO_GETTEXT set.
>>> It is very unexpected.
>>
>> So the reason it's like that is that I was assuming that gettext.sh
>> wouldn't be FUBAR anywhere, but the translations shouldn't kick in
>> since we haven't installed them during "make install".
>>
>> But I wonder if this negatively affects some systems, now we now:
>>
>>  * Don't use gettext.sh, which means that we're using our fallback
>>   shell function instead of the binary gettext(1), which is probably
>>   faster.
>>
>>  * Use our own eval_gettext() instead of using the system one, which
>>   uses the GNU binary which is more likely to be in the FS cache
>>   already since other programs are probably using it.
>>
>> Which is why I didn't do something like this to begin with.
>
> Well, if I say NO_GETTEXT, I kind of want none of local gettext,
> whether it works, or not.

That's not what NO_GETTEXT means, and not what it *should* mean. It means that your output won't be translated, but we might still make use of a locally installed library to provide the gettext() and eval_gettext() functions.

This approach has worked everywhere so far (Linux, OSX, *BSD etc.), and you want to change *everywhere* because you have some completely broken Cygwin install.

How did you even get that install? Is it a known issue? Some ancient now-fixed bug? What version of Cygwin / gettext etc.

Now I'm not saying that we shouldn't fix this, I just don't think that this is the right way to go about it.

Now I haven't done exhaustive tests but this is the sort of slowdown we might be looking at on Linux for output, both with warm cache:

    $ cat our-eval_gettext.sh
    #!/bin/bash
    eval_gettext () {
            printf "%s" "$1" | (
                    export PATH $(git sh-i18n--envsubst --variables "$1");
                    git sh-i18n--envsubst "$1"
            )
    }
    for i in {1..1000}
    do
        some_variable="for speed"
        eval_gettext "benchmark this \$some_variable"
    done
    $ time bash our-eval_gettext.sh >/dev/null
    real    0m3.336s
    user    0m0.052s
    sys     0m0.128s

Compared to using the system eval_gettext, which for me is much faster:

    $ cat system-eval_gettext.sh
    #!/bin/bash
    . gettext.sh
    for i in {1..1000}
    do
        some_variable="for speed"
        eval_gettext "benchmark this \$some_variable"
    done
    $ time bash system-eval_gettext.sh >/dev/null
    real    0m1.671s
    user    0m0.048s
    sys     0m0.140s
And then we have the gettext() function itself:
    $ cat our-gettext.sh
    #!/bin/bash
    gettext () {
            printf "%s" "$1"
    }
    for i in {1..1000}
    do
        gettext "benchmark this"
    done
    $ cat system-gettext.sh
    #!/bin/bash
    for i in {1..1000}
    do
        gettext "benchmark this"
    done
Where our fallback is faster, because printf() is a bash built-in:
    $ time bash system-gettext.sh >/dev/null
    real    0m0.534s
    user    0m0.016s
    sys     0m0.084s
    $ time bash our-gettext.sh >/dev/null
    real    0m0.018s
    user    0m0.016s
    sys     0m0.000s

Anyway speed is the least of the issues here, it's not like we're very constrained by spewing out gettext output.

I just think we should consider portability more carefully than "it doesn't work on one obscure setup, let's change it everywhere", when actually it's working just fine in most places.

I think a better fix would be to add probes for whether the system functions actually work in the autoconf script.

I'd also love to be able to use C macros in the git-*.sh scripts, it would make the code in git-sh-i18n.sh much nicer since we can determine what functions we want at compile time.

Another option would be to pipe our shellscripts through some pre-processor that would completely remove the gettext and eval_gettext calls. Then we'd be doing the same thing we're doing on the C-Level, and we wouldn't have the previously cited command-call overhead or Win32.

But in summary: We shouldn't be *always* using fallback functions whether they're the C stuff in compat/* or the gettext fallbacks in git-sh-i18n.sh just because there's some version out there of the system-supplied functions that's broken.

It makes sense to prefer the system functions by default in both cases, but when the OS one can be broken or lacking we can just add probes or Makefile options like we do for fnmatch() with the NO_FNMATCH_CASEFOLD switch.

Previous: Alex RiesenNext: Jonathan Nieder
Message 9 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.