Guides on ActiveRecord error I18n seem to be WRONG


#1

Hi everyone.

I was trying to customize AR validation error messages and came across
this kind of message lookup order, which EVERY I18n guide in existence
seems to be giving:

activerecord.errors.messages.models.user.attributes.name.blank
activerecord.errors.messages.models.user.blank
activerecord.errors.messages.blank

I tried to follow that, but, to my surprise, only least-detailed variant
worked: “activerecord.errors.messages.blank”.

After a bit of research I’ve found out that lookup paths for Rails 2.2.2
are different from what’s stated above.

I.e. the ACTUAL paths being used are:

activerecord.errors.models.user.attributes.name.blank
activerecord.errors.models.user.blank
activerecord.errors.messages.blank

My test localization yaml is (model name is ‘script’):

en:
  activerecord:
    errors:
      messages:
        blank: I'm errors.messages.blank

        models:
          script:
            # As documented, doesn't work.
            blank: I'm errors.messages.models.script.blank

            attributes:
              name:
                # As documented, doesn't work.
                blank: I'm
errors.messages.models.script.attributes.name.blank

      models:
        script:
          # Not as documented, but it works.
          blank: I'm errors.MODELS.script.blank

          attributes:
            name:
               # Not as documented, but it works.
               blank: I'm errors.MODELS.script.attributes.name.blank

That kind of discrepancy in I18n guides seems rather serious to me, so
I’m asking everyone who’s in contact with guide authors or wikis to fix
AR message lookup paths in documentation.

If that’s a confusion or version mismatch on my side, please correct me.
I’m using Rails 2.2.2.

Here are some guide links that seem to be WRONG:
http://guides.rails.info/i18n.html
http://rails-i18n.org/wiki/pages/i18n-rails-guide
(and more, just search for ‘activerecord.errors.messages.models.user’)

This page is RIGHT on lookup order:
http://api.rubyonrails.org/classes/ActiveRecord/Errors.html

Alex


#2

Thanks for pointing this out. Saved my day.


#3

Mr. Ronald wrote:

Thanks for pointing this out. Saved my day.

Guide at guides.rails.info has already been fixed by guide maintainer,
Karel.


#4

But isn’t there still an error in
http://rails-i18n.org/wiki/pages/i18n-rails-guide

activerecord.errors.messages.models.user.attributes.name.blank

which should be

activerecord.errors.models.user.attributes.name.blank

right?


#5

On Fri, Mar 20, 2009 at 5:51 PM, Mr. Ronald removed_email_address@domain.invalid wrote:

But isn’t there still an error in
http://rails-i18n.org/wiki/pages/i18n-rails-guide

Yeah don’t rely on that page, it is just draft.

The i18n guide is at http://guides.rubyonrails.org/i18n.html.