Hi everybody,
In ActionView::Helpers::ActiveRecordHelper's error_messages_for method, the translation key used for getting a model's human name (used in "1 error prohibited this {{model}} from being saved") is resolved like this:
object_name = options[:object_name].to_s.gsub('_', ' ') object_name = I18n.t(object_name, :default => object_name, :scope => [:activerecord, :models], :count => 1)
... where options[:object_name] is the underscore version of the model's name.
This means that if I write this in my locale file, da:yml:
activerecord: models: item_type: 'ting type'
... it won't work as expected because the above mentioned code will generate 'item type' instead of 'item_type' as the first argument when calling the I18n.t method. ItemType.human_name works as expected though.
Instead, if I change my locale file to this:
activerecord: models: item type: 'ting type'
... error_messages_for works as expected, but ItemType.human_name breaks (giving me the default name instead of the translated).
Thus I'm forced to define "item type" and "item_type" in my locale file which isn't very dry.
My suggestion for a fix, would be to replace the above mentioned lines with this one line:
object_name = I18n.t(object_name, :default => options [:object_name].to_s.gsub('_', ' '), :scope => [:activerecord, :models], :count => 1)
This fix should be considered temporarily, as it would be much cooler if the procedure of resolving the translation key was defined only one place (in ActiveRecord::Base#human_name).
So, am I overlooking something or is this to be considered a bug?
Thank you.