i18n-processes 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4a3c64fbecf9527d7bc551b27b06e2a8ebaae26f
4
- data.tar.gz: 5698f8ba6eec69a68205b101afe5a9d922a63032
3
+ metadata.gz: 87d81ef2177dadee1bbbdca639f62978b76ae95d
4
+ data.tar.gz: 4bb93d9332d8cddf13be5fd0d1ab19286426a920
5
5
  SHA512:
6
- metadata.gz: ab7236cd1ba6da353561a7b31b27334b00181d7af119df8c30a755c4bd41d5ba40e9bbfc91b6f11b6d9b3a764559fbea99f4a8774bfb2594e2ae7a0c2148e68c
7
- data.tar.gz: 7898211f013a1f1e99b27ff88aba20dd9238a16bf8c879e1cb14d8bd25a38a2c8d75c24eb0db248412403122d7529523096cd26a2ea42f666c6757abb735d093
6
+ metadata.gz: 693fe773012aa012c988218305ebb2d60c06af2b8bbc34dd1e01c2ece2fa3c2dab5fe5a1d45c1e8cfbc36c77b4cede0a6b5d7fefa97f2a100fa72c6f8b2900ad
7
+ data.tar.gz: a1441e38fabb441ee634ae75455bbdda78a9b5d07aacdbaf4fe56929524acbdb73fcb192085eb69ad643bd720b2bd4695656c7abd9f66a637e06a49e2c03ceb9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- i18n-processes (0.1.0)
4
+ i18n-processes (0.1.1)
5
5
  activesupport (>= 4.0.2)
6
6
  ast (>= 2.1.0)
7
7
  easy_translate (>= 0.5.1)
@@ -12,95 +12,95 @@ module I18n::Processes
12
12
  '--pattern_router',
13
13
  'Use pattern router: keys moved per config data.write'
14
14
 
