36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/i18n/tasks/console_context.rb', line 36
def guide
"#{Rainbow('i18n-tasks IRB Quick Start guide').green.bright}\n#{<<~TEXT}"
#{Rainbow('Data as trees').yellow}
tree(locale)
used_tree(key_filter: nil, strict: nil)
unused_tree(locale: base_locale, strict: nil)
build_tree('es' => {'hello' => 'Hola'})
#{Rainbow('Traversal').yellow}
tree = missing_diff_tree('es')
tree.nodes { |node| }
tree.nodes.to_a
tree.leaves { |node| }
tree.each { |root_node| }
# also levels, depth_first, and breadth_first
#{Rainbow('Select nodes').yellow}
tree.select_nodes { |node| } # new tree with only selected nodes
#{Rainbow('Match by full key').yellow}
tree.select_keys { |key, leaf| } # new tree with only selected keys
tree.grep_keys(/hello/) # grep, using ===
tree.keys { |key, leaf| } # enumerate over [full_key, leaf_node]
# Pass {root: true} to include root node in full_key (usually locale)
#{Rainbow('Nodes').yellow}
node = node(key, locale)
node.key # only the part after the last dot
node.full_key # full key. Includes root key, pass {root: false} to override.
# also: value, value_or_children_hash, data, walk_to_root, walk_from_root
Tree::Node.new(key: 'en')
#{Rainbow('Keys').yellow}
t(key, locale)
key_value?(key, locale)
depluralize_key(key, locale) # convert 'hat.one' to 'hat'
TEXT
end
|