I'm trying to customize (translate) an active record attribute name in rails 3.1 ("first_name"). Here's beginning of my locale file (config/locales/sv.yml):
"sv":
activerecord:
models:
employee: "Anställd"
attributes:
employee:
first_name: "Förnamn"
I'm sure this file is used by rails because changing translations further down in the file works. Here's the form field erb code that should say "Förnamn" not "First name":
<div class="field">
<%= f.label :first_name %><br />
<%= f.text_field :first_name %>
</div>
Running Employee.human_attribute_name(:first_name)
in rails console returns "First name".
Thank you very much
In Rails 3.1 you can do it this way as well:
<% form_for @post do |f| %>
<%= f.label :title %>
<%= f.text_field :title %>
<%= f.submit %>
<% end %>
en:
helpers:
label:
post:
title: 'Customized title'
This approach is ORM agnostic and works fine for active model (with mongoid for instance).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With