Sha256: b7d82e3ee754b395e248a0b6537066fd1424af0bb45413e8ac67fa333e05c130

Contents?: true

Size: 999 Bytes

Versions: 42

Compression:

Stored size: 999 Bytes

Contents

class AwesomeTranslations::Handlers::BaseHandler
  def add_translations_for_hash(dir, _group, yielder, hash)
    translations_for_hash_recursive(dir, hash[:translations], yielder, [])
  end

  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

  def enabled?
    true
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
awesome_translations-0.0.67 lib/awesome_translations/handlers/base_handler.rb
awesome_translations-0.0.66 lib/awesome_translations/handlers/base_handler.rb
awesome_translations-0.0.65 lib/awesome_translations/handlers/base_handler.rb
awesome_translations-0.0.64 lib/awesome_translations/handlers/base_handler.rb
awesome_translations-0.0.63 lib/awesome_translations/handlers/base_handler.rb
awesome_translations-0.0.62 lib/awesome_translations/handlers/base_handler.rb
awesome_translations-0.0.61 lib/awesome_translations/handlers/base_handler.rb
awesome_translations-0.0.60 lib/awesome_translations/handlers/base_handler.rb
awesome_translations-0.0.59 lib/awesome_translations/handlers/base_handler.rb
awesome_translations-0.0.58 lib/awesome_translations/handlers/base_handler.rb
awesome_translations-0.0.57 lib/awesome_translations/handlers/base_handler.rb
awesome_translations-0.0.56 lib/awesome_translations/handlers/base_handler.rb
awesome_translations-0.0.55 lib/awesome_translations/handlers/base_handler.rb
awesome_translations-0.0.54 lib/awesome_translations/handlers/base_handler.rb
awesome_translations-0.0.53 lib/awesome_translations/handlers/base_handler.rb
awesome_translations-0.0.52 lib/awesome_translations/handlers/base_handler.rb
awesome_translations-0.0.51 lib/awesome_translations/handlers/base_handler.rb
awesome_translations-0.0.50 lib/awesome_translations/handlers/base_handler.rb
awesome_translations-0.0.49 lib/awesome_translations/handlers/base_handler.rb
awesome_translations-0.0.48 lib/awesome_translations/handlers/base_handler.rb