based on #1295782: Misuse of format_plural() the format_plural needs some more documentation. There was also a similar misuse in Drupal core #103784: Fix misuse of format_plural() in multiple places

maybe we should rename the $singular parameter

also it could be extended with user documentation how to translate it #384866: Clarify documentation for format_plural() (just linked as related issue, do not mix it here, please reopen if you agree)

Comments

jhodgdon’s picture

Status: Active » Postponed (maintainer needs more info)

Can you explain here how it was misused and what needs to be fixed? And preferably, some suggested better doc wording?

Pasqualle’s picture

the problem is with parameter $singular. The parameter is not really a singular form, it would be better to call it plural_formula[0]

The Russian plural formula:

Plural-Forms: nplurals=3; plural=((((n%10)==1)&&((n%100)!=11))?(0):(((((n%10)>=2)&&((n%10)<=4))&&(((n%100)<10)||((n%100)>=20)))?(1):2));\n" 

plural_formula[0] = 1, 21, 31, 41 ..
plural_formula[1] = 2, 3, 4, 22, 23, 24, 32, ..
plural_formula[2] = anything else 5, 6, 7, 8, 9, 10, 11, 12 ..

Translation example
plural_formula[0] : 1 Answer - @count ответ
plural_formula[1] : @count Answers - @count ответa
plural_formula[2] : @count[2] Answers - @count[2] ответов (or just @count, not sure)

so for example 21 Answer is also translated with plural_formula[0]

so, if you use something like this:

plural_formula($count, 'Answer', 'Some answers');

then for $count=21 in Russian you will get t('Answer') [ when it is evident you need t('Some answers') ]

so you should not use plural formula without including the @count in the text
correct formats:

if ($count == 1) {
  t('Answer');
}
else {
  t('Some answer');
}

or

  plural_formula($count, '1 Answer', '@count answers');

note: I do not speak Russian, just learned this with a new web project.

Pasqualle’s picture

Status: Postponed (maintainer needs more info) » Active
droplet’s picture

is it a bug?

jhodgdon’s picture

Issue tags: +Needs backport to D7

Yes, apparently the documentation, and the name of the parameter $singular, are confusing. We can change parameter names even in Drupal 7 (that is essentially documentation, since the API does not change).

So I'd love to see a patch with the concerns in comment #2 addressed.

Gábor Hojtsy’s picture

Well, it is named $singular because the English version passed there *is* singular. That after translation, the first variant will not be singular is a different thing IMHO. So the concern might be that t($singular) looks misleading - but again its just the English singular variant that might become non-singular in a translation AFAIS. Drupal 8 changed the backend and format_plural() to store/retrieve the singular+plural combinations at once, so the source is stored with both together and the translations are stored as all of the translations together in one field, so the source and translation retains a 1-1 relation like for other strings, no need to create extra (unused) mock English plural variants in the DB. So not sure what can be fixed there if anything.

jhodgdon’s picture

Issue summary: View changes
Status: Active » Closed (works as designed)

Looking at old issues... Sounds like this is a "works as designed".