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

Re: [PATCH] WIP: begin to translate git with gettext

From
Jeff Epler <jepler@unpythonic.net>
Date
May 18, 2010, 16:40 UTC
Message-ID
<20100518164002.GC20842@unpythonic.net>
In-Reply-To
<4BF24467.7000204@drmicha.warpmail.net>
On Tue, May 18, 2010 at 09:40:23AM +0200, Michael J Gruber wrote:
Show 8 quoted lines
> > -		color_fprintf(s->fp, c, "unmerged:   %s", one);
> > +		color_fprintf(s->fp, c, _("unmerged:   %s"), one);
> 
> I have no experience whatsover with gettext, but it looks quite
> dangerous to me to have printf format specifiers as part of the
> localized text. It means that our programs can crash depending on the
> LANG setting at run time if localisers mess up. We'll never catch this
> unless we run all tests in all languages!

This is exactly how gettext works. Yes, you can get crashes if the translated string does not have the right arguments--and I would not be at all surprised to hear of at least one privilege escalation bug due to a bad message catalog, since printf format errors can be used in such interesting ways.

Anyway, for printf-style formats, 'msgfmt' can be directed to check for
this situation:
    $ cat bad.po
    msgid ""
    msgstr "Content-Type: text/plain; charset=UTF-8\n"
    #,c-format
    msgid "foo %s %d"
    msgstr "föö %d %d"
    $ msgfmt --check-format bad.po
    bad.po:6: format specifications in 'msgid' and 'msgstr' for argument 1 are not the same
    msgfmt: found 1 fatal error
 
> Also, the basic structure of the output should probably be independent
> of the language, preferring consistent structure across languages over
> linguistically consistent structure  within a language.

No, the ability of gettext+printf to use the right structure of the user's language is a strength. For instance, consider the translation into Yoda's locale of the following sentence:

    printf("The %s is %s.\n", "Future", "Clouded");
The proper localized message is
    Clouded the Future is.

Anything else will range from confusing to unintelligible to the native speaker. You get that with gettext by writing

    printf(_("The %s is %s.\n"), _("Future"), _("Clouded"));
together with the message catalog entry
    msgid "The %s is %s.\n"
    msgfmt "%2$s the %1$s is.\n"
Show 5 quoted lines
> >  	if (extra.len) {
> > -		color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "%s", extra.buf);
> > +		color_fprintf(s->fp, color(WT_STATUS_HEADER, s), _("%s"), extra.buf);
> 
> Seriously?

No, that one's a mistake. I did not take care when choosing which strings to mark, because I was mostly interested in showing a proof-of-concept for using gettext to translate core parts of git.

The amount of work to mark all the source files and then to keep the marks up to date should not be underestimated--and that's just the work to enable translators to localize the software. It is important to gauge the interest in the git community in actually doing this work.

As my own primary language is English, I have only a theoretical interest in this feature. However, the existence of translations for gitk and git-gui indicates to me that the community probably does desire this.

Jeff
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 6 of 9 in “WIP: begin to translate git with gettext”
  1. WIP: begin to translate git with gettextJeff Epler, May 17, 2010
  2. Robert BuckMay 17, 2010
  3. Ævar Arnfjörð BjarmasonMay 18, 2010
  4. Michael J GruberMay 18, 2010
  5. Ævar Arnfjörð BjarmasonMay 18, 2010
  6. Jeff EplerMay 18, 2010
  7. Ævar Arnfjörð BjarmasonMay 18, 2010
  8. Ævar Arnfjörð BjarmasonMay 20, 2010
  9. Dévai TamásMay 21, 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.