1

I understand Weblate has support for translating a string to all plural forms and I found examples on how to define the keys in .po files. But how can I define plural forms for a string in json format?

I tried multiple variants, an example for English language:

{
  "key" : "A single key"
  "key_plural" : "%d keys"
}

But I just end up with 2 different strings, not two variations of one string as I've seen in the Weblate demo.

So how should I do this properly for English and for other languages with more plural forms (one, few, many, …)

2 Answers2

2

You can not reliably support plurals in this way. Many languages have different number of plurals, so there is no 1:1 mapping to English. To properly support plurals you need to use translation format which can understand it, for example Gettext (this is just an example, actually most of translation formats do support this). You can find more information on plurals in their documentation: http://www.gnu.org/savannah-checkouts/gnu/gettext/manual/html_node/Plural-forms.html

Michal Čihař
  • 9,799
  • 6
  • 49
  • 87
0

Just to add a different example for how this can be done in JavaScript, the messageformat library has support for plural forms, supporting the different cases that can happen in various languages.

For English pluralization you can use it like this:

var pluralMessage = mf.compile("There {NUM_RESULTS, plural, one{is} other{are}} {NUM_RESULTS} {NUM_RESULTS, plural, one{result} other{results}}")

console.log(pluralMessage({ NUM_RESULTS: 1 });
// There is 1 result

console.log(pluralMessage({ NUM_RESULTS: 5 });
// There are 5 result

oneand other are plural categories. Which plural categories are available depends on the pluralization rules of the target language. E.g. in Japanese where there is no grammatical distinction between singular and plural only other{...} would be used, whereas for Czech there are 4 different cases:

  • zero{...}
  • few{...}
  • many{...}:
  • other{...}

See also the documentation for PluralFormat and this overview over Language Plural Rules

phw
  • 430
  • 3
  • 11