15
- cmd :normalize,
16
- pos: '[locale ...]',
17
- desc: 'normalize translation data: sort and move to the right files',
18
- args: %i[locales pattern_router]
19
-
20
- def normalize(opt = {})
21
- i18n.normalize_store! locales: opt[:locales],
22
- force_pattern_router: opt[:pattern_router]
23
- end
24
-
25
- cmd :check_normalized,
26
- pos: '[locale ...]',
27
- desc: 'verify that all translation data is normalized',
28
- args: %i[locales]
29
-
30
- def check_normalized(opt)
31
- non_normalized = i18n.non_normalized_paths locales: opt[:locales]
32
- terminal_report.check_normalized_results(non_normalized)
33
- :exit_1 unless non_normalized.empty?
34
- end
35
-
36
- cmd :mv,
37
- pos: 'FROM_KEY_PATTERN TO_KEY_PATTERN',
38
- desc: 'rename/merge the keys in locale data that match the given pattern'
39
- def mv(opt = {})
40
- fail CommandError, 'requires FROM_KEY_PATTERN and TO_KEY_PATTERN' if opt[:arguments].size < 2
41
- from_pattern = opt[:arguments].shift
42
- to_pattern = opt[:arguments].shift
43
- forest = i18n.data_forest
44
- results = forest.mv_key!(compile_key_pattern(from_pattern), to_pattern, root: false)
45
- i18n.data.write forest
46
- terminal_report.mv_results results
47
- end
48
-
49
- cmd :rm,
50
- pos: 'KEY_PATTERN [KEY_PATTERN...]',
51
- desc: 'remove the keys in locale data that match the given pattern'
52
- def rm(opt = {})
53
- fail CommandError, 'requires KEY_PATTERN' if opt[:arguments].empty?
54
- forest = i18n.data_forest
55
- results = opt[:arguments].each_with_object({}) do |key_pattern, h|
56
- h.merge! forest.mv_key!(compile_key_pattern(key_pattern), '', root: false)
57
- end
58
- i18n.data.write forest
59
- terminal_report.mv_results results
60
- end
61
-
62
- cmd :data,
63
- pos: '[locale ...]',
64
- desc: 'show locale data',
65
- args: %i[locales out_format]
66
-
67
- def data(opt = {})
68
- $stderr.puts Rainbow("data from here?!")
69
- print_forest i18n.data_forest(opt[:locales]), opt
70
- end
71
-
72
- cmd :data_merge,
73
- pos: '[tree ...]',
74
- desc: 'merge locale data with trees',
75
- args: %i[data_format nostdin]
76
-
77
- def data_merge(opt = {})
78
- forest = merge_forests_stdin_and_pos!(opt)
79
- merged = i18n.data.merge!(forest)
80
- print_forest merged, opt
81
- end
82
-
83
- cmd :data_write,
84
- pos: '[tree]',
85
- desc: 'replace locale data with tree',
86
- args: %i[data_format nostdin]
87
-
88
- def data_write(opt = {})
89
- forest = forest_pos_or_stdin!(opt)
90
- i18n.data.write forest
91
- print_forest forest, opt
92
- end
93
-
94
- cmd :data_remove,
95
- pos: '[tree]',
96
- desc: 'remove keys present in tree from data',
97
- args: %i[data_format nostdin]
98
-
99
- def data_remove(opt = {})
100
- removed = i18n.data.remove_by_key!(forest_pos_or_stdin!(opt))
101
- log_stderr 'Removed:'
102
- print_forest removed, opt
103
- end
15
+ # cmd :normalize,
16
+ # pos: '[locale ...]',
17
+ # desc: 'normalize translation data: sort and move to the right files',
18
+ # args: %i[locales pattern_router]
19
+
20
+ # def normalize(opt = {})
21
+ # i18n.normalize_store! locales: opt[:locales],
22
+ # force_pattern_router: opt[:pattern_router]
23
+ # end
24
+ #
25
+ # cmd :check_normalized,
26
+ # pos: '[locale ...]',
27
+ # desc: 'verify that all translation data is normalized',
28
+ # args: %i[locales]
29
+ #
30
+ # def check_normalized(opt)
31
+ # non_normalized = i18n.non_normalized_paths locales: opt[:locales]
32
+ # terminal_report.check_normalized_results(non_normalized)
33
+ # :exit_1 unless non_normalized.empty?
34
+ # end
35
+ #
36
+ # cmd :mv,
37
+ # pos: 'FROM_KEY_PATTERN TO_KEY_PATTERN',
38
+ # desc: 'rename/merge the keys in locale data that match the given pattern'
39
+ # def mv(opt = {})
40
+ # fail CommandError, 'requires FROM_KEY_PATTERN and TO_KEY_PATTERN' if opt[:arguments].size < 2
41
+ # from_pattern = opt[:arguments].shift
42
+ # to_pattern = opt[:arguments].shift
43
+ # forest = i18n.data_forest
44
+ # results = forest.mv_key!(compile_key_pattern(from_pattern), to_pattern, root: false)
45
+ # i18n.data.write forest
46
+ # terminal_report.mv_results results
47
+ # end
48
+ #
49
+ # cmd :rm,
50
+ # pos: 'KEY_PATTERN [KEY_PATTERN...]',
51
+ # desc: 'remove the keys in locale data that match the given pattern'
52
+ # def rm(opt = {})
53
+ # fail CommandError, 'requires KEY_PATTERN' if opt[:arguments].empty?
54
+ # forest = i18n.data_forest
55
+ # results = opt[:arguments].each_with_object({}) do |key_pattern, h|
56
+ # h.merge! forest.mv_key!(compile_key_pattern(key_pattern), '', root: false)
57
+ # end
58
+ # i18n.data.write forest
59
+ # terminal_report.mv_results results
60
+ # end
61
+ #
62
+ # cmd :data,
63
+ # pos: '[locale ...]',
64
+ # desc: 'show locale data',
65
+ # args: %i[locales out_format]
66
+ #
67
+ # def data(opt = {})
68
+ # $stderr.puts Rainbow("data from here?!")
69
+ # print_forest i18n.data_forest(opt[:locales]), opt
70
+ # end
71
+ #
72
+ # cmd :data_merge,
73
+ # pos: '[tree ...]',
74
+ # desc: 'merge locale data with trees',
75
+ # args: %i[data_format nostdin]
76
+ #
77
+ # def data_merge(opt = {})
78
+ # forest = merge_forests_stdin_and_pos!(opt)
79
+ # merged = i18n.data.merge!(forest)
80
+ # print_forest merged, opt
81
+ # end
82
+ #
83
+ # cmd :data_write,
84
+ # pos: '[tree]',
85
+ # desc: 'replace locale data with tree',
86
+ # args: %i[data_format nostdin]
87
+ #
88
+ # def data_write(opt = {})
89
+ # forest = forest_pos_or_stdin!(opt)
90
+ # i18n.data.write forest
91
+ # print_forest forest, opt
92
+ # end
93
+ #
94
+ # cmd :data_remove,
95
+ # pos: '[tree]',
96
+ # desc: 'remove keys present in tree from data',
97
+ # args: %i[data_format nostdin]
98
+ #
99
+ # def data_remove(opt = {})
100
+ # removed = i18n.data.remove_by_key!(forest_pos_or_stdin!(opt))
101
+ # log_stderr 'Removed:'
102
+ # print_forest removed, opt
103
+ # end
104
104
  end
