Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
diff --git a/lib/simple_form/inputs/base.rb b/lib/simple_form/inputs/base.rb
index 40c3e3f..4e12cf1 100644
--- a/lib/simple_form/inputs/base.rb
+++ b/lib/simple_form/inputs/base.rb
@@ -130,13 +130,16 @@ module SimpleForm
joined_model_names = model_names.join(".")
model_names.shift
- lookups << :"#{joined_model_names}.#{lookup_action}.#{reflection_or_attribute_name}"
+ lookups << :"#{joined_model_names}.#{lookup_action}.#{reflection_or_attribute_name}" unless namespace == :options
lookups << :"#{joined_model_names}.#{reflection_or_attribute_name}"
end
lookups << :"#{reflection_or_attribute_name}"
lookups << default
- I18n.t(lookups.shift, :scope => :"simple_form.#{namespace}", :default => lookups).presence
+ lookup = lookups.shift
+ lookup = "#{lookup}.#{default}" if namespace == :options
+
+ I18n.t(lookup, :scope => :"simple_form.#{namespace}", :default => lookups).presence
end
# Extract the model names from the object_name mess, ignoring numeric and
diff --git a/lib/simple_form/inputs/collection_input.rb b/lib/simple_form/inputs/collection_input.rb
index cc6fe1e..258d290 100644
--- a/lib/simple_form/inputs/collection_input.rb
+++ b/lib/simple_form/inputs/collection_input.rb
@@ -29,7 +29,18 @@ module SimpleForm
def collection
@collection ||= begin
collection = options.delete(:collection) || self.class.boolean_collection
- collection.respond_to?(:call) ? collection.call : collection.to_a
+ collection = collection.respond_to?(:call) ? collection.call : collection.to_a
+
+ if collection.is_a?(Array)
+ if collection.map(&:class).include?(Array)
+ collection.map { |label, value| [label.is_a?(Symbol) ? translate(:options, label) : label, value] }
+ else
+ collection.map { |label| [label.is_a?(Symbol) ? translate(:options, label) : label, label] }
+ end
+ else
+ collection
+ end
+
end
end
@josevalim

Possible suggestion:

if collection.is_a?(Array)
  collection.map { |item| translate_item(item) }
else
  collection
end

def translate_item(item)
  if item.is_a?(Array)
    item.fill(translate_item(item[0]), 0, 1)
  elsif item.is_a?(Symbol)
    # Implement translate
  else
    item
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.