diff --git a/remarkable/lib/remarkable/messages.rb b/remarkable/lib/remarkable/messages.rb index 57fbe97..814ea19 100644 --- a/remarkable/lib/remarkable/messages.rb +++ b/remarkable/lib/remarkable/messages.rb @@ -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 diff --git a/remarkable_activerecord/lib/remarkable_activerecord/base.rb b/remarkable_activerecord/lib/remarkable_activerecord/base.rb index 73e16bf..a2dab40 100644 --- a/remarkable_activerecord/lib/remarkable_activerecord/base.rb +++ b/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. # @@ -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 @@ -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