105
105
  end
106
106
  end
@@ -7,14 +7,14 @@ module I18n::Processes
7
7
  module EqBase
8
8
  include Command::Collection
9
9
 
10
- cmd :eq_base,
11
- pos: '[locale ...]',
12
- desc: 'show translations equal to base value',
13
- args: %i[locales out_format]
14
-
15
- def eq_base(opt = {})
16
- print_forest i18n.eq_base_keys(opt), opt, :eq_base_keys
17
- end
10
+ # cmd :eq_base,
11
+ # pos: '[locale ...]',
12
+ # desc: 'show translations equal to base value',
13
+ # args: %i[locales out_format]
14
+ #
15
+ # def eq_base(opt = {})
16
+ # print_forest i18n.eq_base_keys(opt), opt, :eq_base_keys
17
+ # end
18
18
  end
19
19
  end
20
20
  end
@@ -7,19 +7,19 @@ module I18n::Processes
7
7
  module Health
8
8
  include Command::Collection
9
9
 
10
- cmd :health,
11
- pos: '[locale ...]',
12
- desc: 'is everything OK?',
13
- args: %i[locales out_format]
14
-
15
- def health(opt = {})
16
- forest = i18n.data_forest(opt[:locales])
17
- stats = i18n.forest_stats(forest)
18
- fail CommandError, 'No keys detected. Check data.read in config/i18n-processes.yml.' if stats[:key_count].zero?
19
- terminal_report.forest_stats forest, stats
20
- $stderr.puts Rainbow("#{opt}").green
21
- [missing(opt), unused(opt), check_normalized(opt)].detect { |result| result == :exit_1 }
22
- end
10
+ # cmd :health,
11
+ # pos: '[locale ...]',
12
+ # desc: 'is everything OK?',
13
+ # args: %i[locales out_format]
14
+ #
15
+ # def health(opt = {})
16
+ # forest = i18n.data_forest(opt[:locales])
17
+ # stats = i18n.forest_stats(forest)
18
+ # fail CommandError, 'No keys detected. Check data.read in config/i18n-processes.yml.' if stats[:key_count].zero?
19
+ # terminal_report.forest_stats forest, stats
20
+ # $stderr.puts Rainbow("#{opt}").green
21
+ # [missing(opt), unused(opt), check_normalized(opt)].detect { |result| result == :exit_1 }
22
+ # end
23
23
  end
24
24
  end
25
25
  end
@@ -7,31 +7,31 @@ module I18n::Processes
7
7
  module Meta
8
8
  include Command::Collection
9
9
 
