Skip to content
Browse files

Bring back i18n_key to avoid regression

  • Loading branch information...
1 parent 4e2bacd commit e413953cac637f5df4f9eae370451d0265fd7c73 @spastorino spastorino committed Mar 30, 2011
View
4 activemodel/lib/active_model/errors.rb
@@ -295,8 +295,8 @@ def generate_message(attribute, type = :invalid, options = {})
end
defaults = @base.class.lookup_ancestors.map do |klass|
- [ :"#{@base.class.i18n_scope}.errors.models.#{klass.model_name.underscore}.attributes.#{attribute}.#{type}",
- :"#{@base.class.i18n_scope}.errors.models.#{klass.model_name.underscore}.#{type}" ]
+ [ :"#{@base.class.i18n_scope}.errors.models.#{klass.model_name.i18n_key}.attributes.#{attribute}.#{type}",
+ :"#{@base.class.i18n_scope}.errors.models.#{klass.model_name.i18n_key}.#{type}" ]
end
defaults << options.delete(:message)
View
8 activemodel/lib/active_model/naming.rb
@@ -2,7 +2,7 @@
module ActiveModel
class Name < String
- attr_reader :singular, :plural, :element, :collection, :partial_path
+ attr_reader :singular, :plural, :element, :collection, :partial_path, :i18n_key
alias_method :cache_key, :collection
def initialize(klass)
@@ -14,6 +14,7 @@ def initialize(klass)
@human = ActiveSupport::Inflector.humanize(@element).freeze
@collection = ActiveSupport::Inflector.tableize(self).freeze
@partial_path = "#{@collection}/#{@element}".freeze
+ @i18n_key = self.underscore.to_sym
end
# Transform the model name into a more humane format, using I18n. By default,
@@ -27,7 +28,7 @@ def human(options={})
@klass.respond_to?(:i18n_scope)
defaults = @klass.lookup_ancestors.map do |klass|
- klass.model_name.underscore.to_sym
+ klass.model_name.i18n_key
end
defaults << options.delete(:default) if options[:default]
@@ -51,6 +52,9 @@ def human(options={})
# BookCover.model_name # => "BookCover"
# BookCover.model_name.human # => "Book cover"
#
+ # BookCover.model_name.i18n_key # => "book_cover"
+ # BookModule::BookCover.model_name.i18n_key # => "book_module.book_cover"
+ #
# Providing the functionality that ActiveModel::Naming provides in your object
# is required to pass the Active Model Lint test. So either extending the provided
# method below, or rolling your own is required..
View
2 activemodel/lib/active_model/translation.rb
@@ -44,7 +44,7 @@ def lookup_ancestors
# 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.underscore}.#{attribute}"
+ :"#{self.i18n_scope}.attributes.#{klass.model_name.i18n_key}.#{attribute}"
end
defaults << :"attributes.#{attribute}"

0 comments on commit e413953

Please sign in to comment.
Something went wrong with that request. Please try again.