How can I translate model names and attributes of the Rails Engine?

The usual way to translate model names and attributes of a Rails project is:

MyModel.model_name.human MyModel.human_attribute_name :myattribute 

or when you use the form for MyModel:

 form.label :myattribute 

The locale file config/locales/en.yml looks like this:

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

And this works for a regular Rails project. If the same model is part of an Engine called MyEngine , then it will be placed in config/locales/en.yml Engine and with the prefix my_engine:

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

The my_engine prefix works for various translations except when trying to get model or attribute names using the above methods.

I installed a new Rails and Engine project with Rails 3.2.11 to test this, but to no avail.

Does anyone know how to make this work?

+4
source share
1 answer

I got help in the Rails github questions section. This is the answer:

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

All Articles