10
- cmd :config,
11
- pos: '[section ...]',
12
- desc: 'display i18n-processes configuration'
13
-
14
- def config(opts = {})
15
- cfg = i18n.config_for_inspect
16
- cfg = cfg.slice(*opts[:arguments]) if opts[:arguments].present?
17
- cfg = cfg.to_yaml
18
- cfg.sub!(/\A---\n/, '')
19
- cfg.gsub!(/^([^\s-].+?:)/, Rainbow('\1').cyan.bright)
20
- puts cfg
21
- end
22
-
23
- cmd :gem_path, desc: 'show path to the gem'
24
-
25
- def gem_path
26
- puts I18n::Processes.gem_path
27
- end
28
-
29
- cmd :irb, desc: 'start REPL session within i18n-processes context'
30
-
31
- def irb
32
- require 'i18n/processes/console_context'
33
- ::I18n::Processes::ConsoleContext.start
34
- end
10
+ # cmd :config,
11
+ # pos: '[section ...]',
12
+ # desc: 'display i18n-processes configuration'
13
+ #
14
+ # def config(opts = {})
15
+ # cfg = i18n.config_for_inspect
16
+ # cfg = cfg.slice(*opts[:arguments]) if opts[:arguments].present?
17
+ # cfg = cfg.to_yaml
18
+ # cfg.sub!(/\A---\n/, '')
19
+ # cfg.gsub!(/^([^\s-].+?:)/, Rainbow('\1').cyan.bright)
20
+ # puts cfg
21
+ # end
22
+ #
23
+ # cmd :gem_path, desc: 'show path to the gem'
24
+ #
25
+ # def gem_path
26
+ # puts I18n::Processes.gem_path
27
+ # end
28
+ #
29
+ # cmd :irb, desc: 'start REPL session within i18n-processes context'
30
+ #
31
+ # def irb
32
+ # require 'i18n/processes/console_context'
33
+ # ::I18n::Processes::ConsoleContext.start
34
+ # end
35
35
  end
36
36
  end
37
37
  end
@@ -50,6 +50,7 @@ module I18n::Processes
50
50
  def keys_source(dic, path, locale)
51
51
  filename = path + locale
52
52
  previous_file = "#{path}pre_#{locale}"
53
+ FileUtils::mkdir_p File.dirname(filename) unless Dir.exist?File.dirname(filename)
53
54
  File.delete(previous_file) if File.exist?(previous_file)
54
55
  File.rename(filename, previous_file) if File.exist?(filename)
55
56
  local_file = File.new(filename, 'w')
@@ -8,111 +8,111 @@ module I18n::Processes
8
8
  include Command::Collection
9
9
  include I18n::Processes::KeyPatternMatching
10
10
 
