diff options
author | José Valim <jose.valim@gmail.com> | 2012-04-28 09:00:14 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2012-04-28 09:00:14 -0700 |
commit | 71cf6ef1f5c29a8d318f2ff9390f56f768edb963 (patch) | |
tree | ae0fdb3a5125d00f59f74b9cae7cac3342366a3e /activemodel/lib/active_model/translation.rb | |
parent | 9fc9e894771d1915fe3e565305424ed9ca537b79 (diff) | |
parent | f48d83b5996f34103fc7c725a098a3e9a4062703 (diff) | |
download | rails-71cf6ef1f5c29a8d318f2ff9390f56f768edb963.tar.gz rails-71cf6ef1f5c29a8d318f2ff9390f56f768edb963.tar.bz2 rails-71cf6ef1f5c29a8d318f2ff9390f56f768edb963.zip |
Merge pull request #6035 from carlosantoniodasilva/amo-translation-refactor
Refactor AMo::Translation, avoid changing options in human attr name
Diffstat (limited to 'activemodel/lib/active_model/translation.rb')
-rw-r--r-- | activemodel/lib/active_model/translation.rb | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/activemodel/lib/active_model/translation.rb b/activemodel/lib/active_model/translation.rb index 02b7c54d61..6f0ca92e2a 100644 --- a/activemodel/lib/active_model/translation.rb +++ b/activemodel/lib/active_model/translation.rb @@ -1,5 +1,3 @@ -require 'active_support/core_ext/hash/reverse_merge' - module ActiveModel # == Active Model Translation @@ -43,19 +41,20 @@ module ActiveModel # # Specify +options+ with additional translating options. def human_attribute_name(attribute, options = {}) - defaults = [] + options = { :count => 1 }.merge!(options) parts = attribute.to_s.split(".", 2) attribute = parts.pop namespace = parts.pop + attributes_scope = "#{self.i18n_scope}.attributes" if namespace - lookup_ancestors.each do |klass| - defaults << :"#{self.i18n_scope}.attributes.#{klass.model_name.i18n_key}/#{namespace}.#{attribute}" + defaults = lookup_ancestors.map do |klass| + :"#{attributes_scope}.#{klass.model_name.i18n_key}/#{namespace}.#{attribute}" end - defaults << :"#{self.i18n_scope}.attributes.#{namespace}.#{attribute}" + defaults << :"#{attributes_scope}.#{namespace}.#{attribute}" else - lookup_ancestors.each do |klass| - defaults << :"#{self.i18n_scope}.attributes.#{klass.model_name.i18n_key}.#{attribute}" + defaults = lookup_ancestors.map do |klass| + :"#{attributes_scope}.#{klass.model_name.i18n_key}.#{attribute}" end end @@ -63,7 +62,7 @@ module ActiveModel defaults << options.delete(:default) if options[:default] defaults << attribute.humanize - options.reverse_merge! :count => 1, :default => defaults + options[:default] = defaults I18n.translate(defaults.shift, options) end end |