【发布时间】:2018-01-16 18:33:30
【问题描述】:
我有一个看起来像这样的模型:
class Search
validate :customers_are_of_age
def customers
[customer1, customer2]
end
def customers_are_of_age
unless customers.all?(&:of_age)
errors.add(:customers, :not_of_age)
end
end
end
这是一个人为的例子,但突出了我面临的问题。现在我的翻译文件是这样的:
en:
activemodel:
errors:
models:
search:
customers:
not_of_age: "not of age"
de:
activemodel:
errors:
models:
search:
customers:
not_of_age: "nicht im Alter"
这几乎可以正常工作,因为如果我有一个未通过验证的搜索对象,我会收到我想要的消息“未达到年龄的客户”。但是在德语中,我收到消息“Customers nicht im Alter”。
如何翻译“客户”键?我尝试了以下方法无济于事:
activemodel:
errors:
attributes:
search/customers: "Customers"
models:
search:
customers:
not_of_age: "not of age"
这个我也试过了,还是不行:
activemodel:
models:
search:
customers:
one: "Customer"
many: "Customers"
not_of_age: "not of age"
【问题讨论】:
-
activemodel: errors: models: search: customers: "xxxxx"怎么样?这似乎与您的工作结构一致。您向客户展示的两个想法似乎与它不一致。
标签: ruby-on-rails ruby activerecord internationalization