Support Plurals
chrismccord opened this issue · 4 comments
We could parse the rules for the plurals from CLDR's data. To do this, we could:
- Parse the rules for each language from the
/common/supplemental/plurals.xml
file (in the core.zip archive). - Translate those rules into Elixir functions.
- Create a function that, given a language and a number, return the mnemonic tag for the plural category.
- With the information given in 3, look up the translation.
The data structure for the translations, when there is a plural form that depends on a number, would look like this:
[
en: [
users: [
title: [
one: "There is one user.",
other: "There are %{n} users."
]
]
]
]
Bonus: we could also add support for the categories "zero" and "one", even if they are not in the rules, because, as CLDR says: "[...] pluralized message APIs should also offer the ability to specify at least the 0 and 1 cases explicitly; developers can use that ability whenever these values might occur in a placeholder.".
Some links:
- Introduction for plural rules: http://cldr.unicode.org/index/cldr-spec/plural-rules
- Chart of the language plural rules: http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html
- Specification for the language plural rules: http://www.unicode.org/reports/tr35/tr35-numbers.html#Language_Plural_Rules
These are great ideas! I can't get to them right away, but I'll take a look once I finished up some Phoenix related work.
I began to work on them. You can see a possible way to achieve the number 1 with cldr. I am working on number 2!