comahe-de / i18n4k

Internationalization for Kotlin
Apache License 2.0
78 stars 9 forks source link

Plural-Select-Pattern #45

Closed comahe-de closed 10 months ago

comahe-de commented 12 months ago

It is like a normal select-pattern (#36), but instead of using the number value of the parameter directly, the number is passed to a plural-provider that returns the plural typed of the number.

Predefined return values of the gender-provider

The plural-provider may also return other values, for currently unconsidered cases.

The are two different plural rule types

The default plural provider should be based on the Plural Rules of the Unicode CLDR. They have a large collection of rules for almost all language. They also provide JSON files in a special format for cardinals and ordinals.

There are also projects like this that implement the CLDR rule and parsers for the JSON files. These can be converted to Kotlin.

For cardinals the “plural” key is used in the pattern. For ordinals the “ordinal” key is used.

Example “plural”:

COUNT_BAGS = There {0, plural, one: is | ? are } {0} {0, plural, one: bag | ? bags}.

COUNT_BAGS(1) -> There is 1 bag. COUNT_BAGS(2) -> There are 2 bags.

Example “ordinal”:

METING_NUMBER = This is the {0}{0, ordinal, one: st | two: nd | few: rd | ? th } meeting.

METING_NUMBER(1) -> This is the 1st meeting. METING_NUMBER(4) ->This is the 4th meeting.