I'm trying to implement locale-specific pluralization rules in I18n & Rails, but I'm having no luck. Here's what I'm doing:
# in config/initializers/locale.rb
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
{
# Force Use of :few key
:ru => {:i18n => {:plural => {:rule => lambda { |n| :few}}}}
}
# in config/locales/ru.yml
ru:
user:
one: One User
few: Few Users
many: Many Users
other: Other Users
# Testing
script/console
>> I18n.locale = :ru ; I18n.t("user", :count => 20)
=> "Other Users"
As you can see, i'm trying to force the :few key(it should return "Few Users"), just to see if this dang pluralizer will work...but no dice :(
Here's the environment I'm running:
Any Ideas?
Tried replicating your problem, and had the same issue. Moved the pluralization rule into the locale file, and worked fine.
Switched the locale file over to the Ruby-style, as the regular YAML didn't seem to like my lambda for some reason.
# config/initializers/locale.rb
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
# config/locales/ru.rb
{
:ru => {
:user => {
:one => "One User",
:few => "Few Users",
:many => "Many Users",
:other => "Other Users"
},
:i18n => {
:plural => {
:rule => lambda { |n| :few }
}
}
}
}
# Testing
$ script/console
Loading development environment (Rails 2.3.8)
>> I18n.locale = :ru; I18n.t("user", :count => 20) #=> "Few Users"
might give that a try and see if it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With