class Localer::Data::Processor

Parse translations into hash: key: translation key value: hash of locale values

Attributes

data[R]
locales[R]

Public Instance Methods

call() click to toggle source
# File lib/localer/data/processor.rb, line 17
def call
  @data = Hash.new { |hsh, key| hsh[key] = {} }
  @locales = []
  translations.each do |(locale, translation)|
    next unless config.locale[locale.downcase].enabled

    @locales.push locale
    prepare(locale, translation)
  end
  [@locales, @data]
end

Private Instance Methods

exclude?(key, locale) click to toggle source
# File lib/localer/data/processor.rb, line 45
def exclude?(key, locale)
  (config.exclude + config.locale[locale.downcase].exclude).any? do |pattern|
    match?(key, pattern)
  end
end
match?(key, pattern) click to toggle source
# File lib/localer/data/processor.rb, line 51
def match?(key, pattern)
  if (regex = pattern.to_regexp)
    key =~ regex
  else
    key.start_with?(pattern)
  end
end
prepare(locale, translation, prefix = "") click to toggle source
# File lib/localer/data/processor.rb, line 31
def prepare(locale, translation, prefix = "")
  if translation.is_a?(Hash)
    translation.each do |(key, value)|
      full_key = prefix + ".#{key}"
      next if exclude?(full_key, locale)

      prepare(locale, value, full_key)
    end
  else
    # @data[prefix] ||= {}
    @data[prefix][locale] = translation
  end
end