我使用rails-i18n宝石来使用:hr作为我的主要语言。
gem起作用,但对于header message则不行。
( 4 errors prohibited this list from being saved:部分)
这就是我在提交带有无效分布的表单时得到的结果:
4 errors prohibited this list from being saved: #doesn't translate
Field1 ne smije biti prazan #translates/presence
Field2 ne smije biti prazan #translates/presence
Field3 ne smije biti prazan #translates/presence
Filed4 nije odgovarajuće duljine (treba biti 11 znakova) #translates/length至于代码,我只将config.i18n.default_locale = :hr添加到config/application.rb中。
在文件中说:
下列地区已完成: bs,da,en,en-US,es-PA,hr,is,ja,nl,sr,ur,zh-HK
使用其他语言环境进行测试,但仍然不能翻译4 errors prohibited this list from being saved:部分。
是我做错了什么,还是.yml文件中缺少翻译?
注意:我使用rails 4.0.0
更新:
<%= form_for(@report) do |f| %>
<% if @report.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@report.errors.count, "error") %> prohibited this list from being saved:</h2>
<ul>
<% @report.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="form-container">
<div class="inline half">
<div class="field">
<%= f.label :field1 %><br>
<%= f.text_field :field1 %>
</div>
<div class="field">
<%= f.label :field2 %><br>
<%= f.text_field :field2 %>
</div>
<div class="field">
<%= f.label :field3 %><br>
<%= f.text_field :field3 %>
</div>
<div class="field">
<%= f.label :field4 %><br>
<%= f.text_field :field4 %>
</div>
</div>
<div class="inline half">
<div class="actions">
<%= f.submit "Create", class: "continue-button" %>
</div>
</div>
</div>
<% end %>发布于 2013-12-19 16:48:22
由于某些字段的翻译很清楚,我认为您必须查找“禁止的错误.”消息。此消息应该在您的activerecord.hr.yml文件中,应该如下所示
hr:
errors:
messages:
not_saved:
one: '1 error prohibited this %{resource} from being saved:'
other: '%{count} errors prohibited this %{resource} from being saved:'(但在你的语言中)
现在在您的视图中更改代码
= pluralize(@report.errors.count, "error") %> prohibited this list from being saved:转到
t('errors.messages.not_saved', count: @report.errors.count, resource: Report.model_name.human)为了获得翻译成匈牙利语的Report.model_name.human中提到的“报告”,您应该在hr.yml文件中添加一些内容,如
activerecord:
models:
report: Translation of report in Hungarian
reports: Translation of reports in Hungarian这应该给你完全的灵活性..。
发布于 2013-12-23 16:31:31
您可以尝试将<%= pluralize(@report.errors.count, "error") %> prohibited this list from being saved:更改为<%= t( :errors, :count => @report.errors.count, :model => t("model.Report")) %>,它将从以下地方获取模型和错误
hr:
model:
Report: "Report"
errors:
one: "%{model} can't be saved... 1 error custom message."
other: "%{model} can't be saved for %{count} custom errors"https://stackoverflow.com/questions/20676111
复制相似问题