Rails - 在表单操作中翻译模型名称

Joh*_*ith 8 locale translation ruby-on-rails internationalization

我想使用i18n系统翻译rails表单.

我的模型属性已正确翻译,但是当我想翻译提交操作时,模型名称不会被翻译.

这是我的fr.yml语言环境文件

fr:
  activerecord:
    model:
      character:
        one: "Personnage"
        other: "Personnages"
    attributes:
      character:
        name: "Nom"
        title: "Titre"
        biography: "Biographie"
  helpers:
    submit:
      update: "Mise à jour %{model}"
Run Code Online (Sandbox Code Playgroud)

我的_form.html.erb是

<%= 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 %>
Run Code Online (Sandbox Code Playgroud)

在我的形式,我期待更新按钮是"濑à怨妇Personnage ",但我仍然有"濑à怨妇角色 ".

谢谢你的帮助 !

Chr*_*erg 12

看起来你有一个model应该拥有的地方models.

将你的fr.yml改成这样:

fr:
  activerecord:
    models:
      character:
        one: "Personnage"
        other: "Personnages"
    ...
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请参阅有关活动记录模型的翻译的rails i18n文档部分.