Class: AwesomeTranslations::Handlers::BaseHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/awesome_translations/handlers/base_handler.rb

Instance Method Summary collapse

Instance Method Details

#add_translations_for_hash(dir, _group, yielder, hash) ⇒ Object



2
3
4
# File 'lib/awesome_translations/handlers/base_handler.rb', line 2

def add_translations_for_hash(dir, _group, yielder, hash)
  translations_for_hash_recursive(dir, hash[:translations], yielder, [])
end

#enabled?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/awesome_translations/handlers/base_handler.rb', line 33

def enabled?
  true
end

#translations_for_hash_recursive(dir, hash, yielder, current_keys) ⇒ Object



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
# File 'lib/awesome_translations/handlers/base_handler.rb', line 6

def translations_for_hash_recursive(dir, hash, yielder, current_keys)
  hash.each do |key, value|
    current_keys << key

    if value.is_a?(Hash)
      translations_for_hash_recursive(dir, value, yielder, current_keys)
    elsif value.is_a?(Array)
      value.each_index do |index|
        yielder << AwesomeTranslations::Translation.new(
          dir: dir,
          key: "#{current_keys.join('.')}[#{index}]",
          key_show: "#{current_keys.join('.')}[#{index}]"
        )
      end
    else
      yielder << AwesomeTranslations::Translation.new(
        dir: dir,
        key: current_keys.join("."),
        key_show: current_keys.join("."),
        default: value
      )
    end

    current_keys.pop
  end
end