Module: I18n::Tasks::Command::Commands::Missing

Includes:
I18n::Tasks::Command::Collection
Included in:
I18n::Tasks::Commands
Defined in:
lib/i18n/tasks/command/commands/missing.rb

Instance Method Summary collapse

Methods included from I18n::Tasks::Command::Collection

included

Instance Method Details

#add_missing(opt = {}) ⇒ Object

Merge base locale first, as this may affect the value for the other locales



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/i18n/tasks/command/commands/missing.rb', line 64

def add_missing(opt = {}) # rubocop:disable Metrics/AbcSize
  [
    [i18n.base_locale] & opt[:locales],
    opt[:locales] - [i18n.base_locale]
  ].reject(&:empty?).each_with_object(i18n.empty_forest) do |locales, added|
    forest = i18n.missing_keys(locales: locales, **opt.slice(:types, :base_locale))
                 .set_each_value!(opt[:'nil-value'] ? nil : opt[:value])
    if opt[:pattern]
      pattern_re = i18n.compile_key_pattern(opt[:pattern])
      forest.select_keys! { |full_key, _node| full_key =~ pattern_re }
    end
    i18n.data.merge! forest
    added.merge! forest
  end.tap do |added|
    log_stderr t('i18n_tasks.add_missing.added', count: added.leaves.count)
    print_forest added, opt
  end
end

#missing(opt = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/i18n/tasks/command/commands/missing.rb', line 30

def missing(opt = {})
  forest = i18n.missing_keys(**opt.slice(:locales, :base_locale, :types))
  if opt[:pattern]
    pattern_re = i18n.compile_key_pattern(opt[:pattern])
    forest.select_keys! { |full_key, _node| full_key =~ pattern_re }
  end
  print_forest forest, opt, :missing_keys
  :exit1 unless forest.empty?
end

#translate_missing(opt = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/i18n/tasks/command/commands/missing.rb', line 45

def translate_missing(opt = {})
  missing = i18n.missing_diff_forest opt[:locales], opt[:from]
  if opt[:pattern]
    pattern_re = i18n.compile_key_pattern(opt[:pattern])
    missing.select_keys! { |full_key, _node| full_key =~ pattern_re }
  end
  translated = i18n.translate_forest missing, from: opt[:from], backend: opt[:backend].to_sym
  i18n.data.merge! translated
  log_stderr t('i18n_tasks.translate_missing.translated', count: translated.leaves.count)
  print_forest translated, opt
end