change/linguist

Support Plurals

chrismccord opened this issue · 4 comments

Support Plurals

We could parse the rules for the plurals from CLDR's data. To do this, we could:

  1. Parse the rules for each language from the /common/supplemental/plurals.xml file (in the core.zip archive).
  2. Translate those rules into Elixir functions.
  3. Create a function that, given a language and a number, return the mnemonic tag for the plural category.
  4. 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:

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!

This feature was added in 860a979.