ruby-i18n / i18n

Internationalization (i18n) library for Ruby
MIT License
986 stars 411 forks source link

Some translations are returned as hash after 1.7.1 #510

Closed mg-partec closed 4 years ago

mg-partec commented 4 years ago

What I tried to do

I am developing a Rails 5.2 app with English and Italian languages. The translations of some model names fail after updating i18n from 1.7.0 to 1.7.1. Reverting to 1.7.0 fixed the issue.

What I expected to happen

PurchaseOrder.model_name.human count:1 => "Ordine di acquisto" PurchaseOrder.model_name.human count:2 => "Ordini di acquisto"

What actually happened

PurchaseOrder.model_name.human count: 1 => {:one=>"Ordine di acquisto", :other=>"Ordini di acquisto", :limit_order=>"Ordine al limite", :market_order=>"Ordine a mercato", :order_total=>"Totale ordine", :recurring_order=>{:one=>"Ordine ricorrente", :other=>"Ordini ricorrenti"}, :open=>"Ordini aperti", :reorder=>"Riordina"}

PurchaseOrder.model_name.human count: 2 => {:one=>"Ordine di acquisto", :other=>"Ordini di acquisto", :limit_order=>"Ordine al limite", :market_order=>"Ordine a mercato", :order_total=>"Totale ordine", :recurring_order=>{:one=>"Ordine ricorrente", :other=>"Ordini ricorrenti"}, :open=>"Ordini aperti", :reorder=>"Riordina"}

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

Rails 5.2.4 i18n 1.7.1

Issue is solved reverting to 1.7.0

radar commented 4 years ago

Is this still an issue in 1.8.1?

ydkn commented 4 years ago

Still having this issue with 1.8.1

irb(main):007:0> I18n::VERSION
=> "1.8.1"
irb(main):008:0> Device.model_name.human
=> {:one=>"Device", :other=>"Devices", :features=>{:description=>"Description", ...
radar commented 4 years ago

Could you please provide the locale files that you're using? Well, just the relevant parts. That would help me debug this.

ydkn commented 4 years ago

I created a new rails app and added a simple i18n yaml to showcase this issue: https://github.com/ydkn/ruby-i18n-issue-510

It has no views but you can test it using the rails console like the example above:

irb(main):001:0> MyModel.model_name.human(count: 2)
=> {:one=>"My Model Translation", :other=>"My Models Translation", :some_other_key=>{:key=>"Value"}}
radar commented 4 years ago

Thank you. I have confirmed this is indeed broken in 1.8.1. My guess is https://github.com/ruby-i18n/i18n/commit/b7f69f78a5f92976c8fc3c222d863bf5ab8015b7 is responsible. I will look more into this later on.

radar commented 4 years ago

This fix for this has been applied in 1b5e345. Thank you very much for letting me know about the issue and providing some really awesome steps to reproduce it.

The fix has been released in i18n 1.8.2. Please upgrade to this version in your applications.

mg-partec commented 4 years ago

Unfortunately in my case the error seems to be still there. Here is another example:

v 1.8.2 Portfolio.model_name.human count: 2 => {:one=>"Dossier", :other=>"Dossier", :content=>"Contenuto", :earning=>{:one=>"Guadagno", :other=>"Guadagni"}, :mean_paid=>"Media pagato", :total_value=>"Valore totale"}

v 1.7.0 Portfolio.model_name.human count: 2 => "Dossier"

chevinbrown commented 4 years ago

This is still an issue if you've formatted translations like this:

ryan_big:
  one: "Ryan"
  other: "Ryans "
  other_things:
    thing1: "Baloons"

Ryan.model_name.human(count: 2) #=> Hash Removing the nested attributes returns expected behavior.

It seems that translations related to the model, but not necessarily attributes of the model, are nested under the model-key.

radar commented 4 years ago

@chevinbrown Please open a new issue for this, even if it is related. The fix itself may be separate, and so it helps to track that with separate issue numbers.