From a25ef06956725f5c4c8833f86f61f1f12c4323e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 7 Jan 2010 02:45:50 +0100 Subject: Allow to specify default attributes names translation in I18n yml files. For example, you could easily specify :created_at and :updated_at translations as: en: attributes: created_at: "Created at" updated_at: "Updated at" This configuration is built on ActiveModel, so it means those translations are shared between different ORMs as well (but always as a fallback). --- activemodel/lib/active_model/translation.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'activemodel/lib/active_model/translation.rb') diff --git a/activemodel/lib/active_model/translation.rb b/activemodel/lib/active_model/translation.rb index e5ef1e6114..2d2df269d0 100644 --- a/activemodel/lib/active_model/translation.rb +++ b/activemodel/lib/active_model/translation.rb @@ -25,13 +25,14 @@ module ActiveModel # Specify +options+ with additional translating options. def human_attribute_name(attribute, options = {}) defaults = lookup_ancestors.map do |klass| - :"#{klass.model_name.underscore}.#{attribute}" + :"#{self.i18n_scope}.attributes.#{klass.model_name.underscore}.#{attribute}" end + defaults << :"attributes.#{attribute}" defaults << options.delete(:default) if options[:default] defaults << attribute.to_s.humanize - options.reverse_merge! :scope => [self.i18n_scope, :attributes], :count => 1, :default => defaults + options.reverse_merge! :count => 1, :default => defaults I18n.translate(defaults.shift, options) end -- cgit v1.2.3