Обсуждение: on gettext plural support
After spending some time with the new plural string translation support, I admit I am confused. I was just going over this string in pg_dump: #: pg_dump.c:5011 #, c-format msgid "expected %d check constraint on table \"%s\" but found %d\n" msgid_plural "expected %d check constraints on table \"%s\" but found %d\n" So I've been assuming that msgstr[0] is for the case where there is one of the pluralizable thing, and msgstr[1] is for the case where there is more than one. This is the correct thing to do for spanish, where I have "Plural-Forms: nplurals=2; plural=n != 1;" So it turns out that for the string above it doesn't make any sense to have the %d being exactly 1: the code is ntups = PQntuples(res); if (ntups != 1) { write_msg(NULL, ngettext("query returned %d row instead of one: %s\n", "query returned %d rows instead of one: %s\n", ntups), ntups, query->data); exit_nicely(); } So ntups is either 0, or it's greater than 1 -- the first message does not really make sense to me ... I'm not really seeing whether I have to cater for the case where there are zero tuples (in which case the english message is not really correct, is it?), or that ntups equals one (which is impossible and thus I could just insult the Pope in that translation and no one would notice), or ...? -- Alvaro Herrera http://www.CommandPrompt.com/ The PostgreSQL Company - Command Prompt, Inc.
Alvaro Herrera wrote: > #: pg_dump.c:5011 > #, c-format > msgid "expected %d check constraint on table \"%s\" but found %d\n" > msgid_plural "expected %d check constraints on table \"%s\" but found %d\n" Sorry, I'm an idiot -- the one I wanted to paste was #: pg_dump.c:6344 pg_dump.c:6543 pg_dump.c:7194 #, fuzzy, c-format msgid "query returned %d row instead of one: %s\n" msgid_plural "query returned %d rows instead of one: %s\n" which actually matches the code fragment I pasted: > ntups = PQntuples(res); > if (ntups != 1) > { > write_msg(NULL, ngettext("query returned %d row instead of one: %s\n", > "query returned %d rows instead of one: %s\n", > ntups), > ntups, query->data); > exit_nicely(); > } -- Alvaro Herrera http://www.CommandPrompt.com/ PostgreSQL Replication, Consulting, Custom Development, 24x7 support
On Sunday 12 April 2009 04:10:07 Alvaro Herrera wrote: > So it turns out that for the string above it doesn't make any sense to > have the %d being exactly 1: the code is > So ntups is either 0, or it's greater than 1 -- the first message does > not really make sense to me ... > > I'm not really seeing whether I have to cater for the case where there > are zero tuples (in which case the english message is not really > correct, is it?), or that ntups equals one (which is impossible and thus > I could just insult the Pope in that translation and no one would > notice), or ...? Yes, there are cases where not all of the plural forms can actually happen in practice. Just like there are a few cases where n == 1 cannot happen, it may be possible to prove in some cass that n >= 5 cannot happen, which would be of interest to Russian, for example. I don't think there is much you can do here. Either leave it out, or write "CANNOT HAPPEN", or just translate normally.
Peter Eisentraut <peter_e@gmx.net> writes: > I don't think there is much you can do here. Either leave it out, or write > "CANNOT HAPPEN", or just translate normally. But Alvaro's complaint that the current coding is incorrect for English still stands, no? Or does ngettext choose the second string for n = 0? regards, tom lane
On Sunday 12 April 2009 18:06:48 Tom Lane wrote: > Peter Eisentraut <peter_e@gmx.net> writes: > > I don't think there is much you can do here. Either leave it out, or > > write "CANNOT HAPPEN", or just translate normally. > > But Alvaro's complaint that the current coding is incorrect for English > still stands, no? Or does ngettext choose the second string for n = 0? In English (i.e., the default case), ngettext chooses the second/plural string for zero. In other languages, it chooses whatever string you configure. For example, in Spanish the recommended formula is Plural-Forms: nplurals=2; plural=n != 1; which is the same as in English. In French and Brazilian Portuguese, the recommended formula is Plural-Forms: nplurals=2; plural=n>1; which means that zero uses the singular form. So those guys should also translate msgstr[0] with the expectation of it being used, because n==0 can happen, even if n==1 cannot.