2017-02-09 28 views
1

我有一些模型带有我想要翻译的价格属性。应用默认命名空间ActiveRecord翻译

在我的语言环境中的文件,我有这样的翻译:

de: 
    activerecord: 
    attributes: 
     defaults: 
     price: Preis 

这适用于任何非命名空间模型,如:

Shoe.human_attribute_name(:price) # works! 

但是,它不会为命名空间模型的工作,例如:

Product::Shoe.human_attribute_name(:price) # doesn't translate! 

是否可以保留翻译文件DRY并将默认值应用于命名空间mo dels以及?

回答

0

你可以在你的i18n文件中添加namespace/model这样的:

de: 
    activerecord: 
    attributes: 
     product/shoe: 
     price: Preis 
+0

我必须增加明确的翻译每一个命名空间模式? – SvenDittmer

+0

我相信是的。命名空间的i18n键与非命名空间的键不同。 – MurifoX