Sha256: 79fa6bbe417deb8361b3cf422effd79ced733b915b9c8fcbe08e8847dba8161c

Contents?: true

Size: 1.16 KB

Versions: 6

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true
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 [nil, :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
    @ignore_patterns[type]        ||= {}
    @ignore_patterns[type][locale] ||= begin
      global = ignore_config.presence || []
      type_ignore = ignore_config(type).presence || []
      patterns = if type_ignore.is_a?(Array)
                   global + type_ignore
                 elsif type_ignore.is_a?(Hash)
                   # ignore per locale
                   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

6 entries across 6 versions & 1 rubygems

Version Path
i18n-tasks-0.9.12 lib/i18n/tasks/ignore_keys.rb
i18n-tasks-0.9.11 lib/i18n/tasks/ignore_keys.rb
i18n-tasks-0.9.10 lib/i18n/tasks/ignore_keys.rb
i18n-tasks-0.9.9 lib/i18n/tasks/ignore_keys.rb
i18n-tasks-0.9.8 lib/i18n/tasks/ignore_keys.rb
i18n-tasks-0.9.7 lib/i18n/tasks/ignore_keys.rb