diff options
author | José Valim <jose.valim@gmail.com> | 2011-06-11 17:21:22 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-06-11 18:01:26 +0200 |
commit | 410a42860b7e2b83b37573e5b72d1f1cb93a9f69 (patch) | |
tree | 3aa8bcd9ce92e7367634ea524c088072f60c59e5 /activemodel | |
parent | f5e1548c1bd5645b9a6bf66c8f5fedf801f23218 (diff) | |
download | rails-410a42860b7e2b83b37573e5b72d1f1cb93a9f69.tar.gz rails-410a42860b7e2b83b37573e5b72d1f1cb93a9f69.tar.bz2 rails-410a42860b7e2b83b37573e5b72d1f1cb93a9f69.zip |
Get rid of the alternate namespace lookup.
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/naming.rb | 7 | ||||
-rw-r--r-- | activemodel/lib/active_model/translation.rb | 5 | ||||
-rw-r--r-- | activemodel/test/cases/translation_test.rb | 10 |
3 files changed, 5 insertions, 17 deletions
diff --git a/activemodel/lib/active_model/naming.rb b/activemodel/lib/active_model/naming.rb index c7b9c41f46..4c1a82f413 100644 --- a/activemodel/lib/active_model/naming.rb +++ b/activemodel/lib/active_model/naming.rb @@ -21,7 +21,7 @@ module ActiveModel @partial_path = "#{@collection}/#{@element}".freeze @param_key = (namespace ? _singularize(@unnamespaced) : @singular).freeze @route_key = (namespace ? ActiveSupport::Inflector.pluralize(@param_key) : @plural).freeze - @i18n_key = self.underscore.tr('/', '.').to_sym + @i18n_key = self.underscore.to_sym end # Transform the model name into a more humane format, using I18n. By default, @@ -35,9 +35,8 @@ module ActiveModel @klass.respond_to?(:i18n_scope) defaults = @klass.lookup_ancestors.map do |klass| - [klass.model_name.i18n_key, - klass.model_name.i18n_key.to_s.tr('.', '/').to_sym] - end.flatten + klass.model_name.i18n_key + end defaults << options[:default] if options[:default] defaults << @human diff --git a/activemodel/lib/active_model/translation.rb b/activemodel/lib/active_model/translation.rb index c615311692..6d64c81b5f 100644 --- a/activemodel/lib/active_model/translation.rb +++ b/activemodel/lib/active_model/translation.rb @@ -44,9 +44,8 @@ module ActiveModel # Specify +options+ with additional translating options. def human_attribute_name(attribute, options = {}) defaults = lookup_ancestors.map do |klass| - [:"#{self.i18n_scope}.attributes.#{klass.model_name.i18n_key}.#{attribute}", - :"#{self.i18n_scope}.attributes.#{klass.model_name.i18n_key.to_s.tr('.', '/')}.#{attribute}"] - end.flatten + :"#{self.i18n_scope}.attributes.#{klass.model_name.i18n_key}.#{attribute}" + end defaults << :"attributes.#{attribute}" defaults << options.delete(:default) if options[:default] diff --git a/activemodel/test/cases/translation_test.rb b/activemodel/test/cases/translation_test.rb index 838956bc98..1b1d972d5c 100644 --- a/activemodel/test/cases/translation_test.rb +++ b/activemodel/test/cases/translation_test.rb @@ -76,15 +76,5 @@ class ActiveModelI18nTests < ActiveModel::TestCase Person.model_name.human(options) assert_equal({:default => 'person model'}, options) end - - def test_alternate_namespaced_model_attribute_translation - I18n.backend.store_translations 'en', :activemodel => {:attributes => {:person => {:gender => {:attribute => 'person gender attribute'}}}} - assert_equal 'person gender attribute', Person::Gender.human_attribute_name('attribute') - end - - def test_alternate_namespaced_model_translation - I18n.backend.store_translations 'en', :activemodel => {:models => {:person => {:gender => 'person gender model'}}} - assert_equal 'person gender model', Person::Gender.model_name.human - end end |