Module: I18n::Tasks::UnusedKeys

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

Instance Method Summary collapse

Instance Method Details

#unused_keys(locales: nil, strict: nil) ⇒ Object



8
9
10
11
# File 'lib/i18n/tasks/unused_keys.rb', line 8

def unused_keys(locales: nil, strict: nil)
  locales = Array(locales).presence || self.locales
  locales.map { |locale| unused_tree(locale: locale, strict: strict) }.compact.reduce(:merge!)
end

#unused_tree(locale: base_locale, strict: nil) ⇒ Object

Parameters:

  • locale (String) (defaults to: base_locale)
  • strict (Boolean) (defaults to: nil)

    if true, do not match dynamic keys



15
16
17
18
19
20
21
22
# File 'lib/i18n/tasks/unused_keys.rb', line 15

def unused_tree(locale: base_locale, strict: nil)
  used_key_names = used_tree(strict: true).key_names
  collapse_plural_nodes!(data[locale].select_keys do |key, _node|
    !ignore_key?(key, :unused) &&
      (strict || !used_in_expr?(key)) &&
      !used_key_names.include?(depluralize_key(key, locale))
  end)
end