ruby-i18n / i18n

Internationalization (i18n) library for Ruby
MIT License
981 stars 408 forks source link

[BUG] Wrong pluralization logic in i18n files. #564

Closed webzorg closed 3 years ago

webzorg commented 3 years ago

What I tried to do

To reproduce I ran

# Some background information, calling this: 
Item.model_name.human

# invokes this behind scenes from 
I18n.translate("item", :scope=>[:activerecord, :models], :count=>1, :default=>[])

What I expected to happen

Having following locale data

ka: 
  activerecord:
    models:
      item:
        one: "საბიბლიოთეკო ერთეული"
        many: "%{count} საბიბლიოთეკო ერთეული"
        # other: საბიბლიოთეკო ერთეულები

Item.model_name.human should return singular, using one i18n key. Instead it expects count whether I run

Item.model_name.human
Item.model_name.human(count: 2)
# yes, two lines above result in same error, while one should be singular and other should be plural.

What actually happened

Got an error:

I18n::InvalidPluralizationData: translation data {:one=>"საბიბლიოთეკო ერთეული", :many=>"%{count} საბიბლიოთეკო ერთეული"} can not be used with :count => 1. key 'other' is missing.

Versions of i18n, rails, and anything else you think is necessary

I18n::VERSION
=> "1.8.9"

Problem lies in:

gems/ruby-3.0.0/gems/i18n-1.8.9/lib/i18n/backend/pluralization.rb:37
pluralizer.call(count)

always returns :other, which doesn't make sense

Thanks! :heart:

webzorg commented 3 years ago

Solved, not a bug. Found the fault was here:

gems/ruby-3.0.0/gems/rails-i18n-6.0.0/rails/pluralization/ka.rb
# was using 
::RailsI18n::Pluralization::Other.with_locale(:ka)
# instead of 
::RailsI18n::Pluralization::OneOther.with_locale(:ka)