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

From: Jeff Epler <[email-masked]>
Date: Tue, 18 May 2010 11:40:02 -0500

On Tue, May 18, 2010 at 09:40:23AM +0200, Michael J Gruber wrote:
> > -		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"

> >  	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