11
- cmd :tree_translate,
12
- pos: '[tree (or stdin)]',
13
- desc: 'Google Translate a tree to root locales',
14
- args: [:locale_to_translate_from, arg(:data_format).from(1)]
15
-
16
- def tree_translate(opts = {})
17
- forest = forest_pos_or_stdin!(opts)
18
- print_forest i18n.google_translate_forest(forest, opts[:from]), opts
19
- end
20
-
21
- cmd :tree_merge,
22
- pos: '[[tree] [tree] ... (or stdin)]',
23
- desc: 'merge trees',
24
- args: %i[data_format nostdin]
25
-
26
- def tree_merge(opts = {})
27
- print_forest merge_forests_stdin_and_pos!(opts), opts
28
- end
29
-
30
- cmd :tree_filter,
31
- pos: '[pattern] [tree (or stdin)]',
32
- desc: 'filter tree by key pattern',
33
- args: %i[data_format pattern]
34
-
35
- def tree_filter(opts = {})
36
- pattern = arg_or_pos! :pattern, opts
37
- forest = forest_pos_or_stdin! opts
38
- unless pattern.blank?
39
- pattern_re = i18n.compile_key_pattern(pattern)
40
- forest = forest.select_keys { |full_key, _node| full_key =~ pattern_re }
41
- end
42
- print_forest forest, opts
43
- end
44
-
45
- cmd :tree_rename_key,
46
- pos: 'KEY_PATTERN NAME [tree (or stdin)]',
47
- desc: 'rename tree node',
48
- args: [['-k', '--key KEY_PATTERN', 'Full key (pattern) to rename. Required'],
49
- ['-n', '--name NAME', 'New name, interpolates original name as %{key}. Required'],
50
- :data_format]
51
-
52
- def tree_rename_key(opt = {})
53
- warn_deprecated 'Use tree-mv instead.'
54
- key = arg_or_pos! :key, opt
55
- name = arg_or_pos! :name, opt
56
- forest = forest_pos_or_stdin! opt
57
- fail CommandError, 'pass full key to rename (-k, --key)' if key.blank?
58
- fail CommandError, 'pass new name (-n, --name)' if name.blank?
59
- forest.rename_each_key!(key, name)
60
- print_forest forest, opt
61
- end
62
-
63
- arg :all_locales,
64
- '-a',
65
- '--all-locales',
66
- 'Do not expect key patterns to start with a locale, instead apply them to all locales implicitly.'
67
-
68
- cmd :tree_mv,
69
- pos: 'FROM_KEY_PATTERN TO_KEY_PATTERN [tree (or stdin)]',
70
- desc: 'rename/merge/remove the keys matching the given pattern',
71
- args: %i[data_format all_locales]
72
- def tree_mv(opt = {})
73
- fail CommandError, 'requires FROM_KEY_PATTERN and TO_KEY_PATTERN' if opt[:arguments].size < 2
74
- from_pattern = opt[:arguments].shift
75
- to_pattern = opt[:arguments].shift
76
- forest = forest_pos_or_stdin!(opt)
77
- forest.mv_key!(compile_key_pattern(from_pattern), to_pattern, root: !opt[:'all-locales'])
78
- print_forest forest, opt
79
- end
80
-
81
- cmd :tree_subtract,
82
- pos: '[[tree] [tree] ... (or stdin)]',
83
- desc: 'tree A minus the keys in tree B',
84
- args: %i[data_format nostdin]
85
-
86
- def tree_subtract(opt = {})
87
- forests = forests_stdin_and_pos! opt, 2
88
- forest = forests.reduce(:subtract_by_key) || empty_forest
89
- print_forest forest, opt
90
- end
91
-
92
- cmd :tree_set_value,
93
- pos: '[VALUE] [tree (or stdin)]',
94
- desc: 'set values of keys, optionally match a pattern',
95
- args: %i[value data_format nostdin pattern]
96
-
97
- def tree_set_value(opt = {})
98
- value = arg_or_pos! :value, opt
99
- forest = forest_pos_or_stdin!(opt)
100
- key_pattern = opt[:pattern]
101
- fail CommandError, 'pass value (-v, --value)' if value.blank?
102
- forest.set_each_value!(value, key_pattern)
103
- print_forest forest, opt
104
- end
105
-
106
- cmd :tree_convert,
107
- pos: '[tree (or stdin)]',
108
- desc: 'convert tree between formats',
109
- args: [arg(:data_format).dup.tap { |a| a[0..1] = ['-f', '--from FORMAT'] },
110
- arg(:out_format).dup.tap { |a| a[0..1] = ['-t', '--to FORMAT'] }]
111
-
112
- def tree_convert(opt = {})
113
- forest = forest_pos_or_stdin! opt.merge(format: opt[:from])
114
- print_forest forest, opt.merge(format: opt[:to])
115
- end
11
+ # cmd :tree_translate,
12
+ # pos: '[tree (or stdin)]',
13
+ # desc: 'Google Translate a tree to root locales',
14
+ # args: [:locale_to_translate_from, arg(:data_format).from(1)]
15
+ #
16
+ # def tree_translate(opts = {})
17
+ # forest = forest_pos_or_stdin!(opts)
18
+ # print_forest i18n.google_translate_forest(forest, opts[:from]), opts
19
+ # end
20
+ #
21
+ # cmd :tree_merge,
22
+ # pos: '[[tree] [tree] ... (or stdin)]',
23
+ # desc: 'merge trees',
24
+ # args: %i[data_format nostdin]
25
+ #
26
+ # def tree_merge(opts = {})
27
+ # print_forest merge_forests_stdin_and_pos!(opts), opts
28
+ # end
29
+ #
30
+ # cmd :tree_filter,
31
+ # pos: '[pattern] [tree (or stdin)]',
32
+ # desc: 'filter tree by key pattern',
33
+ # args: %i[data_format pattern]
34
+ #
35
+ # def tree_filter(opts = {})
36
+ # pattern = arg_or_pos! :pattern, opts
37
+ # forest = forest_pos_or_stdin! opts
38
+ # unless pattern.blank?
39
+ # pattern_re = i18n.compile_key_pattern(pattern)
40
+ # forest = forest.select_keys { |full_key, _node| full_key =~ pattern_re }
41
+ # end
42
+ # print_forest forest, opts
43
+ # end
44
+ #
45
+ # cmd :tree_rename_key,
46
+ # pos: 'KEY_PATTERN NAME [tree (or stdin)]',
47
+ # desc: 'rename tree node',
48
+ # args: [['-k', '--key KEY_PATTERN', 'Full key (pattern) to rename. Required'],
49
+ # ['-n', '--name NAME', 'New name, interpolates original name as %{key}. Required'],
50
+ # :data_format]
51
+ #
52
+ # def tree_rename_key(opt = {})
53
+ # warn_deprecated 'Use tree-mv instead.'
54
+ # key = arg_or_pos! :key, opt
55
+ # name = arg_or_pos! :name, opt
56
+ # forest = forest_pos_or_stdin! opt
57
+ # fail CommandError, 'pass full key to rename (-k, --key)' if key.blank?
58
+ # fail CommandError, 'pass new name (-n, --name)' if name.blank?
59
+ # forest.rename_each_key!(key, name)
60
+ # print_forest forest, opt
61
+ # end
62
+ #
63
+ # arg :all_locales,
64
+ # '-a',
65
+ # '--all-locales',
66
+ # 'Do not expect key patterns to start with a locale, instead apply them to all locales implicitly.'
67
+ #
68
+ # cmd :tree_mv,
69
+ # pos: 'FROM_KEY_PATTERN TO_KEY_PATTERN [tree (or stdin)]',
70
+ # desc: 'rename/merge/remove the keys matching the given pattern',
71
+ # args: %i[data_format all_locales]
72
+ # def tree_mv(opt = {})
73
+ # fail CommandError, 'requires FROM_KEY_PATTERN and TO_KEY_PATTERN' if opt[:arguments].size < 2
74
+ # from_pattern = opt[:arguments].shift
75
+ # to_pattern = opt[:arguments].shift
76
+ # forest = forest_pos_or_stdin!(opt)
77
+ # forest.mv_key!(compile_key_pattern(from_pattern), to_pattern, root: !opt[:'all-locales'])
78
+ # print_forest forest, opt
79
+ # end
80
+ #
81
+ # cmd :tree_subtract,
82
+ # pos: '[[tree] [tree] ... (or stdin)]',
83
+ # desc: 'tree A minus the keys in tree B',
84
+ # args: %i[data_format nostdin]
85
+ #
86
+ # def tree_subtract(opt = {})
87
+ # forests = forests_stdin_and_pos! opt, 2
88
+ # forest = forests.reduce(:subtract_by_key) || empty_forest
89
+ # print_forest forest, opt
90
+ # end
91
+ #
92
+ # cmd :tree_set_value,
93
+ # pos: '[VALUE] [tree (or stdin)]',
94
+ # desc: 'set values of keys, optionally match a pattern',
95
+ # args: %i[value data_format nostdin pattern]
96
+ #
97
+ # def tree_set_value(opt = {})
98
+ # value = arg_or_pos! :value, opt
99
+ # forest = forest_pos_or_stdin!(opt)
100
+ # key_pattern = opt[:pattern]
101
+ # fail CommandError, 'pass value (-v, --value)' if value.blank?
102
+ # forest.set_each_value!(value, key_pattern)
103
+ # print_forest forest, opt
104
+ # end
105
+ #
106
+ # cmd :tree_convert,
107
+ # pos: '[tree (or stdin)]',
108
+ # desc: 'convert tree between formats',
109
+ # args: [arg(:data_format).dup.tap { |a| a[0..1] = ['-f', '--from FORMAT'] },
110
+ # arg(:out_format).dup.tap { |a| a[0..1] = ['-t', '--to FORMAT'] }]
111
+ #
112
+ # def tree_convert(opt = {})
113
+ # forest = forest_pos_or_stdin! opt.merge(format: opt[:from])
114
+ # print_forest forest, opt.merge(format: opt[:to])
115
+ # end
116
116
  end
