Permalink
Browse files

Refactor human attribute name

  • Loading branch information...
1 parent cafe6a3 commit f48d83b5996f34103fc7c725a098a3e9a4062703 @carlosantoniodasilva carlosantoniodasilva committed Apr 28, 2012
Showing with 7 additions and 7 deletions.
  1. +1 −1 activemodel/lib/active_model/naming.rb
  2. +6 −6 activemodel/lib/active_model/translation.rb
View
2 activemodel/lib/active_model/naming.rb
@@ -54,7 +54,7 @@ def human(options={})
defaults << options[:default] if options[:default]
defaults << @human
- options = {:scope => [@klass.i18n_scope, :models], :count => 1, :default => defaults}.merge(options.except(:default))
+ options = { :scope => [@klass.i18n_scope, :models], :count => 1, :default => defaults }.merge!(options.except(:default))
I18n.translate(defaults.shift, options)
end
View
12 activemodel/lib/active_model/translation.rb
@@ -42,19 +42,19 @@ def lookup_ancestors
# Specify +options+ with additional translating options.
def human_attribute_name(attribute, options = {})
options = { :count => 1 }.merge!(options)
- defaults = []
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

0 comments on commit f48d83b

Please sign in to comment.