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

Odd encoding issue with UTF-8 + gettext yields ? on non-ASCII

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Aug 28, 2010, 21:17 UTC
Message-ID
<AANLkTi=cb5zyKyogdunB6NzWDk99V2hSg-c0vQpwKM-Z@mail.gmail.com>

I'm having an odd encoding issue with gettext on my gettextize-git-mainporcelain branch that hadn't been turned up before because none of the existing messages used non-ASCII translations.

With this in is.po (full version at [is.po]):
    "Content-Type: text/plain; charset=UTF-8\n"
    "Content-Transfer-Encoding: 8bit\n
I do:
    $ msgfmt -o /opt/git/next-gettext/share/locale/is/LC_MESSAGES/git.mo is.po
Which, under an Icelandic locale gives me:
    $ rm -rf /tmp/meh; LANGUAGE= LC_ALL= LANG=is_IS.UTF-8 git init /tmp/meh
    Bj? til t?ma Git lind ? /tmp/meh/.git/
Those "?" characters are actual ASCII question marks.
But if I don't specify an encoding msgfmt will complain:
    $ msgfmt -o /opt/git/next-gettext/share/locale/is/LC_MESSAGES/git.mo is.po
    is.po: warning: Charset missing in header.
                    Message conversion to user's charset will not work.

But git will now emit the non-ASCII characters from its message catalogue. Probably because some component now doesn't try to be smart about encoding.

    $ rm -rf /tmp/meh; LANGUAGE= LC_ALL= LANG=is_IS.UTF-8 git init /tmp/meh
    Bjó til tóma Git lind í /tmp/meh/.git/

That'd probably break under a non-UTF-8 locale, like an ISO-8859-1 one though.

A `hexdump -C` of the two `.mo` files is exactly the same, aside from the charset header. I.e. both contain valid UTF-8 sequences, so the issue is somewhere between the `*.mo` file being read and it being emitted by `libintl` and the `gettext` function.

We're not doing anything odd in our [gettext.c] that I can see that could explain this.

To reproduce it, do:
    git clone --reference ~/g/git git://github.com/avar/git.git next-gettext
    cd next-gettext
    git checkout -t origin/gettextize-git-mainporcelain
    make -j 4 prefix=/tmp/git all install
    rm -rf /tmp/meh; LANGUAGE= LANG=is_IS.utf8 /tmp/git/bin/git init /tmp/meh
Which'll give (as mentioned above):
    Bj? til t?ma Git lind ? /tmp/meh/.git/
But editing out the Content-Type line gives:
    Bjó til tóma Git lind í /tmp/meh/.git/

[gettextize-git-mainporcelain]: http://github.com/avar/git/tree/gettextize-git-mainporcelain] [is.po]: http://github.com/avar/git/blob/gettextize-git-mainporcelain/po/is.po [gettext.c]: http://github.com/avar/git/blob/gettextize-git-mainporcelain/gettext.c

Next: Ævar Arnfjörð Bjarmason
Message 1 of 20 in “Odd encoding issue with UTF-8 + gettext yields ? on non-ASCII”
  1. Ævar Arnfjörð BjarmasonAug 28, 2010
  2. Ævar Arnfjörð BjarmasonAug 28, 2010
  3. Jonathan NiederAug 28, 2010
  4. Jonathan NiederAug 28, 2010
  5. Marcin CieslakAug 28, 2010
  6. Jonathan NiederAug 28, 2010
  7. Ævar Arnfjörð BjarmasonAug 29, 2010
  8. Ævar Arnfjörð BjarmasonAug 29, 2010
  9. Jonathan NiederAug 30, 2010
  10. Ævar Arnfjörð BjarmasonAug 29, 2010
  11. Jonathan NiederAug 29, 2010
  12. Ævar Arnfjörð BjarmasonAug 30, 2010
  13. Jonathan NiederAug 30, 2010
  14. Marcin CieslakAug 30, 2010
  15. Jonathan NiederAug 30, 2010
  16. Ævar Arnfjörð BjarmasonAug 30, 2010
  17. Ævar Arnfjörð BjarmasonAug 30, 2010
  18. Ævar Arnfjörð BjarmasonAug 30, 2010
  19. Jonathan NiederAug 28, 2010
  20. Marcin CieslakAug 28, 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.