微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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文档部分.

原文地址:https://www.jb51.cc/ruby/270552.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