Class: I18n::Tasks::Reports::Terminal
Overview
rubocop:disable Metrics/ClassLength
Defined Under Namespace
Modules: HighlightOther, HighlightUnderline
Constant Summary
Constants included
from Logging
Logging::MUTEX, Logging::PROGRAM_NAME
Instance Attribute Summary
Attributes inherited from Base
#task
Instance Method Summary
collapse
#highlight_string
#highlight_string
Methods inherited from Base
#initialize
Methods included from Logging
log_error, log_stderr, log_verbose, log_warn, program_name, warn_deprecated
Instance Method Details
#check_normalized_results(non_normalized) ⇒ Object
102
103
104
105
106
107
108
109
110
|
# File 'lib/i18n/tasks/reports/terminal.rb', line 102
def check_normalized_results(non_normalized)
if non_normalized.empty?
print_success 'All data is normalized'
return
end
log_stderr Rainbow('The following data requires normalization:').yellow
puts non_normalized
log_stderr Rainbow('Run `i18n-tasks normalize` to fix').yellow
end
|
#cp_results(results) ⇒ Object
96
97
98
99
100
|
# File 'lib/i18n/tasks/reports/terminal.rb', line 96
def cp_results(results)
results.each do |(from, to)|
print_info "#{Rainbow(from).cyan} #{Rainbow('+').yellow.bright} #{Rainbow(to).green}"
end
end
|
#eq_base_keys(tree = task.eq_base_keys) ⇒ Object
62
63
64
65
66
67
68
69
70
|
# File 'lib/i18n/tasks/reports/terminal.rb', line 62
def eq_base_keys(tree = task.eq_base_keys)
keys = tree.root_key_value_data(true)
if keys.present?
print_title eq_base_title(keys)
print_locale_key_value_data_table keys
else
print_info Rainbow('No translations are the same as base value').cyan
end
end
|
#forest_stats(forest, stats = task.forest_stats(forest)) ⇒ Object
76
77
78
79
80
81
82
83
84
|
# File 'lib/i18n/tasks/reports/terminal.rb', line 76
def forest_stats(forest, stats = task.forest_stats(forest))
text = if stats[:locale_count] == 1
I18n.t('i18n_tasks.data_stats.text_single_locale', **stats)
else
I18n.t('i18n_tasks.data_stats.text', **stats)
end
title = Rainbow(I18n.t('i18n_tasks.data_stats.title', **stats.slice(:locales))).bright
print_info "#{Rainbow(title).cyan} #{Rainbow(text).cyan}"
end
|
#inconsistent_interpolations(forest = task.inconsistent_interpolations) ⇒ Object
27
28
29
30
31
32
33
34
|
# File 'lib/i18n/tasks/reports/terminal.rb', line 27
def inconsistent_interpolations(forest = task.inconsistent_interpolations)
if forest.present?
print_title inconsistent_interpolations_title(forest)
show_tree(forest)
else
print_success I18n.t('i18n_tasks.inconsistent_interpolations.none')
end
end
|
#missing_keys(forest = task.missing_keys) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/i18n/tasks/reports/terminal.rb', line 9
def missing_keys(forest = task.missing_keys)
forest = collapse_missing_tree! forest
if forest.present?
print_title missing_title(forest)
print_table headings: [Rainbow(I18n.t('i18n_tasks.common.locale')).cyan.bright,
Rainbow(I18n.t('i18n_tasks.common.key')).cyan.bright,
I18n.t('i18n_tasks.missing.details_title')] do |t|
t.rows = sort_by_attr!(forest_to_attr(forest)).map do |a|
[{ value: Rainbow(format_locale(a[:locale])).cyan, alignment: :center },
format_key(a[:key], a[:data]),
missing_key_info(a)]
end
end
else
print_success I18n.t('i18n_tasks.missing.none')
end
end
|
#mv_results(results) ⇒ Object
86
87
88
89
90
91
92
93
94
|
# File 'lib/i18n/tasks/reports/terminal.rb', line 86
def mv_results(results)
results.each do |(from, to)|
if to
print_info "#{Rainbow(from).cyan} #{Rainbow('⮕').yellow.bright} #{Rainbow(to).cyan}"
else
print_info "#{Rainbow(from).red}#{Rainbow(' 🗑').red.bright}"
end
end
end
|
#show_tree(tree) ⇒ Object
72
73
74
|
# File 'lib/i18n/tasks/reports/terminal.rb', line 72
def show_tree(tree)
print_locale_key_value_data_table tree.root_key_value_data(true)
end
|
#unused_keys(tree = task.unused_keys) ⇒ Object
52
53
54
55
56
57
58
59
60
|
# File 'lib/i18n/tasks/reports/terminal.rb', line 52
def unused_keys(tree = task.unused_keys)
keys = tree.root_key_value_data(true)
if keys.present?
print_title unused_title(keys)
print_locale_key_value_data_table keys
else
print_success I18n.t('i18n_tasks.unused.none')
end
end
|
#used_keys(used_tree = task.used_tree) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/i18n/tasks/reports/terminal.rb', line 36
def used_keys(used_tree = task.used_tree)
keys_nodes = used_tree.nodes.select { |node| node.data[:occurrences].present? }.map do |node|
[node.full_key(root: false), node]
end
print_title used_title(keys_nodes, used_tree.first.root.data[:key_filter])
if keys_nodes.present?
keys_nodes.sort! { |a, b| a[0] <=> b[0] }.each do |key, node|
print_occurrences node, key
end
else
print_error I18n.t('i18n_tasks.usages.none')
end
end
|