Plural and Select patterns - Nemo64/meteor-translator GitHub Wiki
Variations in translations (because of plural or gender) can be represented by an ICU message-format pattern. There might be some differences so prefer reading this documentation (unless you want to help improving this implementation)
pluralization
friend_count: >
{friends, plural,
=0 {You have no friends!}
one {You have a friend!}
other{You have # friends!}
}
There are 2 ways to tell when which variation should be used. The first is using =0
or =1
etc.. Those can come in handy for special cases like 0. The better way is using the cldr plural rules. The equals variation always has a higher priority though. If no rule matches, other
will be used. This means {var, plural, other{text}}
will always print text
. If there is no other
rule no text will be printed.
Any number variable and arrays can be used for the plural pattern. For arrays the length is used. If the type does not conform the other
rule will be used.
Note the nice way you can define multiline text in yaml. The Symfony Project has a nice documentation for that.
select
Other variations like gender can be represented by the select pattern.
item_add: >
{gender, select,
female{{count, plural, one{She added one item!} other{She added # items!} }}
male {{count, plural, one{He added one item!} other{He added # items!} }}
other {{count, plural, one{They added one item!}other{They added # items!}}}
}
This example combines the select rule with the plural rule. The select rule searches for an exact match meaning gender
must contain female
or male
. If no rule applies other
will be used. If there is no other
rule no text will be printed.