加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 19:17:01 所属栏目:百科 来源:网络整理
导读:我想使用i18n系统翻译rails表单. 我的模型属性被正确翻译,但是当我想翻译提交操作时,模型名称不会被翻译. 这是我的fr.yml语言环境文件 fr: activerecord: model: character: one: "Personnage" other: "Personnages" attributes: character: name: "Nom" tit
我想使用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文档部分.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读