ruby-on-rails – Rails – 在表单操作中翻译模型名称

我想使用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}"

我的_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 %>

在我的表格上,我希望更新按钮是“MiseàjourPersonnage”,但我仍然有“MiseàjourCharacter”.

谢谢你的帮助 !

解决方法

看起来你有一个模型,你应该有模型.

将你的fr.yml改成这样:

fr:
  activerecord:
    models:
      character:
        one: "Personnage"
        other: "Personnages"
    ...

有关详细信息,请参阅Translations for Active Record Models上的rails i18n文档部分.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...