This project is archived and is in readonly mode.
Label form helper and I18n with nested attributes does not work
-
Tsutomu Kuroda
Hi, Anton
The object_name may have plural form before '_attributes'.
You should singularize the base_name like:
base_name = $1.singularizeBut, I propose the following modification:
base_name = object.class.name.underscorebecause the object name can be different from the model name.
-
Anton Bangratz
Thank you,
I have added the suggestions. The tests suggest that the method works - finding where the object comes from was a bit ominous at first glance.
Still, I have two separate patches to implement either solution - anyone will have to apply them in order.
Anton
-
Tsutomu Kuroda
Anton,
I changed my mind about this theme. Now I think that the current implementation is correct.
Here is the relevant code snipet from form_helper.rb:
content = if text.blank? I18n.t("helpers.label.#{object_name}.#{method_name}", :default => "").presence else text.to_s end content ||= if object && object.class.respond_to?(:human_attribute_name) object.class.human_attribute_name(method_name) end content ||= method_name.humanizeThe class method
human_attribute_namelooks into thelang.activerecord.attributes.authornamespace. The YAML file will go as follow:ja: activerecord: attributes: author: name: 名前This is the normal and traditional way to translate the label text.
Alternatively, we can provide texts in the
lang.helpers.label.post[author_attributes]namespace like this:ja: helpers: label: post[author_attributes]: name: 投稿者名We might want to provide other texts for the attributes of the Author model nested in the another model, say Article. In this case, we will modify the YAML file as follows:
ja: helpers: label: post[author_attributes]: name: 投稿者名 article[author_attributes]: name: 筆者名I am happy with this behaviour.
-
Santiago Pastorino
- State changed from new to open
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
Santiago Pastorino
- State changed from open to stale
