Class: I18n::Processes::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
#changed_keys(diff = nil) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/i18n/processes/reports/terminal.rb', line 28
def changed_keys(diff = nil)
if diff
print_title "#{diff.count} keys' value changed"
print_table headings: [Rainbow('key').cyan.bright,
Rainbow('Current').cyan.bright,
'Previous'] do |t|
t.rows = diff.map do |key, value|
[key, value[:current], value[:previous]]
end
end
else
print_success 'No key have been changed.'
end
end
|
#check_normalized_results(non_normalized) ⇒ Object
108
109
110
111
112
113
114
115
116
|
# File 'lib/i18n/processes/reports/terminal.rb', line 108
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-processes normalize` to fix').yellow
end
|
#eq_base_keys(tree = task.eq_base_keys) ⇒ Object
74
75
76
77
78
79
80
81
82
|
# File 'lib/i18n/processes/reports/terminal.rb', line 74
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
88
89
90
91
92
93
94
95
96
|
# File 'lib/i18n/processes/reports/terminal.rb', line 88
def forest_stats(forest, stats = task.forest_stats(forest))
text = if stats[:locale_count] == 1
"has #{stats[:key_count]} keys in total. On average, values are #{stats[:value_chars_avg]} characters long, keys have #{stats[:key_segments_avg]} segments."
else
"has #{stats[:key_count]} keys across #{stats[:locale_count]} locales. On average, values are #{stats[:value_chars_avg]} characters long, keys have #{stats[:key_segments_avg]} segments, a locale has #{stats[:per_locale_avg]} keys."
end
title = Rainbow("Forest (#{stats.slice(:locales)})").bright
print_info "#{Rainbow(title).cyan} #{Rainbow(text).cyan}"
end
|
#icon(type) ⇒ Object
43
44
45
46
|
# File 'lib/i18n/processes/reports/terminal.rb', line 43
def icon(type)
glyph = missing_type_info(type)[:glyph]
{ missing_used: Rainbow(glyph).red, missing_diff: Rainbow(glyph).yellow }[type]
end
|
#missing_keys(forest = task.missing_keys) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/i18n/processes/reports/terminal.rb', line 10
def missing_keys(forest = task.missing_keys)
forest = collapse_missing_tree! forest
if forest.present?
print_title missing_title(forest)
print_table headings: [Rainbow('Locale').cyan.bright,
Rainbow('Key').cyan.bright,
'Value in other locales or source'] 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 'No translations are missing.'
end
end
|
#mv_results(results) ⇒ Object
98
99
100
101
102
103
104
105
106
|
# File 'lib/i18n/processes/reports/terminal.rb', line 98
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
84
85
86
|
# File 'lib/i18n/processes/reports/terminal.rb', line 84
def show_tree(tree)
print_locale_key_value_data_table tree.root_key_value_data(true)
end
|
#unused_keys(tree = task.unused_keys) ⇒ Object
64
65
66
67
68
69
70
71
72
|
# File 'lib/i18n/processes/reports/terminal.rb', line 64
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 'Every translation is in use.'
end
end
|
#used_keys(used_tree = task.used_tree) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/i18n/processes/reports/terminal.rb', line 48
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 'No key usages found.'
end
end
|