i18n icon indicating copy to clipboard operation
i18n copied to clipboard

Out-of-the-box CLDR pluralization rules

Open ragesoss opened this issue 8 years ago • 5 comments

I started from an InvalidPluralizationData error in my rails app, and realized that it isn't using the CLDR plural rules like I thought it was.

Then I came across https://github.com/svenfuchs/i18n/wiki/Pluralizations:

We still have to figure out how to actually ship a bunch of default pluralizers best...

I'm willing to work on this, as I'd much rather have the standard CLDR rules live upstream instead of copying them into the translation data and maintaining them as the CLDR releases get updated.

My first thought would be to just ship a simple CLDR backend as an alternative to the Pluralization one, like this: https://github.com/ragesoss/i18n/commit/6838e4ba7f240762e178ef46b1dfbc54d7469a21

Is that a viable direction to go?

ragesoss avatar Jun 05 '17 21:06 ragesoss

@ragesoss have you checked: https://github.com/svenfuchs/rails-i18n ?

dmitry avatar Jun 06 '17 20:06 dmitry

@dmitry I had not, thanks! So it looks like although this gem is part of rails by default, the way to get automatic per-language pluralization rules is to explicitly add the rails-i18n gem. (Maybe I will try to do a PR for the Rails guides, because this is something that I did not pick up from http://guides.rubyonrails.org/i18n.html#pluralization)

The unicode pluralization rules aren't a rails-specific thing, though. Should they live here rather than in rails-i18n?

ragesoss avatar Jun 06 '17 21:06 ragesoss

Probably it's a good idea to add/move them to i18n gem, but in that case all those features should be lazy loaded.

dmitry avatar Jun 07 '17 13:06 dmitry

For the feature-wide support of CLDR formatting and localization check out also a twitter gem: https://github.com/twitter/twitter-cldr-rb

dmitry avatar Jun 07 '17 13:06 dmitry

n.b.: rails-i18n doesn't match CLDR's pluralization rules in all cases.

For example, rails-i18n uses its east_slavic rules for bs, which means that it tries to use the many key for 0. However, CLDR doesn't think that many is a valid key for bs at all (source).

Update: This is a bug and will be fixed in https://github.com/svenfuchs/rails-i18n/pull/987

movermeyer avatar Nov 04 '21 01:11 movermeyer