This project is archived and is in readonly mode.
autosave error messages cannot be translated (i18n)
Reported by Raffael Schmid | March 26th, 2010 @ 12:05 PM
This seems to be similar to #3147.
ActiveRecord::Schema.define do
create_table(:owners) { |o| o.string :username }
create_table(:items) { |i| i.string :property }
end
class Owner < ActiveRecord::Base
has_one :item, :autosave => true
validates_presence_of :username
end
class Item < ActiveRecord::Base
validates_presence_of :property
end
I18n.backend.store_translations :en, :"activerecord.attributes.item.property" => "Testing1"
owner = Owner.new
owner.build_item
owner.valid?
owner.errors.full_messages
item = Item.create
item.errors.full_messages
This code above will result in
["Item property can't be blank", "Username can't be
blank"] and
["Testing1 can't be blank"]
The first output is not as expected. It should be like ["Testing1 can't be blank", "Username can't be blank"].
With the following patch, it works as expected.
Maybe there is a better fix, but this works for my project.
Comments and changes to this ticket
-
Raffael Schmid March 26th, 2010 @ 12:27 PM
- Title changed from nested attributes error messages cannot be looked up to autosave error messages cannot be translated (i18n)
Sorry, patch works for my test in the description but not in my rails-project.
Following patch works for both.
-
José Valim March 26th, 2010 @ 11:01 PM
- State changed from new to invalid
You need to have the translation under "activerecord.attributes.item.property" and "activerecord.attributes.owner.item.property". You can use a symbol to symlink translations (check I18n documentation for more information). Notice that we cannot rely on constantize, since it would fail in some cases like:
has_many :super_projects, :class_name => "Project"
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>