aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2012-05-29 23:26:26 -0700
committerJosé Valim <jose.valim@gmail.com>2012-05-29 23:26:26 -0700
commit555d8152c79eabc575413a0ddd199ac8304d776b (patch)
treed8ea15c1bb1301336f11e43c84d7b6c6ffb5d743
parent70bc0d7a4f60ee9c5ca7538eb55b4dae96d7a985 (diff)
parentb0e2fc843b555f94a4472ed50b337dc5048c8b8c (diff)
downloadrails-555d8152c79eabc575413a0ddd199ac8304d776b.tar.gz
rails-555d8152c79eabc575413a0ddd199ac8304d776b.tar.bz2
rails-555d8152c79eabc575413a0ddd199ac8304d776b.zip
Merge pull request #5843 from kuroda/translation_of_deeply_nested_model_attributes
Fix human attribute_name to handle deeply nested attributes
-rw-r--r--activemodel/lib/active_model/translation.rb4
-rw-r--r--activemodel/test/cases/translation_test.rb5
2 files changed, 7 insertions, 2 deletions
diff --git a/activemodel/lib/active_model/translation.rb b/activemodel/lib/active_model/translation.rb
index 6f0ca92e2a..7a86701f73 100644
--- a/activemodel/lib/active_model/translation.rb
+++ b/activemodel/lib/active_model/translation.rb
@@ -42,9 +42,9 @@ module ActiveModel
# Specify +options+ with additional translating options.
def human_attribute_name(attribute, options = {})
options = { :count => 1 }.merge!(options)
- parts = attribute.to_s.split(".", 2)
+ parts = attribute.to_s.split(".")
attribute = parts.pop
- namespace = parts.pop
+ namespace = parts.join("/") unless parts.empty?
attributes_scope = "#{self.i18n_scope}.attributes"
if namespace
diff --git a/activemodel/test/cases/translation_test.rb b/activemodel/test/cases/translation_test.rb
index 4999583802..fd833cdd06 100644
--- a/activemodel/test/cases/translation_test.rb
+++ b/activemodel/test/cases/translation_test.rb
@@ -56,6 +56,11 @@ class ActiveModelI18nTests < ActiveModel::TestCase
assert_equal 'person gender attribute', Person::Gender.human_attribute_name('attribute')
end
+ def test_translated_deeply_nested_model_attributes
+ I18n.backend.store_translations 'en', :activemodel => {:attributes => {:"person/contacts/addresses" => {:street => 'Deeply Nested Address Street'}}}
+ assert_equal 'Deeply Nested Address Street', Person.human_attribute_name('contacts.addresses.street')
+ end
+
def test_translated_nested_model_attributes
I18n.backend.store_translations 'en', :activemodel => {:attributes => {:"person/addresses" => {:street => 'Person Address Street'}}}
assert_equal 'Person Address Street', Person.human_attribute_name('addresses.street')