This project is archived and is in readonly mode.
Patch for internationalization (I18n) of label method when binding a form with form_for
Reported by Antonio Espinosa | February 22nd, 2010 @ 03:38 PM
Hello,
I am a newbie in Rails' community and this is my first suggestion to participate to the wonderful Rails' adventure.
The problem I have encountered is that the label method in the form_for helper is not internationalized.
Example
a view:
<% form_for @user, :url => { :controller => :users, :action => :send_signup } do |f| %>
<%= f.label :name %><br />
<%= f.text_field :name %>
<%= f.submit I18n.t(:send) %>
<% end %>
Return label text: NameBut I want Nom because I use the french locale.
My suggestion is to add the support of I18n to the label method:
fr.yml (locale for french)
fr:
activerecord:
attributes:
user:
name: Nom
Original
Version: Rails 2.3.5
File:
../actionpack-2.3.5/lib/action_view/helpers/form_helper.rb
Line 742: content = (text.blank? ? nil : text.to_s) || method_name.humanize
Suggestion
Line 742: content = (text.blank? ? nil : text.to_s) || I18n.t(method_name, :default => method_name.humanize, :scope => [:activerecord, :attributes, object_name])
I hope this will be helpful.
Best regards,
A. Espinosa
Comments and changes to this ticket
-
Antonio Espinosa February 22nd, 2010 @ 05:17 PM
- Title changed from Internationalization (I18n) of label method when binding a form with form_for to Patch for internationalization (I18n) of label method when binding a form with form_for
-
José Valim February 23rd, 2010 @ 09:09 PM
- State changed from new to duplicate
It's on both Rails 2.3 and Rails 3.0. Please wait for the next release.
-
Sebastian February 23rd, 2010 @ 10:06 PM
- Assigned user set to José Valim
José, I'm using actionpack-2.3.5, line 742 in actionpack-2.3.5/lib/action_view/helpers/form_helper.rb still looks like this:
content = (text.blank? ? nil : text.to_s) || method_name.humanize
Or are you talking about 2.3.6?
-
Antonio Espinosa February 24th, 2010 @ 07:07 AM
v 2.3.6
Line 808: I18n.t("helpers.label.#{object_name}.#{method_name}", :default => "").presence
This version use the scope "helpers.label" in the locale file. Why not use the already existing scope "activerecord.attributes" used by Model#human_attribute_name ?
-
José Valim February 24th, 2010 @ 07:08 AM
Because it should be ORM agnostic. What if you are using Datamapper? Your own form object?
-
Antonio Espinosa February 24th, 2010 @ 07:35 AM
So what's your recommandation for not have redundant text in activerecords.attributes and helpers.label scope ? Overload Model#human_attribute_name to use label.section instead of activerecords.attributes ?
Thanks. -
José Valim February 24th, 2010 @ 07:38 AM
The code on 2.3.6 and 3.0.0 searches first in helpers.label and then in activerecord.attribute. Please take a look at the code that you will see it.
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>