i18n-tasks 0.9.29 → 0.9.34
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -5
- data/config/locales/en.yml +6 -0
- data/config/locales/ru.yml +6 -0
- data/i18n-tasks.gemspec +9 -6
- data/lib/i18n/tasks/cli.rb +12 -14
- data/lib/i18n/tasks/command/commander.rb +1 -1
- data/lib/i18n/tasks/command/commands/data.rb +8 -6
- data/lib/i18n/tasks/command/commands/eq_base.rb +2 -2
- data/lib/i18n/tasks/command/commands/health.rb +7 -6
- data/lib/i18n/tasks/command/commands/interpolations.rb +2 -2
- data/lib/i18n/tasks/command/commands/meta.rb +1 -1
- data/lib/i18n/tasks/command/commands/missing.rb +8 -7
- data/lib/i18n/tasks/command/commands/tree.rb +8 -6
- data/lib/i18n/tasks/command/commands/usages.rb +7 -6
- data/lib/i18n/tasks/command/dsl.rb +4 -4
- data/lib/i18n/tasks/command/option_parsers/enum.rb +2 -0
- data/lib/i18n/tasks/command/option_parsers/locale.rb +2 -1
- data/lib/i18n/tasks/command/options/data.rb +1 -0
- data/lib/i18n/tasks/command/options/locales.rb +5 -5
- data/lib/i18n/tasks/concurrent/cached_value.rb +2 -0
- data/lib/i18n/tasks/configuration.rb +5 -4
- data/lib/i18n/tasks/console_context.rb +1 -1
- data/lib/i18n/tasks/data/adapter/yaml_adapter.rb +1 -1
- data/lib/i18n/tasks/data/file_formats.rb +2 -0
- data/lib/i18n/tasks/data/file_system_base.rb +7 -6
- data/lib/i18n/tasks/data/router/conservative_router.rb +2 -1
- data/lib/i18n/tasks/data/router/pattern_router.rb +2 -0
- data/lib/i18n/tasks/data/tree/node.rb +7 -5
- data/lib/i18n/tasks/data/tree/nodes.rb +2 -2
- data/lib/i18n/tasks/data/tree/siblings.rb +10 -3
- data/lib/i18n/tasks/data/tree/traversal.rb +17 -10
- data/lib/i18n/tasks/html_keys.rb +2 -4
- data/lib/i18n/tasks/ignore_keys.rb +4 -3
- data/lib/i18n/tasks/interpolations.rb +4 -2
- data/lib/i18n/tasks/key_pattern_matching.rb +3 -2
- data/lib/i18n/tasks/missing_keys.rb +33 -7
- data/lib/i18n/tasks/plural_keys.rb +6 -1
- data/lib/i18n/tasks/references.rb +2 -0
- data/lib/i18n/tasks/reports/base.rb +3 -2
- data/lib/i18n/tasks/reports/terminal.rb +10 -9
- data/lib/i18n/tasks/scanners/file_scanner.rb +4 -3
- data/lib/i18n/tasks/scanners/files/caching_file_finder.rb +0 -3
- data/lib/i18n/tasks/scanners/files/file_finder.rb +3 -2
- data/lib/i18n/tasks/scanners/occurrence_from_position.rb +3 -3
- data/lib/i18n/tasks/scanners/pattern_scanner.rb +7 -4
- data/lib/i18n/tasks/scanners/pattern_with_scope_scanner.rb +4 -2
- data/lib/i18n/tasks/scanners/relative_keys.rb +1 -0
- data/lib/i18n/tasks/scanners/ruby_ast_scanner.rb +18 -15
- data/lib/i18n/tasks/scanners/ruby_key_literals.rb +3 -3
- data/lib/i18n/tasks/scanners/scanner_multiplexer.rb +2 -0
- data/lib/i18n/tasks/split_key.rb +2 -0
- data/lib/i18n/tasks/string_interpolation.rb +1 -0
- data/lib/i18n/tasks/translation.rb +6 -3
- data/lib/i18n/tasks/translators/base_translator.rb +3 -1
- data/lib/i18n/tasks/translators/deepl_translator.rb +9 -2
- data/lib/i18n/tasks/translators/google_translator.rb +2 -0
- data/lib/i18n/tasks/translators/yandex_translator.rb +63 -0
- data/lib/i18n/tasks/used_keys.rb +15 -11
- data/lib/i18n/tasks/version.rb +1 -1
- data/templates/config/i18n-tasks.yml +1 -1
- data/templates/rspec/i18n_spec.rb +9 -2
- metadata +48 -31
- data/lib/i18n/tasks/rainbow_utils.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5477cbdf1fb14c575eaad7221cac570147acfcde877fa5960dcdfd958d76d270
|
4
|
+
data.tar.gz: b40dbef296c01aa2c047b8ae2f6ef3567f8643b35895516a8fde281f225e6daa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f732fc9479ba13cd3acb1c7222401f873ace5a8db1ef248712c1ea4dbdb9d05a7fdc5da5bb3600c7c799c64b7f21b1586518b1feec508a0ad36d211110b07b3e
|
7
|
+
data.tar.gz: f05241d9bd75bbecb1cb992882d84c4e9826c00c66b66263e7203603e19c9a188e96ea7f4e4131160e23216265df675f4519d190263cf14de59384bd2e62c88d
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# i18n-tasks [![Build Status][badge-travis]][travis] [![Coverage Status][badge-coverage]][coverage] [![
|
1
|
+
# i18n-tasks [![Build Status][badge-travis]][travis] [![Coverage Status][badge-coverage]][coverage] [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/glebm/i18n-tasks?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
2
2
|
|
3
3
|
i18n-tasks helps you find and manage missing and unused translations.
|
4
4
|
|
@@ -22,7 +22,7 @@ i18n-tasks can be used with any project using the ruby [i18n gem][i18n-gem] (def
|
|
22
22
|
Add i18n-tasks to the Gemfile:
|
23
23
|
|
24
24
|
```ruby
|
25
|
-
gem 'i18n-tasks', '~> 0.9.
|
25
|
+
gem 'i18n-tasks', '~> 0.9.34'
|
26
26
|
```
|
27
27
|
|
28
28
|
Copy the default [configuration file](#configuration):
|
@@ -104,6 +104,17 @@ $ i18n-tasks translate-missing --backend=deepl
|
|
104
104
|
$ i18n-tasks translate-missing --backend=deepl --from=en fr nl
|
105
105
|
```
|
106
106
|
|
107
|
+
### Yandex Translate missing keys
|
108
|
+
|
109
|
+
Translate missing values with Yandex Translate ([more below on the API key](#yandex-translation-config)).
|
110
|
+
|
111
|
+
```console
|
112
|
+
$ i18n-tasks translate-missing --backend=yandex
|
113
|
+
|
114
|
+
# accepts from and locales options:
|
115
|
+
$ i18n-tasks translate-missing --from=en es fr
|
116
|
+
```
|
117
|
+
|
107
118
|
### Find usages
|
108
119
|
|
109
120
|
See where the keys are used with `i18n-tasks find`:
|
@@ -374,7 +385,7 @@ See the [config file][config] to find out more.
|
|
374
385
|
Where this key is depends on your Google API console:
|
375
386
|
|
376
387
|
* Old console: API Access -> Simple API Access -> Key for server apps.
|
377
|
-
* New console:
|
388
|
+
* New console: Nav Menu -> APIs & Services -> Credentials -> Create Credentials -> API Keys -> Restrict Key -> Cloud Translation API
|
378
389
|
|
379
390
|
In both cases, you may need to create the key if it doesn't exist.
|
380
391
|
|
@@ -397,6 +408,17 @@ translation:
|
|
397
408
|
deepl_api_key: <Deep Pro API key>
|
398
409
|
```
|
399
410
|
|
411
|
+
<a name="yandex-translation-config"></a>
|
412
|
+
### Yandex Translate
|
413
|
+
|
414
|
+
`i18n-tasks translate-missing` requires a Yandex API key, get it at [Yandex](https://tech.yandex.com/translate).
|
415
|
+
|
416
|
+
```yaml
|
417
|
+
# config/i18n-tasks.yml
|
418
|
+
translation:
|
419
|
+
yandex_api_key: <Yandex API key>
|
420
|
+
```
|
421
|
+
|
400
422
|
## Interactive console
|
401
423
|
|
402
424
|
`i18n-tasks irb` starts an IRB session in i18n-tasks context. Type `guide` for more information.
|
@@ -415,8 +437,6 @@ Custom tasks can be added easily, see the examples [on the wiki](https://github.
|
|
415
437
|
[badge-travis]: https://img.shields.io/travis/glebm/i18n-tasks.svg
|
416
438
|
[coverage]: https://codeclimate.com/github/glebm/i18n-tasks
|
417
439
|
[badge-coverage]: https://api.codeclimate.com/v1/badges/5d173e90ada8df07cedc/test_coverage
|
418
|
-
[gemnasium]: https://gemnasium.com/glebm/i18n-tasks
|
419
|
-
[badge-gemnasium]: https://gemnasium.com/glebm/i18n-tasks.svg
|
420
440
|
[config]: https://github.com/glebm/i18n-tasks/blob/master/templates/config/i18n-tasks.yml
|
421
441
|
[wiki]: https://github.com/glebm/i18n-tasks/wiki "i18n-tasks wiki"
|
422
442
|
[i18n-gem]: https://github.com/svenfuchs/i18n "svenfuchs/i18n on Github"
|
data/config/locales/en.yml
CHANGED
@@ -120,3 +120,9 @@ en:
|
|
120
120
|
none: Every translation is in use.
|
121
121
|
usages:
|
122
122
|
none: No key usages found.
|
123
|
+
yandex_translate:
|
124
|
+
errors:
|
125
|
+
no_api_key: >-
|
126
|
+
Set Yandex API key via YANDEX_API_KEY environment variable or translation.yandex_api_key
|
127
|
+
in config/i18n-tasks.yml. Get the key at https://tech.yandex.com/translate.
|
128
|
+
no_results: Yandex returned no results.
|
data/config/locales/ru.yml
CHANGED
@@ -122,3 +122,9 @@ ru:
|
|
122
122
|
none: Все переводы используются.
|
123
123
|
usages:
|
124
124
|
none: Не найдено использований.
|
125
|
+
yandex_translate:
|
126
|
+
errors:
|
127
|
+
no_api_key: |-
|
128
|
+
Установить ключ API Яндекса с помощью переменной среды YANDEX_API_KEY или translation.yandex_api_key
|
129
|
+
в config / i18n-tasks.yml. Получите ключ по адресу https://tech.yandex.com/translate/.
|
130
|
+
no_results: Яндекс не дал результатов.
|
data/i18n-tasks.gemspec
CHANGED
@@ -16,16 +16,16 @@ Gem::Specification.new do |s| # rubocop:disable Metrics/BlockLength
|
|
16
16
|
|
17
17
|
It analyses code statically for key usages, such as `I18n.t('some.key')`, in order to report keys that are missing or unused,
|
18
18
|
pre-fill missing keys (optionally from Google Translate), and remove unused keys.
|
19
|
-
TEXT
|
19
|
+
TEXT
|
20
20
|
s.post_install_message = <<~TEXT
|
21
21
|
# Install default configuration:
|
22
22
|
cp $(bundle exec i18n-tasks gem-path)/templates/config/i18n-tasks.yml config/
|
23
23
|
# Add an RSpec for missing and unused keys:
|
24
24
|
cp $(bundle exec i18n-tasks gem-path)/templates/rspec/i18n_spec.rb spec/
|
25
|
-
TEXT
|
25
|
+
TEXT
|
26
26
|
s.homepage = 'https://github.com/glebm/i18n-tasks'
|
27
27
|
s.metadata = { 'issue_tracker' => 'https://github.com/glebm/i18n-tasks' } if s.respond_to?(:metadata=)
|
28
|
-
s.required_ruby_version = '
|
28
|
+
s.required_ruby_version = '>= 2.5', '< 4.0' if s.respond_to?(:required_ruby_version=)
|
29
29
|
|
30
30
|
s.files = `git ls-files`.split($/)
|
31
31
|
s.files -= s.files.grep(%r{^(doc/|\.|spec/)}) + %w[CHANGES.md config/i18n-tasks.yml Gemfile]
|
@@ -44,11 +44,14 @@ TEXT
|
|
44
44
|
s.add_dependency 'terminal-table', '>= 1.5.1'
|
45
45
|
s.add_development_dependency 'axlsx', '~> 2.0'
|
46
46
|
s.add_development_dependency 'bundler', '~> 2.0', '>= 2.0.1'
|
47
|
-
s.add_development_dependency 'deepl-rb', '>= 2.1.0'
|
48
|
-
s.add_development_dependency 'easy_translate', '>= 0.5.1'
|
49
47
|
s.add_development_dependency 'rake'
|
50
48
|
s.add_development_dependency 'rspec', '~> 3.3'
|
51
|
-
s.add_development_dependency 'rubocop', '~>
|
49
|
+
s.add_development_dependency 'rubocop', '~> 1.6.1'
|
52
50
|
s.add_development_dependency 'simplecov'
|
53
51
|
s.add_development_dependency 'yard'
|
52
|
+
|
53
|
+
# Translation backends
|
54
|
+
s.add_development_dependency 'deepl-rb', '>= 2.1.0'
|
55
|
+
s.add_development_dependency 'easy_translate', '>= 0.5.1' # Google Translate
|
56
|
+
s.add_development_dependency 'yandex-translator', '>= 0.3.3'
|
54
57
|
end
|
data/lib/i18n/tasks/cli.rb
CHANGED
@@ -15,21 +15,19 @@ class I18n::Tasks::CLI
|
|
15
15
|
|
16
16
|
def start(argv)
|
17
17
|
auto_output_coloring do
|
18
|
+
exit 1 if run(argv) == :exit1
|
19
|
+
rescue OptionParser::ParseError => e
|
20
|
+
error e.message, 64
|
21
|
+
rescue I18n::Tasks::CommandError => e
|
18
22
|
begin
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
rescue I18n::Tasks::CommandError => e
|
23
|
-
begin
|
24
|
-
error e.message, 78
|
25
|
-
ensure
|
26
|
-
log_verbose e.backtrace * "\n"
|
27
|
-
end
|
28
|
-
rescue Errno::EPIPE
|
29
|
-
# ignore Errno::EPIPE which is throw when pipe breaks, e.g.:
|
30
|
-
# i18n-tasks missing | head
|
31
|
-
exit 1
|
23
|
+
error e.message, 78
|
24
|
+
ensure
|
25
|
+
log_verbose e.backtrace * "\n"
|
32
26
|
end
|
27
|
+
rescue Errno::EPIPE
|
28
|
+
# ignore Errno::EPIPE which is throw when pipe breaks, e.g.:
|
29
|
+
# i18n-tasks missing | head
|
30
|
+
exit 1
|
33
31
|
end
|
34
32
|
rescue ExecutionError => e
|
35
33
|
exit e.exit_code
|
@@ -195,7 +193,7 @@ class I18n::Tasks::CLI
|
|
195
193
|
end
|
196
194
|
end
|
197
195
|
|
198
|
-
def auto_output_coloring(coloring = ENV['I18N_TASKS_COLOR'] ||
|
196
|
+
def auto_output_coloring(coloring = ENV['I18N_TASKS_COLOR'] || $stdout.isatty)
|
199
197
|
coloring_was = Rainbow.enabled
|
200
198
|
Rainbow.enabled = coloring
|
201
199
|
yield
|
@@ -12,7 +12,7 @@ module I18n::Tasks
|
|
12
12
|
t('i18n_tasks.cmd.args.desc.pattern_router')
|
13
13
|
|
14
14
|
cmd :normalize,
|
15
|
-
pos:
|
15
|
+
pos: '[locale ...]',
|
16
16
|
desc: t('i18n_tasks.cmd.desc.normalize'),
|
17
17
|
args: %i[locales pattern_router]
|
18
18
|
|
@@ -29,7 +29,7 @@ module I18n::Tasks
|
|
29
29
|
def check_normalized(opt)
|
30
30
|
non_normalized = i18n.non_normalized_paths locales: opt[:locales]
|
31
31
|
terminal_report.check_normalized_results(non_normalized)
|
32
|
-
:
|
32
|
+
:exit1 unless non_normalized.empty?
|
33
33
|
end
|
34
34
|
|
35
35
|
cmd :mv,
|
@@ -37,6 +37,7 @@ module I18n::Tasks
|
|
37
37
|
desc: t('i18n_tasks.cmd.desc.mv')
|
38
38
|
def mv(opt = {})
|
39
39
|
fail CommandError, 'requires FROM_KEY_PATTERN and TO_KEY_PATTERN' if opt[:arguments].size < 2
|
40
|
+
|
40
41
|
from_pattern = opt[:arguments].shift
|
41
42
|
to_pattern = opt[:arguments].shift
|
42
43
|
forest = i18n.data_forest
|
@@ -50,6 +51,7 @@ module I18n::Tasks
|
|
50
51
|
desc: t('i18n_tasks.cmd.desc.rm')
|
51
52
|
def rm(opt = {})
|
52
53
|
fail CommandError, 'requires KEY_PATTERN' if opt[:arguments].empty?
|
54
|
+
|
53
55
|
forest = i18n.data_forest
|
54
56
|
results = opt[:arguments].each_with_object({}) do |key_pattern, h|
|
55
57
|
h.merge! forest.mv_key!(compile_key_pattern(key_pattern), '', root: false)
|
@@ -59,7 +61,7 @@ module I18n::Tasks
|
|
59
61
|
end
|
60
62
|
|
61
63
|
cmd :data,
|
62
|
-
pos:
|
64
|
+
pos: '[locale ...]',
|
63
65
|
desc: t('i18n_tasks.cmd.desc.data'),
|
64
66
|
args: %i[locales out_format]
|
65
67
|
|
@@ -68,7 +70,7 @@ module I18n::Tasks
|
|
68
70
|
end
|
69
71
|
|
70
72
|
cmd :data_merge,
|
71
|
-
pos:
|
73
|
+
pos: '[tree ...]',
|
72
74
|
desc: t('i18n_tasks.cmd.desc.data_merge'),
|
73
75
|
args: %i[data_format nostdin]
|
74
76
|
|
@@ -79,7 +81,7 @@ module I18n::Tasks
|
|
79
81
|
end
|
80
82
|
|
81
83
|
cmd :data_write,
|
82
|
-
pos:
|
84
|
+
pos: '[tree]',
|
83
85
|
desc: t('i18n_tasks.cmd.desc.data_write'),
|
84
86
|
args: %i[data_format nostdin]
|
85
87
|
|
@@ -90,7 +92,7 @@ module I18n::Tasks
|
|
90
92
|
end
|
91
93
|
|
92
94
|
cmd :data_remove,
|
93
|
-
pos:
|
95
|
+
pos: '[tree]',
|
94
96
|
desc: t('i18n_tasks.cmd.desc.data_remove'),
|
95
97
|
args: %i[data_format nostdin]
|
96
98
|
|
@@ -7,14 +7,14 @@ module I18n::Tasks
|
|
7
7
|
include Command::Collection
|
8
8
|
|
9
9
|
cmd :eq_base,
|
10
|
-
pos:
|
10
|
+
pos: '[locale ...]',
|
11
11
|
desc: t('i18n_tasks.cmd.desc.eq_base'),
|
12
12
|
args: %i[locales out_format]
|
13
13
|
|
14
14
|
def eq_base(opt = {})
|
15
15
|
forest = i18n.eq_base_keys(opt)
|
16
16
|
print_forest forest, opt, :eq_base_keys
|
17
|
-
:
|
17
|
+
:exit1 unless forest.empty?
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -7,7 +7,7 @@ module I18n::Tasks
|
|
7
7
|
include Command::Collection
|
8
8
|
|
9
9
|
cmd :health,
|
10
|
-
pos:
|
10
|
+
pos: '[locale ...]',
|
11
11
|
desc: t('i18n_tasks.cmd.desc.health'),
|
12
12
|
args: %i[locales out_format]
|
13
13
|
|
@@ -15,13 +15,14 @@ module I18n::Tasks
|
|
15
15
|
forest = i18n.data_forest(opt[:locales])
|
16
16
|
stats = i18n.forest_stats(forest)
|
17
17
|
fail CommandError, t('i18n_tasks.health.no_keys_detected') if stats[:key_count].zero?
|
18
|
+
|
18
19
|
terminal_report.forest_stats forest, stats
|
19
20
|
[
|
20
|
-
missing(opt),
|
21
|
-
unused(opt),
|
22
|
-
check_consistent_interpolations(opt),
|
23
|
-
check_normalized(opt)
|
24
|
-
].detect { |result| result == :
|
21
|
+
missing(**opt),
|
22
|
+
unused(**opt),
|
23
|
+
check_consistent_interpolations(**opt),
|
24
|
+
check_normalized(**opt)
|
25
|
+
].detect { |result| result == :exit1 }
|
25
26
|
end
|
26
27
|
end
|
27
28
|
end
|
@@ -12,9 +12,9 @@ module I18n::Tasks
|
|
12
12
|
args: %i[locales out_format]
|
13
13
|
|
14
14
|
def check_consistent_interpolations(opt = {})
|
15
|
-
forest = i18n.inconsistent_interpolations(opt.slice(:locales, :base_locale))
|
15
|
+
forest = i18n.inconsistent_interpolations(**opt.slice(:locales, :base_locale))
|
16
16
|
print_forest forest, opt, :inconsistent_interpolations
|
17
|
-
:
|
17
|
+
:exit1 unless forest.empty?
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -23,18 +23,18 @@ module I18n::Tasks
|
|
23
23
|
)
|
24
24
|
|
25
25
|
cmd :missing,
|
26
|
-
pos:
|
26
|
+
pos: '[locale ...]',
|
27
27
|
desc: t('i18n_tasks.cmd.desc.missing'),
|
28
28
|
args: %i[locales out_format missing_types]
|
29
29
|
|
30
30
|
def missing(opt = {})
|
31
|
-
forest = i18n.missing_keys(opt.slice(:locales, :base_locale, :types))
|
31
|
+
forest = i18n.missing_keys(**opt.slice(:locales, :base_locale, :types))
|
32
32
|
print_forest forest, opt, :missing_keys
|
33
|
-
:
|
33
|
+
:exit1 unless forest.empty?
|
34
34
|
end
|
35
35
|
|
36
36
|
cmd :translate_missing,
|
37
|
-
pos:
|
37
|
+
pos: '[locale ...]',
|
38
38
|
desc: t('i18n_tasks.cmd.desc.translate_missing'),
|
39
39
|
args: [:locales, :locale_to_translate_from, arg(:out_format).from(1), :translation_backend]
|
40
40
|
|
@@ -47,13 +47,14 @@ module I18n::Tasks
|
|
47
47
|
end
|
48
48
|
|
49
49
|
cmd :add_missing,
|
50
|
-
pos:
|
50
|
+
pos: '[locale ...]',
|
51
51
|
desc: t('i18n_tasks.cmd.desc.add_missing'),
|
52
52
|
args: [:locales, :out_format, arg(:value) + [{ default: '%{value_or_default_or_human_key}' }],
|
53
53
|
['--nil-value', 'Set value to nil. Takes precedence over the value argument.']]
|
54
54
|
|
55
|
-
|
56
|
-
|
55
|
+
# Merge base locale first, as this may affect the value for the other locales
|
56
|
+
def add_missing(opt = {})
|
57
|
+
[
|
57
58
|
[i18n.base_locale] & opt[:locales],
|
58
59
|
opt[:locales] - [i18n.base_locale]
|
59
60
|
].reject(&:empty?).each_with_object(i18n.empty_forest) do |locales, added|
|
@@ -8,7 +8,7 @@ module I18n::Tasks
|
|
8
8
|
include I18n::Tasks::KeyPatternMatching
|
9
9
|
|
10
10
|
cmd :tree_translate,
|
11
|
-
pos:
|
11
|
+
pos: '[tree (or stdin)]',
|
12
12
|
desc: t('i18n_tasks.cmd.desc.tree_translate'),
|
13
13
|
args: [:locale_to_translate_from, arg(:data_format).from(1), :translation_backend]
|
14
14
|
|
@@ -18,7 +18,7 @@ module I18n::Tasks
|
|
18
18
|
end
|
19
19
|
|
20
20
|
cmd :tree_merge,
|
21
|
-
pos:
|
21
|
+
pos: '[[tree] [tree] ... (or stdin)]',
|
22
22
|
desc: t('i18n_tasks.cmd.desc.tree_merge'),
|
23
23
|
args: %i[data_format nostdin]
|
24
24
|
|
@@ -27,7 +27,7 @@ module I18n::Tasks
|
|
27
27
|
end
|
28
28
|
|
29
29
|
cmd :tree_filter,
|
30
|
-
pos:
|
30
|
+
pos: '[pattern] [tree (or stdin)]',
|
31
31
|
desc: t('i18n_tasks.cmd.desc.tree_filter'),
|
32
32
|
args: %i[data_format pattern]
|
33
33
|
|
@@ -52,6 +52,7 @@ module I18n::Tasks
|
|
52
52
|
args: %i[data_format all_locales]
|
53
53
|
def tree_mv(opt = {})
|
54
54
|
fail CommandError, 'requires FROM_KEY_PATTERN and TO_KEY_PATTERN' if opt[:arguments].size < 2
|
55
|
+
|
55
56
|
from_pattern = opt[:arguments].shift
|
56
57
|
to_pattern = opt[:arguments].shift
|
57
58
|
forest = forest_pos_or_stdin!(opt)
|
@@ -60,7 +61,7 @@ module I18n::Tasks
|
|
60
61
|
end
|
61
62
|
|
62
63
|
cmd :tree_subtract,
|
63
|
-
pos:
|
64
|
+
pos: '[[tree] [tree] ... (or stdin)]',
|
64
65
|
desc: t('i18n_tasks.cmd.desc.tree_subtract'),
|
65
66
|
args: %i[data_format nostdin]
|
66
67
|
|
@@ -71,7 +72,7 @@ module I18n::Tasks
|
|
71
72
|
end
|
72
73
|
|
73
74
|
cmd :tree_set_value,
|
74
|
-
pos:
|
75
|
+
pos: '[VALUE] [tree (or stdin)]',
|
75
76
|
desc: t('i18n_tasks.cmd.desc.tree_set_value'),
|
76
77
|
args: %i[value data_format nostdin pattern]
|
77
78
|
|
@@ -80,12 +81,13 @@ module I18n::Tasks
|
|
80
81
|
forest = forest_pos_or_stdin!(opt)
|
81
82
|
key_pattern = opt[:pattern]
|
82
83
|
fail CommandError, 'pass value (-v, --value)' if value.blank?
|
84
|
+
|
83
85
|
forest.set_each_value!(value, key_pattern)
|
84
86
|
print_forest forest, opt
|
85
87
|
end
|
86
88
|
|
87
89
|
cmd :tree_convert,
|
88
|
-
pos:
|
90
|
+
pos: '[tree (or stdin)]',
|
89
91
|
desc: t('i18n_tasks.cmd.desc.tree_convert'),
|
90
92
|
args: [arg(:data_format).dup.tap { |a| a[0..1] = ['-f', '--from FORMAT'] },
|
91
93
|
arg(:out_format).dup.tap { |a| a[0..1] = ['-t', '--to FORMAT'] }]
|
@@ -16,7 +16,7 @@ module I18n::Tasks
|
|
16
16
|
t('i18n_tasks.cmd.args.desc.keep_order')
|
17
17
|
|
18
18
|
cmd :find,
|
19
|
-
pos:
|
19
|
+
pos: '[pattern]',
|
20
20
|
desc: t('i18n_tasks.cmd.desc.find'),
|
21
21
|
args: %i[out_format pattern strict]
|
22
22
|
|
@@ -27,23 +27,23 @@ module I18n::Tasks
|
|
27
27
|
end
|
28
28
|
|
29
29
|
cmd :unused,
|
30
|
-
pos:
|
30
|
+
pos: '[locale ...]',
|
31
31
|
desc: t('i18n_tasks.cmd.desc.unused'),
|
32
32
|
args: %i[locales out_format strict]
|
33
33
|
|
34
34
|
def unused(opt = {})
|
35
|
-
forest = i18n.unused_keys(opt.slice(:locales, :strict))
|
35
|
+
forest = i18n.unused_keys(**opt.slice(:locales, :strict))
|
36
36
|
print_forest forest, opt, :unused_keys
|
37
|
-
:
|
37
|
+
:exit1 unless forest.empty?
|
38
38
|
end
|
39
39
|
|
40
40
|
cmd :remove_unused,
|
41
|
-
pos:
|
41
|
+
pos: '[locale ...]',
|
42
42
|
desc: t('i18n_tasks.cmd.desc.remove_unused'),
|
43
43
|
args: %i[locales out_format strict keep_order confirm pattern]
|
44
44
|
|
45
45
|
def remove_unused(opt = {}) # rubocop:disable Metrics/AbcSize
|
46
|
-
unused_keys = i18n.unused_keys(opt.slice(:locales, :strict))
|
46
|
+
unused_keys = i18n.unused_keys(**opt.slice(:locales, :strict))
|
47
47
|
|
48
48
|
if opt[:pattern]
|
49
49
|
pattern_re = i18n.compile_key_pattern(opt[:pattern])
|
@@ -66,6 +66,7 @@ module I18n::Tasks
|
|
66
66
|
|
67
67
|
def confirm_remove_unused!(unused_keys, opt)
|
68
68
|
return if ENV['CONFIRM'] || opt[:confirm]
|
69
|
+
|
69
70
|
locales = Rainbow(unused_keys.flat_map { |root| root.key.split('+') }.sort.uniq * ', ').bright
|
70
71
|
msg = [
|
71
72
|
Rainbow(t('i18n_tasks.remove_unused.confirm', count: unused_keys.leaves.count, locales: locales)).red,
|