Hi,

the documentation for the function format_plural($count, $singular, $plural) mentions that the singular string should be made very clear, to ease translation. The example given in the code is "1 new comment". Note that the $count parameter ("1") is hardcoded in the singular string. The plural string, however, uses correctly "%count new comments".

As a result, the translators do the same and use a fixed value in the singular string instead of the more flexible variable %count. Unfortunately, this approach does not work in all languages. Take for example French: In that language, the singular string is used for an amount of 0 and 1, the plural string is used for all values greater than one. In that language, the above mentioned example would produce a wrong translation for "0 new comments" ("1 nouveau commentaire" instead of "0 nouveau commentaire").

I propose to rephrase that part of the documentation, I've attached a patch to that effect.

I'd be happy to supply more patches for Drupal to replace the hardcoded count in singular strings with the %count parameter.

CommentFileSizeAuthor
format_plural.patch.txt894 bytestoddy

Comments

killes@www.drop.org’s picture

I think the language formula for French shoudl take care of this.

drumm’s picture

Status: Needs review » Closed (won't fix)

Killes: please provide more information on how to do that, if needed.

toddy’s picture

The language formula for French is correct, this does not solve the problem. The formula is "n>1", so it would yield the first translation for both 0 and 1. However, the first translation uses "1 new comment" instead of "%count new comment", so the user always sees the string "1 new comment", regardless whether there are actually 0 or 1 new comments.

Please note that French is not the only language which is affected by this. There are several other languages, mostly from Eastern Europe and Asia, which have an even more complex plural formula. For Russian, the user would always see the string "1 new comment", even if there are 21, 31, 41, or 51 new comments.

I think this is a bug which should be fixed in the documentation, and ideally in the Drupal code as well.

There has also been a bug report against the French translation for exactly this issue, which I just discovered.

toddy’s picture

Oops, sorry, somehow the link to the bug report got lost: http://drupal.org/node/30876