Hi all,
I just ran into the same problem. For the record, this issue was
already mentioned in Nov 2008, without a solution:
http://groups.google.com/group/rails-i18n/browse_thread/thread/fbc0686719e56576/4672753e697e424c?lnk=gst&q=model+name+underscore#4672753e697e424c
From a quick look at the code (Rails 2.3.2), I think I have found the
cause, looks like a bug with a simple fix.
The "error_messages_for" is in the file:
# File vendor/rails/actionpack/lib/action_view/helpers/
active_record_helper.rb
Here is a short snippet:
192: I18n.with_options :locale => options[:locale], :scope
=> [:activerecord, :errors, :template] do |locale|
193: header_message = if options.include?(:header_message)
194: options[:header_message]
195: else
196: object_name = options[:object_name].to_s.gsub('_',
' ')
197: object_name = I18n.t(object_name, :default =>
object_name, :scope => [:activerecord, :models], :count => 1)
198: locale.t :header, :count => count, :model =>
object_name
On line 196, the underscore of the object_name is replaced by a space,
*before* the translation happens. That is why it worked when you used
"web site" as a key, instead of an underscore.
I am pretty sure we can call this a bug. The proper code should be
something like:
196: object_name = options[:object_name]
197: object_name = I18n.t(object_name, :default =>
object_name.to_s.gsub('_', ' '), :scope =>
[:activerecord, :models], :count => 1)
I'll open a bug report.
Meanwhile, the temporary workaround is: simply define your translation
twice: with the underscore (used human_name and other {{model}}
interpolations), and with spaces instead (used by the above buggy
code):
activerecord:
models:
web_site: "sito web"
web site: "sito web"
HTH.
--
Yves-Eric
On Mar 29, 11:04 pm, Andrea <
Andre...@gmail.com> wrote:
> Hello guys, i've noticed a problem with modelsnametranslation withunderscore... in my forms in case of errors mymodel"web_site" dont
> get translated to "sito web". If instead i write in the locale file
> "web site", withoutunderscore, themodelnameget translated. The
> main problem is with error_form_for.
>
> Dont Work:
>
> activerecord:
> models:
> web_site: "sito web" <-- error because there is the _underscore
>
> Work:
>
> activerecord:
> models:
> web site: "sito web" <-- work because web_sitemodelnameis
> without _underscore
>
> Someone know a workaround? Actually my solution is to write 2 times
> themodelnametranslation, one withunderscore, and one without for
> error_message_for