117
117
  end
118
118
  end
@@ -7,49 +7,49 @@ module I18n::Processes
7
7
  module Usages
8
8
  include Command::Collection
9
9
 
10
- arg :strict,
11
- '--[no-]strict',
12
- 'Avoid inferring dynamic key usages such as t("cats.#{cat}.name"). Takes precedence over the config setting if set.'
13
-
14
- cmd :find,
15
- pos: '[pattern]',
16
- desc: 'show where keys are used in the code',
17
- args: %i[out_format pattern strict]
18
-
19
- def find(opt = {})
20
- opt[:filter] ||= opt.delete(:pattern) || opt[:arguments].try(:first)
21
- result = i18n.used_tree(strict: opt[:strict], key_filter: opt[:filter].presence, include_raw_references: true)
22
- print_forest result, opt, :used_keys
23
- end
24
-
25
- cmd :unused,
26
- pos: '[locale ...]',
27
- desc: 'show unused translations',
28
- args: %i[locales out_format strict]
29
-
30
- def unused(opt = {})
31
- forest = i18n.unused_keys(opt.slice(:locales, :strict))
32
- print_forest forest, opt, :unused_keys
33
- :exit_1 unless forest.empty?
34
- end
35
-
36
- cmd :remove_unused,
37
- pos: '[locale ...]',
38
- desc: 'remove unused keys',
39
- args: %i[locales out_format strict confirm]
40
-
41
- def remove_unused(opt = {})
42
- unused_keys = i18n.unused_keys(opt.slice(:locales, :strict))
43
- if unused_keys.present?
44
- terminal_report.unused_keys(unused_keys)
45
- confirm_remove_unused!(unused_keys, opt)
46
- removed = i18n.data.remove_by_key!(unused_keys)
47
- log_stderr "Removed #{unused_keys.leaves.count} keys"
48
- print_forest removed, opt
49
- else
50
- log_stderr Rainbow("No unused keys to remove").green.bright
51
- end
52
- end
10
+ # arg :strict,
11
+ # '--[no-]strict',
12
+ # 'Avoid inferring dynamic key usages such as t("cats.#{cat}.name"). Takes precedence over the config setting if set.'
13
+ #
14
+ # cmd :find,
15
+ # pos: '[pattern]',
16
+ # desc: 'show where keys are used in the code',
17
+ # args: %i[out_format pattern strict]
18
+ #
19
+ # def find(opt = {})
20
+ # opt[:filter] ||= opt.delete(:pattern) || opt[:arguments].try(:first)
21
+ # result = i18n.used_tree(strict: opt[:strict], key_filter: opt[:filter].presence, include_raw_references: true)
22
+ # print_forest result, opt, :used_keys
23
+ # end
24
+ #
25
+ # cmd :unused,
26
+ # pos: '[locale ...]',
27
+ # desc: 'show unused translations',
28
+ # args: %i[locales out_format strict]
29
+ #
30
+ # def unused(opt = {})
31
+ # forest = i18n.unused_keys(opt.slice(:locales, :strict))
32
+ # print_forest forest, opt, :unused_keys
33
+ # :exit_1 unless forest.empty?
34
+ # end
35
+ #
36
+ # cmd :remove_unused,
37
+ # pos: '[locale ...]',
38
+ # desc: 'remove unused keys',
39
+ # args: %i[locales out_format strict confirm]
40
+ #
41
+ # def remove_unused(opt = {})
42
+ # unused_keys = i18n.unused_keys(opt.slice(:locales, :strict))
43
+ # if unused_keys.present?
44
+ # terminal_report.unused_keys(unused_keys)
45
+ # confirm_remove_unused!(unused_keys, opt)
46
+ # removed = i18n.data.remove_by_key!(unused_keys)
47
+ # log_stderr "Removed #{unused_keys.leaves.count} keys"
48
+ # print_forest removed, opt
49
+ # else
50
+ # log_stderr Rainbow("No unused keys to remove").green.bright
51
+ # end
52
+ # end
53
53
 
