Skip to content

Commit

Permalink
Do NOT modify collections.
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jun 12, 2009
1 parent 35cdfdf commit 1cd138a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion remarkable/lib/remarkable/messages.rb
Expand Up @@ -85,7 +85,7 @@ def array_to_sentence(array, inspect=false, empty_default='')
two_words_connector = Remarkable.t 'remarkable.core.helpers.two_words_connector'
last_word_connector = Remarkable.t 'remarkable.core.helpers.last_word_connector'

array.map!{|i| i.inspect} if inspect
array = array.map { |i| i.inspect } if inspect

case array.length
when 0
Expand Down
13 changes: 11 additions & 2 deletions remarkable_activerecord/lib/remarkable_activerecord/base.rb
@@ -1,6 +1,7 @@
module Remarkable
module ActiveRecord
class Base < Remarkable::Base
I18N_COLLECTION = [ :attributes, :associations ]

# Provides a way to send options to all ActiveRecord matchers.
#
Expand Down Expand Up @@ -206,12 +207,14 @@ def collection_interpolation #:nodoc:
@spec.send(:described_class)
end

if RAILS_I18N && described_class.respond_to?(:human_attribute_name) && self.class.matcher_arguments[:collection]
if i18n_collection? && described_class.respond_to?(:human_attribute_name)
options = {}

collection_name = self.class.matcher_arguments[:collection].to_sym
if collection = instance_variable_get("@#{collection_name}")
collection.map!{|attr| described_class.human_attribute_name(attr.to_s, :locale => Remarkable.locale).downcase }
collection = collection.map do |attr|
described_class.human_attribute_name(attr.to_s, :locale => Remarkable.locale).downcase
end
options[collection_name] = array_to_sentence(collection)
end

Expand All @@ -227,6 +230,12 @@ def collection_interpolation #:nodoc:
end
end

# Returns true if the given collection should be translated.
#
def i18n_collection? #:nodoc:
RAILS_I18N && I18N_COLLECTION.include?(self.class.matcher_arguments[:collection])
end

end
end
end

0 comments on commit 1cd138a

Please sign in to comment.