Get list of plural classes
rotsee opened this issue · comments
Feature request: Unless I missed it there is no way to get a list of (cardinal) plural classes available for a language (e.g. ["one", "other"]
for English). This would sometimes be a useful feature.
A quick and dirty workaround:
// Use any countable unit here:
let pluralClasses = Object.keys(cldr.extractUnitPatterns(language).long.unit.massTon)
Absolutely, let's get that in there! Would you like to attempt it?
Kudos for the clever workaround :)
I could give it a try later this spring!
All the relevant information is in https://github.com/papandreou/node-cldr/blob/master/3rdparty/cldr/common/supplemental/plurals.xml and https://github.com/papandreou/node-cldr/blob/a35df229f6734ed43e6018a0be60ef25b56b631c/3rdparty/cldr/common/supplemental/ordinals.xml
You can use the _extractPluralRuleAst
function as a template and just get the count
attributes from the pluralRulesNodes
.
It looks like there's a difference between the set of plural classes within a single locale depending on whether you're looking at cardinals or ordinals, eg. the af
locale has only other
in ordinals.xml, but both one
and other
in plurals.xml
(cardinals). The _extractPluralRuleAst
function already handles this difference via the 2nd parameter.
Overall it shouldn't be too hard to implement. Looking forward to see what you come up with :)