aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-12-05 15:39:41 +0100
committerJosé Valim <jose.valim@gmail.com>2011-12-05 15:39:41 +0100
commitd4964b338667fb14d7755cd90af88bb267238958 (patch)
tree5dc5ca1004da0db180daac96af1a01659b431322 /activemodel/lib/active_model
parent2985151000b9949474b8b575e25bf7ced387da02 (diff)
downloadrails-d4964b338667fb14d7755cd90af88bb267238958.tar.gz
rails-d4964b338667fb14d7755cd90af88bb267238958.tar.bz2
rails-d4964b338667fb14d7755cd90af88bb267238958.zip
Namespaced attribute lookup now works as 'model/association.attribute'.
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r--activemodel/lib/active_model/translation.rb20
1 files changed, 14 insertions, 6 deletions
diff --git a/activemodel/lib/active_model/translation.rb b/activemodel/lib/active_model/translation.rb
index d776fe0ce6..02b7c54d61 100644
--- a/activemodel/lib/active_model/translation.rb
+++ b/activemodel/lib/active_model/translation.rb
@@ -43,17 +43,25 @@ module ActiveModel
#
# Specify +options+ with additional translating options.
def human_attribute_name(attribute, options = {})
- defaults = []
- lookup_ancestors.each do |klass|
- if attribute.match(/\./)
- defaults << :"#{self.i18n_scope}.attributes.#{klass.model_name.i18n_key}.#{attribute.gsub(/\./, '/')}"
+ defaults = []
+ parts = attribute.to_s.split(".", 2)
+ attribute = parts.pop
+ namespace = parts.pop
+
+ if namespace
+ lookup_ancestors.each do |klass|
+ defaults << :"#{self.i18n_scope}.attributes.#{klass.model_name.i18n_key}/#{namespace}.#{attribute}"
+ end
+ defaults << :"#{self.i18n_scope}.attributes.#{namespace}.#{attribute}"
+ else
+ lookup_ancestors.each do |klass|
+ defaults << :"#{self.i18n_scope}.attributes.#{klass.model_name.i18n_key}.#{attribute}"
end
- defaults << :"#{self.i18n_scope}.attributes.#{klass.model_name.i18n_key}.#{attribute}"
end
defaults << :"attributes.#{attribute}"
defaults << options.delete(:default) if options[:default]
- defaults << attribute.to_s.humanize
+ defaults << attribute.humanize
options.reverse_merge! :count => 1, :default => defaults
I18n.translate(defaults.shift, options)