• Download Gist
simple_form_option_translations.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
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

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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.