Function format_plural is useable only if language has only one plural case (English), but I need to use it for Czech language what has (like most languages from slovenian and roman family) more cases for plural.

For example English has two cases:

  • 1: bed
  • 2-∞: beds

But in Czech we needs more cases for the same word:

  • 1: postel
  • 2-4: postele
  • 5-∞: postelí

And the schema is usually different for different words. (Mistake, it is the same for all words in one language, but different between languages.)

Is there some API in core or in some module that can translate this (for Americans crazy :-)) cases?

  • It does seem to be supported if you read through the comments on format_plural and this issue. I haven't tried it but it looks like you might use something like format_plural('1 bed', '@count beds', $count) and then add translations like '1 bed' => '1 postel', '@count[1] beds' => '@count[1] postele', '@count[2] beds' => '@count[2] postelí. Or similar – Clive Feb 17 '17 at 19:15

format_plural() does support multiple plural versions in general.

format_plural() only has arguments for singular and plural because english only has those two and the input is always english, Drupal does not support translating interface text from another language than english.

However, it is something that defined per language and not per word, that doesn't work. I'm not aware of a workaround that can handle per-word differences.

Actually, according to https://en.wikipedia.org/wiki/Czech_declension#Plural_forms, those rules (1, 2-4, 5+) are always the same? So that should just work.

This is how it looks in the UI

Translate example

  • Aha, really all the different rules are always the same limits (1, 2-4, 5+). You just learned me something new about my language. :-) However it does not help us, we still need to deal with two plural forms and still be compatible with languages like English. – Bobík Feb 18 '17 at 13:14
  • I just added a screenshot how it looks for me when adding Czech as a language and importing translations. As I said, the input for format_plural() is english, but the output will use the correct plural form for the target language – Berdir Feb 18 '17 at 13:32
  • Btw, this works only for D8? I can not see this options in a translation form in a D7. – Bobík Feb 18 '17 at 22:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.