Reading up on ActionView::Helpers::FormHelper, I see that it states:
The text of label will default to the attribute name unless a translation is found in the current I18n locale (through helpers.label..) or you specify it explicitly.
So you should be able to create a translation for a title label on a post resource like this:
app/views/posts/new.html.erb
<% form_for @post do |f| %>
<%= f.label :title %>
<%= f.text_field :title %>
<%= f.submit %>
<% end %>
config/locales/en.yml
en:
helpers:
label:
post:
title: 'Customized title'
or
config/locales/en.yml
en:
activerecord:
attributes:
post:
title: 'Customized title'
Is there any way of automatically extracting all form labels and adding the correct keys for them to the i18n locale files? Similarly to what the i18n-tasks gem does for I18n.t defined keys.
I found a solution which is certainly not going to be a universal solution for anyone wanting to handle all use cases, this one simply handles the default output from a scaffolding generator which produces form labels like this:
<%= form.label :username %>. This is basically an extension for thei18n-tasksgem:lib/tasks/scan_resource_form_labels.rb
config/i18n-tasks.yml
(add this at the bottom of the file)