Browse files

Add a deprecation for nested i18n namespace lookup.

  • Loading branch information...
1 parent 83efad0 commit c19bd4f88ea5cf56b2bc8ac0b97f59c5c89dbff7 @josevalim josevalim committed Jun 11, 2011
Showing with 16 additions and 0 deletions.
  1. +16 −0 activerecord/lib/active_record/railtie.rb
View
16 activerecord/lib/active_record/railtie.rb
@@ -96,5 +96,21 @@ class Railtie < Rails::Railtie
end
end
end
+
+ config.after_initialize do
+ container = :"activerecord.attributes"
+ I18n.t(container, :default => {}).each do |key, value|
+ if value.is_a?(Hash) && value.any? { |k,v| v.is_a?(Hash) }
+ $stderr.puts "[DEPRECATION WARNING] Nested I18n namespace lookup under \"#{container}.#{key}\" is no longer supported"
+ end
+ end
+
+ container = :"activerecord.models"
+ I18n.t(container, :default => {}).each do |key, value|
+ if value.is_a?(Hash)
+ $stderr.puts "[DEPRECATION WARNING] Nested I18n namespace lookup under \"#{container}.#{key}\" is no longer supported"
+ end
+ end
+ end
end
end

12 comments on commit c19bd4f

@jonleighton
Ruby on Rails member

@josevalim Looks like this change or the previous one broke the build :(

@arunagw
Ruby on Rails member

Only this change. As master is green. this change is not in master.

@dennisreimann

What are we supposed to use instead?

@josevalim
Ruby on Rails member
@dennisreimann

Thanks for the quick answer. As far as I can tell this doesn't work for the full_messages on errors of nested objects.

Here's what it was like before:

admin:
    posts:
        title: "Titel"

But now neither of these works:

admin/posts:
    title: "Titel"

admin_posts:
    title: "Titel"

admin:
    posts/title: "Titel"

admin:
    posts_title: "Titel"

What am I missing?

@nearapogee

I too am interested in this.

This works with deprecations:

en:
  activerecord:
    attributes:
      location:
        address:
          street1: "Street"
          city: "City"
          state: "State"
          zip: "Zip"

But this does not:

en:
  activerecord:
    attributes:
      location/address:
        street1: "Street"
        city: "City"
        state: "State"
        zip: "Zip"

And returns the default error message:

Address street1 can't be blank

Instead of:

Street can't be blank

Am I not reading this quite right?

Thanks @josevalim for all your contributions!

@apux

Still no solution for this?

@diegorv

Not working yet... =/

@josevalim
Ruby on Rails member

Patches to fix the nested lookup (as in "address/location") is welcome.

@kuroda

@josevalim, please look at my pull request: #3859

My proposal is to use the translation data like this:

en:
  activerecord:
    attributes:
      location:
        address/street1: "Street"
        address/city: "City"
        address/state: "State"
        address/zip: "Zip"

Because, when Location accepts nested attributes for Address and the street1 attribute has a validation error, the @location.errors.messages has address.street1 as a key.

@graywh

What was the motivation for this deprecation?

@viniciusnz

Just so people are aware, in kuroda's example the only way it worked for me was:

en:
  activerecord:
    attributes:
      location/addresses:
        street1: "Street"

I hope it saves people some hours of debugging... Best,

Please sign in to comment.