I want to translate a rails form using i18n system.
My model attributes are translated correctly, but when I want to translate submit actions, the model name is not translated.
Here is my fr.yml locale file
fr:
activerecord:
model:
character:
one: "Personnage"
other: "Personnages"
attributes:
character:
name: "Nom"
title: "Titre"
biography: "Biographie"
helpers:
submit:
update: "Mise à jour %{model}"
My _form.html.erb is
<%= form_for(@character) do |f| %>
<% if @character.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@character.errors.count, "error") %> prohibited this character from being saved:</h2>
<ul>
<% @character.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :biography %><br />
<%= f.text_area :biography, :rows => 8%>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
On my form, I expected the update button to be "Mise à jour Personnage", but I still have "Mise à jour Character".
Thanks for your help !
Looks like you have a model
where you should have models
.
Change your fr.yml to look like this:
fr:
activerecord:
models:
character:
one: "Personnage"
other: "Personnages"
...
See the rails i18n documentation section on Translations for Active Record Models for details.
This is the default behavior of the submit button when used in the form_for tag...it will show the Update Character instead of "Update #{Model.name}"...
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