54
54
  private
55
55
 
@@ -7,22 +7,22 @@ module I18n::Processes
7
7
  module XLSX
8
8
  include Command::Collection
9
9
 
10
- cmd :xlsx_report,
11
- pos: '[locale...]',
12
- desc: 'save missing and unused translations to an Excel file',
13
- args: [:locales,
14
- ['-p', '--path PATH', 'Destination path', default: 'tmp/i18n-report.xlsx']]
15
-
16
- def xlsx_report(opt = {})
17
- begin
18
- require 'axlsx'
19
- rescue LoadError
20
- message = %(For spreadsheet report please add axlsx gem to Gemfile:\ngem 'axlsx', '~> 2.0')
21
- log_stderr Rainbow(message).red.bright
22
- exit 1
23
- end
24
- spreadsheet_report.save_report opt[:path], opt.except(:path)
25
- end
10
+ # cmd :xlsx_report,
11
+ # pos: '[locale...]',
12
+ # desc: 'save missing and unused translations to an Excel file',
13
+ # args: [:locales,
14
+ # ['-p', '--path PATH', 'Destination path', default: 'tmp/i18n-report.xlsx']]
15
+ #
16
+ # def xlsx_report(opt = {})
17
+ # begin
18
+ # require 'axlsx'
19
+ # rescue LoadError
20
+ # message = %(For spreadsheet report please add axlsx gem to Gemfile:\ngem 'axlsx', '~> 2.0')
21
+ # log_stderr Rainbow(message).red.bright
22
+ # exit 1
23
+ # end
24
+ # spreadsheet_report.save_report opt[:path], opt.except(:path)
25
+ # end
26
26
  end
