ActiveRecord的错误消息:翻译领域 [英] ActiveRecord error messages: translation for fields
问题描述
我已经使用的指令指定 http://guides.rubyonrails.org/i18n.html 翻译我的模型的领域,但标签不来翻译。我做错了。
I've used the instructions specifies in http://guides.rubyonrails.org/i18n.html to translate fields of my model, but the labels doesn't come translated. What I'm doing wrong.
我有一个用户
模型领域名称
,我想将它翻译成巴西葡萄牙语(PT_BR),所以我得到了我pt_br.yml:
I have a User
model with the field name
and I'd like to have it translated to Brazilian Portugues (pt_br), so I got my pt_br.yml:
pt_br:
errors: "Erro!"
activerecord:
models:
user: "Usuário"
attributes:
name: "Nome"
address: "Endereço"
errors:
template:
body: "Por favor, corrija os campos assinalados"
header: "Dados inválidos"
messages:
blank: "é obrigatório"
taken: "já existe"
too_short: "incompleto"
当我到了页面的表单:
<% form_for(@usuario) do |f| %>
<%= f.error_messages %>
<%= f.label :name %>
<%= f.text_field :name %>
<% end %>
我槛已在现场标示为名,而不是诺姆因为我想它是。 我也有
I sill have the field labeled as "name" and not as "Nome" as I'd like it to be. I also have
config.i18n.default_locale = :pt_br
在我的environment.rb
in my environment.rb
缺什么?
推荐答案
您需要在用户命名空间的属性
,即:
pt_br:
activerecord:
attributes:
user:
name: "Nome"
address: "Endereço"
您还可以安装 i18n_label插件自动翻译的标签。
You can also install the i18n_label plugin to automatically translate the labels.
这篇关于ActiveRecord的错误消息:翻译领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!