How can I translate model and attribute names of an Rails Engine?

attributes, internationalization, model, rails-engines, ruby-on-rails

Solution

I got help on the Rails issues section on github. This is the answer:

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

Problem

The usual way to translate model and attribute names of a Rails project are: ``` MyModel.model_name.human MyModel.human_attribute_name :myattribute ``` or, when you are using a 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. When the same model would be part of an Engine called `MyEngine`, the same would be put into `config/locales/en.yml` of the Engine and prefixed with 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 via the above mentioned methods. I have set up a fresh Rails project and Engine with Rails 3.2.11 to test that, but without success. Does anybody know how to make this work?

Original source