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
Comment #1
jhodgdonCan you explain here how it was misused and what needs to be fixed? And preferably, some suggested better doc wording?
Comment #2
Pasquallethe 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_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:
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:
or
note: I do not speak Russian, just learned this with a new web project.
Comment #3
PasqualleComment #4
droplet CreditAttribution: droplet commentedis it a bug?
Comment #5
jhodgdonYes, 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.
Comment #6
Gábor HojtsyWell, 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.
Comment #7
jhodgdonLooking at old issues... Sounds like this is a "works as designed".