i18n-tasks 0.9.31 → 0.9.35
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -7
- data/config/locales/en.yml +1 -0
- data/i18n-tasks.gemspec +4 -4
- data/lib/i18n/tasks/base_task.rb +2 -1
- data/lib/i18n/tasks/cli.rb +26 -17
- 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 +4 -3
- data/lib/i18n/tasks/command/commands/interpolations.rb +1 -1
- data/lib/i18n/tasks/command/commands/meta.rb +1 -1
- data/lib/i18n/tasks/command/commands/missing.rb +7 -6
- data/lib/i18n/tasks/command/commands/tree.rb +8 -6
- data/lib/i18n/tasks/command/commands/usages.rb +5 -4
- 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/common.rb +6 -0
- 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 +7 -5
- data/lib/i18n/tasks/console_context.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 +5 -2
- data/lib/i18n/tasks/data/tree/nodes.rb +1 -0
- data/lib/i18n/tasks/data/tree/siblings.rb +9 -2
- data/lib/i18n/tasks/data/tree/traversal.rb +11 -2
- 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 +34 -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 +6 -4
- 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 +18 -3
- data/lib/i18n/tasks/scanners/ruby_ast_scanner.rb +16 -13
- 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 +3 -3
- data/lib/i18n/tasks/translators/base_translator.rb +4 -2
- data/lib/i18n/tasks/translators/deepl_translator.rb +16 -3
- data/lib/i18n/tasks/translators/google_translator.rb +2 -0
- data/lib/i18n/tasks/translators/yandex_translator.rb +2 -0
- data/lib/i18n/tasks/used_keys.rb +18 -13
- data/lib/i18n/tasks/version.rb +1 -1
- data/templates/config/i18n-tasks.yml +10 -1
- metadata +10 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ac03642fdf45424834ce7e968e70af9d602c5d5721eda666dbd38635adcf542
|
4
|
+
data.tar.gz: 793b43903d97f1dccead925e5128142886708b279f55f04bcd62c6b349bddead
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 538b6490808142df807dcfa623e6907dd408dc9346e37b2ecbba2257350fa6dcf91b66f8b1f9338cc24fbd7f138ee5c20a7875633c26c9c06ac06dbb87e7e67a
|
7
|
+
data.tar.gz: f7570702d3599d229236ffd3841b33776b3bef50875b12c515b5bc3e63ace2ef2f86fd3058e957959e196c90ace5dc539a5b328a203f0e9f4460b26f3b751778
|
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.35'
|
26
26
|
```
|
27
27
|
|
28
28
|
Copy the default [configuration file](#configuration):
|
@@ -212,7 +212,7 @@ $ i18n-tasks missing -f yaml fr | i18n-tasks tree-set-value 'TRME %{value}' | i1
|
|
212
212
|
$ i18n-tasks unused -f yaml | i18n-tasks data-remove
|
213
213
|
```
|
214
214
|
|
215
|
-
Remove all keys
|
215
|
+
Remove all keys from `fr` that do not exist in `en`. Do not change `en`:
|
216
216
|
```console
|
217
217
|
$ i18n-tasks missing -t diff -f yaml en | i18n-tasks tree-mv en fr | i18n-tasks data-remove
|
218
218
|
```
|
@@ -385,7 +385,7 @@ See the [config file][config] to find out more.
|
|
385
385
|
Where this key is depends on your Google API console:
|
386
386
|
|
387
387
|
* Old console: API Access -> Simple API Access -> Key for server apps.
|
388
|
-
* New console:
|
388
|
+
* New console: Nav Menu -> APIs & Services -> Credentials -> Create Credentials -> API Keys -> Restrict Key -> Cloud Translation API
|
389
389
|
|
390
390
|
In both cases, you may need to create the key if it doesn't exist.
|
391
391
|
|
@@ -405,7 +405,9 @@ translation:
|
|
405
405
|
```yaml
|
406
406
|
# config/i18n-tasks.yml
|
407
407
|
translation:
|
408
|
-
deepl_api_key: <
|
408
|
+
deepl_api_key: <DeepL Pro API key>
|
409
|
+
deepl_host: <optional>
|
410
|
+
deepl_version: <optional>
|
409
411
|
```
|
410
412
|
|
411
413
|
<a name="yandex-translation-config"></a>
|
@@ -437,8 +439,6 @@ Custom tasks can be added easily, see the examples [on the wiki](https://github.
|
|
437
439
|
[badge-travis]: https://img.shields.io/travis/glebm/i18n-tasks.svg
|
438
440
|
[coverage]: https://codeclimate.com/github/glebm/i18n-tasks
|
439
441
|
[badge-coverage]: https://api.codeclimate.com/v1/badges/5d173e90ada8df07cedc/test_coverage
|
440
|
-
[gemnasium]: https://gemnasium.com/glebm/i18n-tasks
|
441
|
-
[badge-gemnasium]: https://gemnasium.com/glebm/i18n-tasks.svg
|
442
442
|
[config]: https://github.com/glebm/i18n-tasks/blob/master/templates/config/i18n-tasks.yml
|
443
443
|
[wiki]: https://github.com/glebm/i18n-tasks/wiki "i18n-tasks wiki"
|
444
444
|
[i18n-gem]: https://github.com/svenfuchs/i18n "svenfuchs/i18n on Github"
|
data/config/locales/en.yml
CHANGED
@@ -11,6 +11,7 @@ en:
|
|
11
11
|
desc:
|
12
12
|
all_locales: Do not expect key patterns to start with a locale, instead apply them to all
|
13
13
|
locales implicitly.
|
14
|
+
config: Override config location
|
14
15
|
confirm: Confirm automatically
|
15
16
|
data_format: 'Data format: %{valid_text}.'
|
16
17
|
keep_order: Keep the order of the keys
|
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]
|
@@ -46,7 +46,7 @@ TEXT
|
|
46
46
|
s.add_development_dependency 'bundler', '~> 2.0', '>= 2.0.1'
|
47
47
|
s.add_development_dependency 'rake'
|
48
48
|
s.add_development_dependency 'rspec', '~> 3.3'
|
49
|
-
s.add_development_dependency 'rubocop', '~>
|
49
|
+
s.add_development_dependency 'rubocop', '~> 1.6.1'
|
50
50
|
s.add_development_dependency 'simplecov'
|
51
51
|
s.add_development_dependency 'yard'
|
52
52
|
|
data/lib/i18n/tasks/base_task.rb
CHANGED
data/lib/i18n/tasks/cli.rb
CHANGED
@@ -15,28 +15,37 @@ 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
|
36
34
|
end
|
37
35
|
|
38
36
|
def run(argv)
|
39
|
-
|
37
|
+
argv.each_with_index do |arg, i|
|
38
|
+
if ["--config", "-c"].include?(arg)
|
39
|
+
if File.exist?(argv[i+1])
|
40
|
+
@config_file = argv[i+1]
|
41
|
+
break
|
42
|
+
else
|
43
|
+
error "Config file doesn't exist: #{argv[i+1]}", 128
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
I18n.with_locale(base_task(config_file: @config_file).internal_locale) do
|
40
49
|
name, *options = parse!(argv.dup)
|
41
50
|
context.run(name, *options)
|
42
51
|
end
|
@@ -54,8 +63,8 @@ class I18n::Tasks::CLI
|
|
54
63
|
|
55
64
|
private
|
56
65
|
|
57
|
-
def base_task
|
58
|
-
@base_task ||= I18n::Tasks::BaseTask.new
|
66
|
+
def base_task(config_file: nil)
|
67
|
+
@base_task ||= I18n::Tasks::BaseTask.new(config_file: config_file)
|
59
68
|
end
|
60
69
|
|
61
70
|
def parse!(argv)
|
@@ -195,7 +204,7 @@ class I18n::Tasks::CLI
|
|
195
204
|
end
|
196
205
|
end
|
197
206
|
|
198
|
-
def auto_output_coloring(coloring = ENV['I18N_TASKS_COLOR'] ||
|
207
|
+
def auto_output_coloring(coloring = ENV['I18N_TASKS_COLOR'] || $stdout.isatty)
|
199
208
|
coloring_was = Rainbow.enabled
|
200
209
|
Rainbow.enabled = coloring
|
201
210
|
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,21 +7,22 @@ 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
|
-
args: %i[locales out_format]
|
12
|
+
args: %i[locales out_format config]
|
13
13
|
|
14
14
|
def health(opt = {})
|
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
21
|
missing(**opt),
|
21
22
|
unused(**opt),
|
22
23
|
check_consistent_interpolations(**opt),
|
23
24
|
check_normalized(**opt)
|
24
|
-
].detect { |result| result == :
|
25
|
+
].detect { |result| result == :exit1 }
|
25
26
|
end
|
26
27
|
end
|
27
28
|
end
|
@@ -14,7 +14,7 @@ module I18n::Tasks
|
|
14
14
|
def check_consistent_interpolations(opt = {})
|
15
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
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,18 +27,18 @@ 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
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
|
|
@@ -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,
|
@@ -10,8 +10,8 @@ module I18n::Tasks
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
def t(*args)
|
14
|
-
I18n.t(*args)
|
13
|
+
def t(*args, **kwargs)
|
14
|
+
I18n.t(*args, **kwargs)
|
15
15
|
end
|
16
16
|
|
17
17
|
module ClassMethods
|
@@ -42,8 +42,8 @@ module I18n::Tasks
|
|
42
42
|
end
|
43
43
|
|
44
44
|
# late-bound I18n.t for module bodies
|
45
|
-
def t(*args)
|
46
|
-
proc { I18n.t(*args) }
|
45
|
+
def t(*args, **kwargs)
|
46
|
+
proc { I18n.t(*args, **kwargs) }
|
47
47
|
end
|
48
48
|
|
49
49
|
# if class is a module, merge DSL definitions when it is included
|
@@ -16,6 +16,7 @@ module I18n::Tasks
|
|
16
16
|
|
17
17
|
def call(value, *)
|
18
18
|
return @valid.first unless value.present?
|
19
|
+
|
19
20
|
if @valid.include?(value)
|
20
21
|
value
|
21
22
|
else
|
@@ -37,6 +38,7 @@ module I18n::Tasks
|
|
37
38
|
def call(values, *)
|
38
39
|
values = Array(values)
|
39
40
|
return @valid if values == %w[all]
|
41
|
+
|
40
42
|
invalid = values - @valid
|
41
43
|
if invalid.empty?
|
42
44
|
if values.empty?
|
@@ -5,12 +5,13 @@ module I18n::Tasks
|
|
5
5
|
module OptionParsers
|
6
6
|
module Locale
|
7
7
|
module Validator
|
8
|
-
VALID_LOCALE_RE = /\A\w[\w
|
8
|
+
VALID_LOCALE_RE = /\A\w[\w\-.]*\z/i.freeze
|
9
9
|
|
10
10
|
def validate!(locale)
|
11
11
|
if VALID_LOCALE_RE !~ locale
|
12
12
|
fail CommandError, I18n.t('i18n_tasks.cmd.errors.invalid_locale', invalid: locale)
|
13
13
|
end
|
14
|
+
|
14
15
|
locale
|
15
16
|
end
|
16
17
|
end
|
@@ -28,6 +28,12 @@ module I18n::Tasks
|
|
28
28
|
'--value VALUE',
|
29
29
|
t('i18n_tasks.cmd.args.desc.value')
|
30
30
|
|
31
|
+
arg :config,
|
32
|
+
'-c',
|
33
|
+
'--config FILE',
|
34
|
+
t('i18n_tasks.cmd.args.desc.config')
|
35
|
+
|
36
|
+
|
31
37
|
def arg_or_pos!(key, opts)
|
32
38
|
opts[key] ||= opts[:arguments].try(:shift)
|
33
39
|
end
|
@@ -64,6 +64,7 @@ module I18n::Tasks
|
|
64
64
|
# @return [I18n::Tasks::Data::Tree::Siblings]
|
65
65
|
def parse_forest(src, format)
|
66
66
|
fail CommandError, I18n.t('i18n_tasks.cmd.errors.pass_forest') unless src
|
67
|
+
|
67
68
|
if format == 'keys'
|
68
69
|
::I18n::Tasks::Data::Tree::Siblings.from_key_names parse_keys(src)
|
69
70
|
else
|
@@ -13,22 +13,22 @@ module I18n::Tasks
|
|
13
13
|
'--locales en,es,ru',
|
14
14
|
Array,
|
15
15
|
t('i18n_tasks.cmd.args.desc.locales_filter'),
|
16
|
-
parser:
|
17
|
-
default:
|
16
|
+
parser: OptionParsers::Locale::ListParser,
|
17
|
+
default: 'all',
|
18
18
|
consume_positional: true
|
19
19
|
|
20
20
|
arg :locale,
|
21
21
|
'-l',
|
22
22
|
'--locale en',
|
23
23
|
t('i18n_tasks.cmd.args.desc.locale'),
|
24
|
-
parser:
|
24
|
+
parser: OptionParsers::Locale::Parser,
|
25
25
|
default: 'base'
|
26
26
|
|
27
27
|
arg :locale_to_translate_from,
|
28
28
|
'-f',
|
29
29
|
'--from en',
|
30
30
|
t('i18n_tasks.cmd.args.desc.locale_to_translate_from'),
|
31
|
-
parser:
|
31
|
+
parser: OptionParsers::Locale::Parser,
|
32
32
|
default: 'base'
|
33
33
|
|
34
34
|
TRANSLATION_BACKENDS = %w[google deepl].freeze
|
@@ -36,7 +36,7 @@ module I18n::Tasks
|
|
36
36
|
'-b',
|
37
37
|
'--backend BACKEND',
|
38
38
|
t('i18n_tasks.cmd.args.desc.translation_backend'),
|
39
|
-
parser:
|
39
|
+
parser: OptionParsers::Locale::Parser,
|
40
40
|
default: TRANSLATION_BACKENDS[0]
|
41
41
|
end
|
42
42
|
end
|
@@ -19,8 +19,10 @@ module I18n::Tasks::Concurrent
|
|
19
19
|
# @return [Object] Result of the computation.
|
20
20
|
def get
|
21
21
|
return get_result_volatile unless get_result_volatile == NULL
|
22
|
+
|
22
23
|
@mutex.synchronize do
|
23
24
|
next unless get_result_volatile == NULL
|
25
|
+
|
24
26
|
set_result_volatile @computation.call
|
25
27
|
@computation = nil
|
26
28
|
end
|
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
module I18n::Tasks::Configuration # rubocop:disable Metrics/ModuleLength
|
4
4
|
DEFAULTS = {
|
5
|
-
base_locale:
|
5
|
+
base_locale: 'en',
|
6
6
|
internal_locale: 'en',
|
7
|
-
search:
|
8
|
-
data:
|
7
|
+
search: ::I18n::Tasks::UsedKeys::SEARCH_DEFAULTS,
|
8
|
+
data: ::I18n::Tasks::Data::DATA_DEFAULTS
|
9
9
|
}.freeze
|
10
10
|
|
11
11
|
# i18n-tasks config (defaults + config/i18n-tasks.yml)
|
@@ -20,7 +20,7 @@ module I18n::Tasks::Configuration # rubocop:disable Metrics/ModuleLength
|
|
20
20
|
].freeze
|
21
21
|
|
22
22
|
def file_config
|
23
|
-
file = CONFIG_FILES.detect { |f| File.exist?(f) }
|
23
|
+
file = @config_override || CONFIG_FILES.detect { |f| File.exist?(f) }
|
24
24
|
# rubocop:disable Security/Eval
|
25
25
|
config = file && YAML.load(eval(Erubi::Engine.new(File.read(file, encoding: 'UTF-8')).src))
|
26
26
|
# rubocop:enable Security/Eval
|
@@ -47,7 +47,7 @@ module I18n::Tasks::Configuration # rubocop:disable Metrics/ModuleLength
|
|
47
47
|
@config_sections[:data] ||= begin
|
48
48
|
{
|
49
49
|
adapter: data.class.name,
|
50
|
-
config:
|
50
|
+
config: data.config
|
51
51
|
}
|
52
52
|
end
|
53
53
|
end
|
@@ -59,6 +59,8 @@ module I18n::Tasks::Configuration # rubocop:disable Metrics/ModuleLength
|
|
59
59
|
conf = (config[:translation] || {}).with_indifferent_access
|
60
60
|
conf[:google_translate_api_key] = ENV['GOOGLE_TRANSLATE_API_KEY'] if ENV.key?('GOOGLE_TRANSLATE_API_KEY')
|
61
61
|
conf[:deepl_api_key] = ENV['DEEPL_AUTH_KEY'] if ENV.key?('DEEPL_AUTH_KEY')
|
62
|
+
conf[:deepl_host] = ENV['DEEPL_HOST'] if ENV.key?('DEEPL_HOST')
|
63
|
+
conf[:deepl_version] = ENV['DEEPL_VERSION'] if ENV.key?('DEEPL_VERSION')
|
62
64
|
conf[:yandex_api_key] = ENV['YANDEX_API_KEY'] if ENV.key?('YANDEX_API_KEY')
|
63
65
|
conf
|
64
66
|
end
|
@@ -34,7 +34,7 @@ module I18n::Tasks
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def guide
|
37
|
-
Rainbow('i18n-tasks IRB Quick Start guide').green.bright
|
37
|
+
"#{Rainbow('i18n-tasks IRB Quick Start guide').green.bright}\n#{<<~TEXT}"
|
38
38
|
#{Rainbow('Data as trees').yellow}
|
39
39
|
tree(locale)
|
40
40
|
used_tree(key_filter: nil, strict: nil)
|
@@ -53,12 +53,14 @@ module I18n
|
|
53
53
|
content = adapter_dump(hash, adapter)
|
54
54
|
# Ignore unchanged data
|
55
55
|
return if File.file?(path) && content == read_file(path)
|
56
|
+
|
56
57
|
::FileUtils.mkpath(File.dirname(path))
|
57
58
|
::File.open(path, 'w') { |f| f.write content }
|
58
59
|
end
|
59
60
|
|
60
61
|
def normalized?(path, tree)
|
61
62
|
return false unless File.file?(path)
|
63
|
+
|
62
64
|
read_file(path) == adapter_dump(tree.to_hash(true), self.class.adapter_name_for_path(path))
|
63
65
|
end
|
64
66
|
|