Class: PhraseApp::InContextEditor::FallbackKeysFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/phraseapp-in-context-editor-ruby/fallback_keys_fetcher.rb

Class Method Summary collapse

Class Method Details

.extract_fallback_keys(key, options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/phraseapp-in-context-editor-ruby/fallback_keys_fetcher.rb', line 5

def self.extract_fallback_keys(key, options)
  fallback_items = []
  if options.has_key?(:default)
    if options[:default].kind_of?(Array)
      fallback_items = options[:default]
    else
      fallback_items << options[:default]
    end
  end

  return fallback_items.map{ |item| process_fallback_item(item, key, options) }.flatten.uniq
end

.process_fallback_item(item, key, options) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/phraseapp-in-context-editor-ruby/fallback_keys_fetcher.rb', line 18

def self.process_fallback_item(item, key, options)
  fallback_keys = []
  if item.kind_of?(Symbol)
    fallback_key_name = item.to_s
    if options.has_key?(:scope)
      if options[:scope].is_a?(Array)
        fallback_key_name = "#{options[:scope].join(".")}.#{item}"
      else
        fallback_key_name = "#{options[:scope]}.#{item}"
      end
    end
    fallback_keys << fallback_key_name

    if key == "helpers.label.#{fallback_key_name}" # http://apidock.com/rails/v3.1.0/ActionView/Helpers/FormHelper/label
      fallback_keys << "activerecord.attributes.#{fallback_key_name}"
    end

    if key.start_with?("simple_form.") # special treatment for simple form
      fallback_keys << "activerecord.attributes.#{item}"
    end
  end

  return fallback_keys
end