Module: Locomotive::SimpleForm::Inputs::FasterTranslate

Included in:
ApiKeyInput, ArrayInput, DocumentPickerInput, RteInput, ToggleInput
Defined in:
lib/locomotive/simple_form.rb

Instance Method Summary collapse

Instance Method Details

#translate_from_namespace(namespace, default = '') ⇒ Object


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/locomotive/simple_form.rb', line 38

def translate_from_namespace(namespace, default = '')
  if (model_names = lookup_model_names)[0] == 'locomotive'
    model_name = model_names.join('.')

    _key = [
      Locomotive::VERSION,
      I18n.locale,
      template.instance_variable_get(:"@virtual_path"),
      lookup_action,
      namespace,
      model_name,
      reflection_or_attribute_name].join('/')

    Rails.cache.fetch(_key) do
      lookups = [:"#{model_name}.#{lookup_action}.#{reflection_or_attribute_name}"]
      lookups << :"#{model_name}.#{reflection_or_attribute_name}"
      lookups << default

      t(lookups.shift, scope: :"#{i18n_scope}.#{namespace}", default: lookups).presence
    end
  else
    super
  end
end