我尝试使用YAML别名
翻译验证错误消息ru:
activerecord:
models:
user: Пользователь
profile: Профиль
attributes:
profile: &profile_attributes
name: "Отображаемое имя"
ya_login: 'Логин на Яндексе'
description: 'Описание'
user:
password: Пароль
profile_fields:
<<: *profile_attributes
或没有YAML别名,如下所示:
ru:
activerecord:
models:
user: Пользователь
profile: Профиль
attributes:
profile: &profile_attributes
name: "Отображаемое имя"
ya_login: 'Логин на Яндексе'
description: 'Описание'
user:
password: Пароль
profile_fields:
name: "Отображаемое имя"
ya_login: 'Логин на Яндексе'
description: 'Описание
但我收到了:
个人资料ya登录неможетбытьпустым
哪里可能出错?
答案 0 :(得分:1)
我发现这个https://rails.lighthouseapp.com/projects/8994/tickets/5665-label-form-helper-and-i18n-with-nested-attributes-does-not-work帮助我找到了如何翻译嵌套表单。
表单示例:
form_for(@post) do
fields_for(:author) do
label :name
end
end
这对我不起作用:
fr:
activerecord:
attributes:
author:
name: Nom
但这有效:
fr:
helpers:
label:
post[author_attributes]:
name: Nom
如果你想保持干爽:
fr:
activerecord:
attributes:
post:
[...]
author: &author_attributes
name: Nom
helpers:
label:
record[author_attributes]:
<<: *author_attributes
我发现了几个与嵌套表单相关的问题/评论i18n:
https://github.com/rails/rails/pull/3441
https://github.com/rails/rails/commit/c19bd4f88ea5cf56b2bc8ac0b97f59c5c89dbff7
https://github.com/rails/rails/issues/1869
他们应该改进有关如何翻译嵌套表单的文档。