gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 04:34:55 25 4
gpt4 key购买 nike

我想使用 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 à jour Personnage ”,但我仍然有“Mise à jour Character ”。

谢谢你的帮助 !

最佳答案

看起来你有一个 model你应该在哪里models .

将您的 fr.yml 更改为如下所示:

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

请参阅 Translations for Active Record Models 上的 rails i18n 文档部分详情。

关于ruby-on-rails - Rails - 在表单操作中翻译模型名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13231778/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com