Module: I18n::Tasks::IgnoreKeys

Included in:
BaseTask
Defined in:
lib/i18n/tasks/ignore_keys.rb

Instance Method Summary collapse

Instance Method Details

#ignore_key?(key, ignore_type, locale = nil) ⇒ Boolean

whether to ignore the key will also apply global ignore rules

Parameters:

  • ignore_type (:missing, :unused, :eq_base)

Returns:

  • (Boolean)


7
8
9
# File 'lib/i18n/tasks/ignore_keys.rb', line 7

def ignore_key?(key, ignore_type, locale = nil)
  key =~ ignore_pattern(ignore_type, locale)
end

#ignore_pattern(type, locale = nil) ⇒ Regexp

Returns a regexp that matches all the keys ignored for the type (and locale).

Parameters:

  • type (nil, :missing, :unused, :eq_base)

    type

  • locale (String) (defaults to: nil)

    only when type is :eq_base

Returns:

  • (Regexp)

    a regexp that matches all the keys ignored for the type (and locale)



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/i18n/tasks/ignore_keys.rb', line 14

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 = case type_ignore
               when Array
                 global + type_ignore
               when 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