4

通常的方法来翻译模式和属性Rails项目的名称是:如何翻译Rails引擎的模型和属性名称?

MyModel.model_name.human 

MyModel.human_attribute_name :myattribute 

,或者当您使用形式为MyModel:

form.label :myattribute 

区域设置文件config/locales/en.yml看起来是这样的:

en: 
    activerecord: 
    models: 
     mymodel: 
     one: TranslatedMyModel 
     other: TranslatedMyModels 
    attributes: 
    mymodel: 
     myattribute: translated attribute 

这适用于普通的Rails项目。试图让当

en: 
    my_engine: 
     activerecord: 
     models: 
      mymodel: 
      one: TranslatedMyModel 
      other: TranslatedMyModels 
     attributes: 
     mymodel: 
      myattribute: translated attribute 

的my_engine前缀适用于各种翻译,除了:当同一型号将被称为MyEngine的发动机的一部分,同样会被放入引擎config/locales/en.yml与my_engine前缀模型或属性名称通过上述方法。

我建立了一个新的Rails项目和Engine with Rails 3.2.11来测试,但没有成功。

有谁知道如何使这项工作?

回答

6

我在github的Rails问题部分获得了帮助。这就是答案:

en: 
    activerecord: 
    models: 
     'my_engine/mymodel': 
     one: TranslatedMyModel 
     other: TranslatedMyModels 
    attributes: 
     'my_engine/mymodel': 
     myattribute: translated attribute