Module: I18n::Tasks::Command::Commands::Usages
- Includes:
- I18n::Tasks::Command::Collection
- Included in:
- I18n::Tasks::Commands
- Defined in:
- lib/i18n/tasks/command/commands/usages.rb
Instance Method Summary collapse
- #find(opt = {}) ⇒ Object
-
#remove_unused(opt = {}) ⇒ Object
rubocop:disable Metrics/AbcSize.
- #unused(opt = {}) ⇒ Object
Methods included from I18n::Tasks::Command::Collection
Instance Method Details
#find(opt = {}) ⇒ Object
23 24 25 26 27 |
# File 'lib/i18n/tasks/command/commands/usages.rb', line 23 def find(opt = {}) opt[:filter] ||= opt.delete(:pattern) || opt[:arguments].try(:first) result = i18n.used_tree(strict: opt[:strict], key_filter: opt[:filter].presence, include_raw_references: true) print_forest result, opt, :used_keys end |
#remove_unused(opt = {}) ⇒ Object
rubocop:disable Metrics/AbcSize
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/i18n/tasks/command/commands/usages.rb', line 45 def remove_unused(opt = {}) # rubocop:disable Metrics/AbcSize unused_keys = i18n.unused_keys(**opt.slice(:locales, :strict)) if opt[:pattern] pattern_re = i18n.compile_key_pattern(opt[:pattern]) unused_keys = unused_keys.select_keys { |full_key, _node| full_key =~ pattern_re } end if unused_keys.present? terminal_report.unused_keys(unused_keys) confirm_remove_unused!(unused_keys, opt) i18n.data.config = i18n.data.config.merge(sort: false) if opt[:'keep-order'] removed = i18n.data.remove_by_key!(unused_keys) log_stderr t('i18n_tasks.remove_unused.removed', count: unused_keys.leaves.count) print_forest removed, opt else log_stderr Rainbow(t('i18n_tasks.remove_unused.noop')).green.bright end end |
#unused(opt = {}) ⇒ Object
34 35 36 37 38 |
# File 'lib/i18n/tasks/command/commands/usages.rb', line 34 def unused(opt = {}) forest = i18n.unused_keys(**opt.slice(:locales, :strict)) print_forest forest, opt, :unused_keys :exit1 unless forest.empty? end |