27
27
  end
28
28
  end
@@ -3,12 +3,18 @@
3
3
  module I18n::Processes:: Path
4
4
 
5
5
  def origin_files(locale)
6
- source = locale == base_locale ? source_path : translation_path[locale.to_sym]
7
- [].tap do |file|
8
- source.map do |path|
9
- path = path[-1] == '/' ? path : path + '/'
10
- group = Dir.glob("#{path}**/**")
11
- file << group.reject { |x| File.directory?(x) }
6
+ if source_path == []
7
+ log_stderr "please check the path for origin baselocale files"
8
+ elsif translation_path == []
9
+ log_stderr "please check the path for translation files"
10
+ else
11
+ source = locale == base_locale ? source_path : translation_path[locale.to_sym]
12
+ [].tap do |file|
13
+ source.map do |path|
14
+ path = path[-1] == '/' ? path : path + '/'
15
+ group = Dir.glob("#{path}**/**")
16
+ file << group.reject { |x| File.directory?(x) }
17
+ end
12
18
  end
13
19
  end
14
20
  end
@@ -24,15 +30,15 @@ module I18n::Processes:: Path
24
30
  end
25
31
 
26
32
  def source_path
27
- config_file[:data][:source]
33
+ config_file[:data][:source] ||= []
28
34
  end
29
35
 
30
36
  def translation_path
31
- config_file[:data][:translation]
37
+ config_file[:data][:translation] ||= []
32
38
  end
33
39
 
34
40
  def translated_path
35
- config_file[:data][:translated]
41
+ config_file[:data][:translated] ||= []
36
42
  end
37
43
 
38
44
  def config_file
@@ -24,7 +24,7 @@ module I18n::Processes::Reports
24
24
  end
25
25
 
26
26
  def translated_files(locale)
27
- path = translated_path.first
27
+ path = translated_path.first unless translated_path == []
28
28
  dic = get_dic("./tmp/#{locale}")
29
29
  FileUtils.rm_f Dir.glob("./#{path}**/**") unless Dir["./#{path}**/**"].size.zero?
30
30
  origin_files = origin_files(base_locale).flatten
@@ -2,6 +2,6 @@
2
2
 
3
3
  module I18n
4
4
  module Processes
5
- VERSION = '0.1.0'
5
+ VERSION = '0.1.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-processes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-02 00:00:00.000000000 Z
11
+ date: 2018-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport