ActiveRecord models localization

Updated . Posted . Visible to the public. Repeats.

Suppose we have some model and we want to localize it, first of all we need to now i18n_key for that model. Open rails console rails c, and run:

OurModelName.model_name.i18n_key

For example let's do that for model, defined in public_activity gem:

PublicActivity::Activity.model_name.i18n_key
#=> :"public_activity/activity"

Now, we cat easily localize it, by adding this in .yaml file:

activerecord:
  models:
    public_activity/activity: 'Our localized model name'

In the same way we can localize attributes for that model:

activerecord:
  attributes
    public_activity/activity:
      attribute: 'localized attribute name'
konjoot
Last edit
konjoot
Posted by konjoot to wiki (2014-04-09 11:35)