twitter/twitter-cldr-rb — pull request #14 by KL-7 (2012-04-07 23:13:15+00:00)
Title: Pluralization

I tried to lay the ground for pluralization formatter. It's just a beginning and **not yet ready** for merging. This PR is more for discussion as I already have a couple of questions:

1. Currently number and the noun in the correct pluralization form are simply joined, but I'm going to make `format` method accepting real patterns where the number will replace some placeholder so the words order and phrasing can be adjusted by passing a language-specific patterns hash. After that is done instead of calling

f.format(1, :one => 'ball')

one would do smth like

f.format(1, :one => '{0} ball')

I assume that for this purpose existing tokenizers can be used, but I need to dig into that a bit more. What I want to know now is whether the overall idea is right.

2. Is raising an exception when required pattern is not found is a good idea? I'm asking because I don't see much exceptions across the project. Should some default value or `nil` be returned instead in that case?

3. Interface with `format` method accepting a number and a hash of patterns is a good start, but if someone need to format phrases with the same word (and therefore the same patterns hash) over and over it might be annoying to pass this hash every time or to store it somewhere outside of formatter object.

If, e.g., someone needs to format different amounts of hours across the project it might be easier to setup formatter with the proper patterns in constructor and then pass to `format` method only a number. Drawback of this solution is that it requires one formatter for every word that needs to be formatted and it doesn't sound good if someone wants to pluralize a lot of different words simultaneously.

What if we provide some interface for setting up formatter with a specific locale and a dictionary of words for every one of which user provides a patterns hash? Then he can use it like `f.format(1, 'hour')` and the formatter will find proper set of patterns for this word, pluralization rules for the number, choose pattern for this rule, and format the final phrase.

May be the interface won't be exactly like that but I'd be happy to hear your thoughts on that.