Avoid translating each key in the collection, just lookup once

This commit is contained in:
Carlos Antonio da Silva 2012-01-24 15:23:45 -02:00
parent 68b9f6c098
commit fb3e4f61cb
1 changed files with 9 additions and 5 deletions

View File

@ -66,10 +66,9 @@ module SimpleForm
end
def detect_common_display_methods(collection_classes = detect_collection_classes)
if collection_classes == [Symbol]
translate_collection
{ :label => :first, :value => :last }
elsif collection_classes.include?(Array)
collection_translated = translate_collection if collection_classes == [Symbol]
if collection_translated || collection_classes.include?(Array)
{ :label => :first, :value => :last }
elsif collection_includes_basic_objects?(collection_classes)
{ :label => :to_s, :value => :to_s }
@ -92,7 +91,12 @@ module SimpleForm
end
def translate_collection
@collection = collection.map { |value| [translate(:options, value.to_s), value.to_s] }
if translated_collection = translate(:options)
@collection = collection.map do |key|
[translated_collection[key] || key, key]
end
true
end
end
end
end