Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Using region code prevents from loading pluralization rules #261

Merged
merged 2 commits into from Dec 20, 2012

Conversation

Projects
None yet
3 participants
Contributor

samleb commented Dec 20, 2012

I'm currently adding support for localizing an application in Chinese.
There are two different YAML files for Chinese:

  • rails/locale/zh-CN.yml
  • rails/locale/zh-TW.yml

On the other hand, there's only one ruby file defining Chinese pluralization rules:

  • rails/pluralization/zh.rb

As our application should be translated in China Chinese (instead of Taiwan Chinese), I'm tempted to use:

I18n.available_locales += [:"zh-CN"]

But then, when playing in the console:

I18n.locale = :"zh-CN"
I18n.translate("i18n.plural.rule")
# => "translation missing: zh-CN.i18n.plural.rule"

The problem here is that the Railtie only loads files with the exact locale including region as basename, therefore loading rails/locale/zh-CN.yml, but not rails/pluralization/zh.rb, which would define the pluralization rules for the zh locale anyway (without region).

One straightforward solution is for the developer to copy the rails/pluralization/zh.rb to the application's config/locales directory (or anywhere on the I18n.load_path) and change it to:

require 'rails_i18n/common_pluralizations/other'

# Change :zh to :"zh-CN"
::RailsI18n::Pluralization::Other.with_locale(:"zh-CN")

Another solution would be to add add those files to the rails-i18n project which would be IMHO simpler and less surprinsing for the application developer.
What's your opinion about this ? Is this documented anywhere ?

Collaborator

kuroda commented Sep 23, 2012

@samleb

I think you are right. If you make changes and send us a pull request, I will accept it as soon as possible.

Contributor

dmilisic commented Nov 26, 2012

I believe all defined locales should have explicitly defined pluralizations, including zh-CN, and also locales with default pluralizations like en, de, etc. This would solve your issues and also #277.

Any thoughts @samleb, @kuroda?

Collaborator

kuroda commented Nov 26, 2012

@dmilisic I agree with you. I thought exactly the same thing when I saw #277.

samleb added some commits Dec 20, 2012

@samleb samleb Add OneOther default pluralization rule and create corresponding loca…
…le pluralization files

This patch is based on rules found at https://github.com/svenfuchs/i18n/blob/master/test/test_data/locales/plurals.rb.
Since "pt", "rm" and "uz" locales are either absent from this file, or don't use this rule, they're not included in this patch.
a4e4b25
@samleb samleb Add pluralization files for locales with region dcbf0e5
Contributor

samleb commented Dec 20, 2012

@kuroda I hope this will help.
As I've tried to explain in the commit message, I've based my work on the pluralization rules found in plurals.rb in the i18n project test data.
Three locales ("pt", "rm" and "uz") were problematic since they were either not present in these rules, or behaved differently.
I guess we could just fix the "pt" locale by creating a pt.rb file using OneWithZeroOther, but the fact that "pt-PT" seem to use OneOther left me little bit perplex…

@kuroda kuroda added a commit that referenced this pull request Dec 20, 2012

@kuroda kuroda Merge pull request #261 from samleb/master
Fix #261 (Using region code prevents from loading pluralization rules)
0888635

@kuroda kuroda merged commit 0888635 into svenfuchs:master Dec 20, 2012

1 check passed

default The Travis build passed
Details
Collaborator

kuroda commented Dec 20, 2012

@samleb Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment