ruby-on-railsinternationalizationtranslationpluralize

translating model attributes rails


I got the following problem with my rails application: I want to translate some model attributes like this, so that they show up correctly in the validation error messages for example.

de:
  activerecord:
    models:
      account:
        attributes:
          email:
            one: 'Email'
            other: 'Emails'

Now in the rails console I can check

I18n.t 'activerecord.models.account.attributes.email', count: 1

which returns "Email" and everything seems to be fine.

But in if I go to the browser and post a form, I get the error

I18n::InvalidPluralizationData in AccountsController#create
translation data {:attributes=>{:email=>{:one=>"Email", :other=>"Emails"}}} can not be used with :count => 1

How can I resolve this? What translation data does rails expect to get?

Thanks


Solution

  • Model names and Attribute names both have their own i18n scope.

    Try

    activerecord.attributes.account.email
    

    instead of

    activerecord.models.account.attributes.email
    

    (and adjust your yaml file accordingly).

    See also the handy Rails Guide on the I18n API.

    HTH!