Sha256: b8252dad19f6c463da7357570e05505d531634cfa4e885352904501ab4978608

Contents?: true

Size: 1.01 KB

Versions: 16

Compression:

Stored size: 1.01 KB

Contents

module I18n::Tasks::IgnoreKeys
  # whether to ignore the key
  # will also apply global ignore rules
  # @param [:missing, :unused, :eq_base] ignore_type
  def ignore_key?(key, ignore_type, locale = nil)
    key =~ ignore_pattern(ignore_type, locale)
  end

  # @param type [:missing, :unused, :eq_base] type
  # @param locale [String] only when type is :eq_base
  # @return [Regexp] a regexp that matches all the keys ignored for the type (and locale)
  def ignore_pattern(type, locale = nil)
    ((@ignore_patterns ||= HashWithIndifferentAccess.new)[type] ||= {})[locale] = begin
      global, type_ignore = config[:ignore].presence || [], config["ignore_#{type}"].presence || []
      if type_ignore.is_a?(Array)
        patterns = global + type_ignore
      elsif type_ignore.is_a?(Hash)
        # ignore per locale
        patterns = global + (type_ignore[:all] || []) +
            type_ignore.select { |k, v| k.to_s =~ /\b#{locale}\b/ }.values.flatten(1).compact
      end
      compile_patterns_re patterns
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
i18n-tasks-0.2.19 lib/i18n/tasks/ignore_keys.rb
i18n-tasks-0.2.18 lib/i18n/tasks/ignore_keys.rb
i18n-tasks-0.2.17 lib/i18n/tasks/ignore_keys.rb
i18n-tasks-0.2.15 lib/i18n/tasks/ignore_keys.rb
i18n-tasks-0.2.14 lib/i18n/tasks/ignore_keys.rb
i18n-tasks-0.2.13 lib/i18n/tasks/ignore_keys.rb
i18n-tasks-0.2.12 lib/i18n/tasks/ignore_keys.rb
i18n-tasks-0.2.11 lib/i18n/tasks/ignore_keys.rb
i18n-tasks-0.2.10 lib/i18n/tasks/ignore_keys.rb
i18n-tasks-0.2.9 lib/i18n/tasks/ignore_keys.rb
i18n-tasks-0.2.8 lib/i18n/tasks/ignore_keys.rb
i18n-tasks-0.2.7 lib/i18n/tasks/ignore_keys.rb
i18n-tasks-0.2.6 lib/i18n/tasks/ignore_keys.rb
i18n-tasks-0.2.5 lib/i18n/tasks/ignore_keys.rb
i18n-tasks-0.2.4 lib/i18n/tasks/ignore_keys.rb
i18n-tasks-0.2.3 lib/i18n/tasks/ignore_keys.rb