i18n-tasks 0.9.23 → 0.9.24
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 -5
- data/config/locales/en.yml +0 -4
- data/config/locales/ru.yml +0 -4
- data/i18n-tasks.gemspec +3 -3
- data/lib/i18n/tasks/command/commander.rb +0 -5
- data/lib/i18n/tasks/command/commands/missing.rb +1 -6
- data/lib/i18n/tasks/command/commands/tree.rb +2 -20
- data/lib/i18n/tasks/commands.rb +0 -2
- data/lib/i18n/tasks/data/tree/siblings.rb +0 -14
- data/lib/i18n/tasks/translation.rb +10 -9
- data/lib/i18n/tasks/translators/deepl_translator.rb +5 -1
- data/lib/i18n/tasks/translators/google_translator.rb +9 -1
- data/lib/i18n/tasks/version.rb +1 -1
- metadata +32 -34
- data/lib/i18n/tasks/command/commands/xlsx.rb +0 -28
- data/lib/i18n/tasks/reports/spreadsheet.rb +0 -69
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e43145655fa3f1bfe8346745641fbab0cbcdc6d4fce7644360f47dc22c2d1c57
|
4
|
+
data.tar.gz: 3ec016b5aca6502d4a8cc73e9f1850e6d87a6469e631d27a2b9710538b696e34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc3f0df2e53aef54e7fa0d1953c3d448a4ccc57c8a04f60b1494ea3500b8b98d7473548683c62f5c36795a3bd20eab16ee4d2a898f2de6ca21b6cfd64d7dd67f
|
7
|
+
data.tar.gz: d744f48d0b9572e93906cddce55004eadd8a8aa867f6ca436540bedb989274077a641d83c28b5a034adb1a7106d70a2cbac069301d2febcd32eb25e44c674ab8
|
data/README.md
CHANGED
@@ -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.24'
|
26
26
|
```
|
27
27
|
|
28
28
|
Copy the default [configuration file](#configuration):
|
@@ -87,8 +87,9 @@ Translate missing values with Google Translate ([more below on the API key](#goo
|
|
87
87
|
|
88
88
|
```console
|
89
89
|
$ i18n-tasks translate-missing
|
90
|
+
|
90
91
|
# accepts from and locales options:
|
91
|
-
$ i18n-tasks translate-missing --from
|
92
|
+
$ i18n-tasks translate-missing --from=base es fr
|
92
93
|
```
|
93
94
|
|
94
95
|
### DeepL Pro Translate missing keys
|
@@ -96,9 +97,10 @@ $ i18n-tasks translate-missing --from base es fr
|
|
96
97
|
Translate missing values with DeepL Pro Translate ([more below on the API key](#deepl-translation-config)).
|
97
98
|
|
98
99
|
```console
|
99
|
-
$ i18n-tasks translate-missing
|
100
|
+
$ i18n-tasks translate-missing --backend=deepl
|
101
|
+
|
100
102
|
# accepts from and locales options:
|
101
|
-
$ i18n-tasks translate-missing --backend
|
103
|
+
$ i18n-tasks translate-missing --backend=deepl --from=en fr nl
|
102
104
|
```
|
103
105
|
|
104
106
|
### Find usages
|
@@ -385,7 +387,7 @@ translation:
|
|
385
387
|
|
386
388
|
`i18n-tasks irb` starts an IRB session in i18n-tasks context. Type `guide` for more information.
|
387
389
|
|
388
|
-
|
390
|
+
## Import / export to a CSV spreadsheet
|
389
391
|
|
390
392
|
See [i18n-tasks wiki: CSV import and export tasks](https://github.com/glebm/i18n-tasks/wiki/Custom-CSV-import-and-export-tasks).
|
391
393
|
|
data/config/locales/en.yml
CHANGED
@@ -53,12 +53,10 @@ en:
|
|
53
53
|
tree_filter: filter tree by key pattern
|
54
54
|
tree_merge: merge trees
|
55
55
|
tree_mv_key: rename/merge/remove the keys matching the given pattern
|
56
|
-
tree_rename_key: rename tree node
|
57
56
|
tree_set_value: set values of keys, optionally match a pattern
|
58
57
|
tree_subtract: tree A minus the keys in tree B
|
59
58
|
tree_translate: Google Translate a tree to root locales
|
60
59
|
unused: show unused translations
|
61
|
-
xlsx_report: save missing and unused translations to an Excel file
|
62
60
|
encourage:
|
63
61
|
- Good job!
|
64
62
|
- Well done!
|
@@ -75,12 +73,10 @@ en:
|
|
75
73
|
other: 'unknown types: %{invalid}. valid: %{valid}.'
|
76
74
|
pass_forest: pass locale forest
|
77
75
|
common:
|
78
|
-
base_value: Base Value
|
79
76
|
continue_q: Continue?
|
80
77
|
key: Key
|
81
78
|
locale: Locale
|
82
79
|
n_more: "%{count} more"
|
83
|
-
type: Type
|
84
80
|
value: Value
|
85
81
|
data_stats:
|
86
82
|
text: >-
|
data/config/locales/ru.yml
CHANGED
@@ -50,12 +50,10 @@ ru:
|
|
50
50
|
tree_filter: фильтровать дерево по ключу
|
51
51
|
tree_merge: объединенить деревья
|
52
52
|
tree_mv_key: переименованить / объединить / удалить ключи соответствующие заданному шаблону
|
53
|
-
tree_rename_key: переименовать узел дерева
|
54
53
|
tree_set_value: заменить значения ключей
|
55
54
|
tree_subtract: дерево A минус ключи в дереве B
|
56
55
|
tree_translate: Перевести дерево при помощи Google Translate на язык корневых узлов
|
57
56
|
unused: показать неиспользуемые переводы
|
58
|
-
xlsx_report: сохранить недостающие и неиспользуемые переводы в Excel-файл
|
59
57
|
encourage:
|
60
58
|
- Хорошая работа!
|
61
59
|
- Отлично!
|
@@ -72,12 +70,10 @@ ru:
|
|
72
70
|
other: 'Неизвестные типы: %{invalid}. Типы: %{valid}.'
|
73
71
|
pass_forest: Передайте дерево
|
74
72
|
common:
|
75
|
-
base_value: Исходное значение
|
76
73
|
continue_q: Продолжить?
|
77
74
|
key: Ключ
|
78
75
|
locale: Язык
|
79
76
|
n_more: ещё %{count}
|
80
|
-
type: Тип
|
81
77
|
value: Значение
|
82
78
|
data_stats:
|
83
79
|
text: >-
|
data/i18n-tasks.gemspec
CHANGED
@@ -37,16 +37,16 @@ TEXT
|
|
37
37
|
|
38
38
|
s.add_dependency 'activesupport', '>= 4.0.2'
|
39
39
|
s.add_dependency 'ast', '>= 2.1.0'
|
40
|
-
s.add_dependency 'deepl-rb', '>= 2.1.0'
|
41
|
-
s.add_dependency 'easy_translate', '>= 0.5.1'
|
42
40
|
s.add_dependency 'erubi'
|
43
|
-
s.add_dependency 'highline', '>=
|
41
|
+
s.add_dependency 'highline', '>= 2.0.0'
|
44
42
|
s.add_dependency 'i18n'
|
45
43
|
s.add_dependency 'parser', '>= 2.2.3.0'
|
46
44
|
s.add_dependency 'rainbow', '>= 2.2.2', '< 4.0'
|
47
45
|
s.add_dependency 'terminal-table', '>= 1.5.1'
|
48
46
|
s.add_development_dependency 'axlsx', '~> 2.0'
|
49
47
|
s.add_development_dependency 'bundler', '~> 1.3'
|
48
|
+
s.add_development_dependency 'deepl-rb', '>= 2.1.0'
|
49
|
+
s.add_development_dependency 'easy_translate', '>= 0.5.1'
|
50
50
|
s.add_development_dependency 'rake'
|
51
51
|
s.add_development_dependency 'rspec', '~> 3.3'
|
52
52
|
s.add_development_dependency 'rubocop', '~> 0.53.0'
|
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'i18n/tasks/cli'
|
4
4
|
require 'i18n/tasks/reports/terminal'
|
5
|
-
require 'i18n/tasks/reports/spreadsheet'
|
6
5
|
|
7
6
|
module I18n::Tasks
|
8
7
|
module Command
|
@@ -33,10 +32,6 @@ module I18n::Tasks
|
|
33
32
|
@terminal_report ||= I18n::Tasks::Reports::Terminal.new(i18n)
|
34
33
|
end
|
35
34
|
|
36
|
-
def spreadsheet_report
|
37
|
-
@spreadsheet_report ||= I18n::Tasks::Reports::Spreadsheet.new(i18n)
|
38
|
-
end
|
39
|
-
|
40
35
|
delegate :base_locale, :locales, :t, to: :i18n
|
41
36
|
end
|
42
37
|
end
|
@@ -40,12 +40,7 @@ module I18n::Tasks
|
|
40
40
|
|
41
41
|
def translate_missing(opt = {})
|
42
42
|
missing = i18n.missing_diff_forest opt[:locales], opt[:from]
|
43
|
-
translated =
|
44
|
-
when 'deepl'
|
45
|
-
i18n.deepl_translate_forest missing, opt[:from]
|
46
|
-
when 'google'
|
47
|
-
i18n.google_translate_forest missing, opt[:from]
|
48
|
-
end
|
43
|
+
translated = i18n.translate_forest missing, from: opt[:from], backend: opt[:backend].to_sym
|
49
44
|
i18n.data.merge! translated
|
50
45
|
log_stderr t('i18n_tasks.translate_missing.translated', count: translated.leaves.count)
|
51
46
|
print_forest translated, opt
|
@@ -10,11 +10,11 @@ module I18n::Tasks
|
|
10
10
|
cmd :tree_translate,
|
11
11
|
pos: '[tree (or stdin)]',
|
12
12
|
desc: t('i18n_tasks.cmd.desc.tree_translate'),
|
13
|
-
args: [:locale_to_translate_from, arg(:data_format).from(1)]
|
13
|
+
args: [:locale_to_translate_from, arg(:data_format).from(1), :translation_backend]
|
14
14
|
|
15
15
|
def tree_translate(opts = {})
|
16
16
|
forest = forest_pos_or_stdin!(opts)
|
17
|
-
print_forest i18n.
|
17
|
+
print_forest i18n.translate_forest(forest, from: opts[:from], backend: opts[:backend].to_sym), opts
|
18
18
|
end
|
19
19
|
|
20
20
|
cmd :tree_merge,
|
@@ -41,24 +41,6 @@ module I18n::Tasks
|
|
41
41
|
print_forest forest, opts
|
42
42
|
end
|
43
43
|
|
44
|
-
cmd :tree_rename_key,
|
45
|
-
pos: 'KEY_PATTERN NAME [tree (or stdin)]',
|
46
|
-
desc: t('i18n_tasks.cmd.desc.tree_rename_key'),
|
47
|
-
args: [['-k', '--key KEY_PATTERN', t('i18n_tasks.cmd.args.desc.key_pattern_to_rename')],
|
48
|
-
['-n', '--name NAME', t('i18n_tasks.cmd.args.desc.new_key_name')],
|
49
|
-
:data_format]
|
50
|
-
|
51
|
-
def tree_rename_key(opt = {})
|
52
|
-
warn_deprecated 'Use tree-mv instead.'
|
53
|
-
key = arg_or_pos! :key, opt
|
54
|
-
name = arg_or_pos! :name, opt
|
55
|
-
forest = forest_pos_or_stdin! opt
|
56
|
-
fail CommandError, 'pass full key to rename (-k, --key)' if key.blank?
|
57
|
-
fail CommandError, 'pass new name (-n, --name)' if name.blank?
|
58
|
-
forest.rename_each_key!(key, name)
|
59
|
-
print_forest forest, opt
|
60
|
-
end
|
61
|
-
|
62
44
|
arg :all_locales,
|
63
45
|
'-a',
|
64
46
|
'--all-locales',
|
data/lib/i18n/tasks/commands.rb
CHANGED
@@ -9,7 +9,6 @@ require 'i18n/tasks/command/commands/eq_base'
|
|
9
9
|
require 'i18n/tasks/command/commands/data'
|
10
10
|
require 'i18n/tasks/command/commands/tree'
|
11
11
|
require 'i18n/tasks/command/commands/meta'
|
12
|
-
require 'i18n/tasks/command/commands/xlsx'
|
13
12
|
require 'i18n/tasks/command/commander'
|
14
13
|
|
15
14
|
module I18n::Tasks
|
@@ -22,7 +21,6 @@ module I18n::Tasks
|
|
22
21
|
include Command::Commands::Data
|
23
22
|
include Command::Commands::Tree
|
24
23
|
include Command::Commands::Meta
|
25
|
-
include Command::Commands::XLSX
|
26
24
|
|
27
25
|
require 'highline/import'
|
28
26
|
end
|
@@ -32,20 +32,6 @@ module I18n::Tasks::Data::Tree
|
|
32
32
|
self
|
33
33
|
end
|
34
34
|
|
35
|
-
def rename_each_key!(full_key_pattern, new_key_tpl)
|
36
|
-
pattern_re = I18n::Tasks::KeyPatternMatching.compile_key_pattern(full_key_pattern)
|
37
|
-
nodes do |node|
|
38
|
-
next if node.full_key(root: true) !~ pattern_re
|
39
|
-
new_key = new_key_tpl.gsub('%{key}', node.key)
|
40
|
-
if node.parent == parent
|
41
|
-
rename_key(node.key, new_key)
|
42
|
-
else
|
43
|
-
node.parent.children.rename_key(node.key, new_key)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
self
|
47
|
-
end
|
48
|
-
|
49
35
|
# @param from_pattern [Regexp]
|
50
36
|
# @param to_pattern [Regexp]
|
51
37
|
# @param root [Boolean]
|
@@ -7,16 +7,17 @@ module I18n::Tasks
|
|
7
7
|
module Translation
|
8
8
|
# @param [I18n::Tasks::Tree::Siblings] forest to translate to the locales of its root nodes
|
9
9
|
# @param [String] from locale
|
10
|
+
# @param [:deepl, :google] backend
|
10
11
|
# @return [I18n::Tasks::Tree::Siblings] translated forest
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
def translate_forest(forest, from:, backend: :google)
|
13
|
+
case backend
|
14
|
+
when :deepl
|
15
|
+
Translators::DeeplTranslator.new(self).translate_forest(forest, from)
|
16
|
+
when :google
|
17
|
+
Translators::GoogleTranslator.new(self).translate_forest(forest, from)
|
18
|
+
else
|
19
|
+
fail CommandError, "invalid backend: #{backend}"
|
20
|
+
end
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
@@ -1,11 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'deepl'
|
4
3
|
require 'i18n/tasks/translators/base_translator'
|
5
4
|
|
6
5
|
module I18n::Tasks::Translators
|
7
6
|
class DeeplTranslator < BaseTranslator
|
8
7
|
def initialize(*)
|
8
|
+
begin
|
9
|
+
require 'deepl'
|
10
|
+
rescue LoadError
|
11
|
+
raise ::I18n::Tasks::CommandError, "Add gem 'deepl-rb' to your Gemfile to use this command"
|
12
|
+
end
|
9
13
|
super
|
10
14
|
configure_api_key!
|
11
15
|
end
|
@@ -1,10 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'easy_translate'
|
4
3
|
require 'i18n/tasks/translators/base_translator'
|
5
4
|
|
6
5
|
module I18n::Tasks::Translators
|
7
6
|
class GoogleTranslator < BaseTranslator
|
7
|
+
def initialize(*)
|
8
|
+
begin
|
9
|
+
require 'easy_translate'
|
10
|
+
rescue LoadError
|
11
|
+
raise ::I18n::Tasks::CommandError, "Add gem 'easy_translate' to your Gemfile to use this command"
|
12
|
+
end
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
8
16
|
protected
|
9
17
|
|
10
18
|
def translate_values(list, **options)
|
data/lib/i18n/tasks/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n-tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.24
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- glebm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -38,34 +38,6 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 2.1.0
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: deepl-rb
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 2.1.0
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 2.1.0
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: easy_translate
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 0.5.1
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 0.5.1
|
69
41
|
- !ruby/object:Gem::Dependency
|
70
42
|
name: erubi
|
71
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +58,14 @@ dependencies:
|
|
86
58
|
requirements:
|
87
59
|
- - ">="
|
88
60
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
61
|
+
version: 2.0.0
|
90
62
|
type: :runtime
|
91
63
|
prerelease: false
|
92
64
|
version_requirements: !ruby/object:Gem::Requirement
|
93
65
|
requirements:
|
94
66
|
- - ">="
|
95
67
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
68
|
+
version: 2.0.0
|
97
69
|
- !ruby/object:Gem::Dependency
|
98
70
|
name: i18n
|
99
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,6 +156,34 @@ dependencies:
|
|
184
156
|
- - "~>"
|
185
157
|
- !ruby/object:Gem::Version
|
186
158
|
version: '1.3'
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: deepl-rb
|
161
|
+
requirement: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: 2.1.0
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: 2.1.0
|
173
|
+
- !ruby/object:Gem::Dependency
|
174
|
+
name: easy_translate
|
175
|
+
requirement: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: 0.5.1
|
180
|
+
type: :development
|
181
|
+
prerelease: false
|
182
|
+
version_requirements: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - ">="
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: 0.5.1
|
187
187
|
- !ruby/object:Gem::Dependency
|
188
188
|
name: rake
|
189
189
|
requirement: !ruby/object:Gem::Requirement
|
@@ -286,7 +286,6 @@ files:
|
|
286
286
|
- lib/i18n/tasks/command/commands/missing.rb
|
287
287
|
- lib/i18n/tasks/command/commands/tree.rb
|
288
288
|
- lib/i18n/tasks/command/commands/usages.rb
|
289
|
-
- lib/i18n/tasks/command/commands/xlsx.rb
|
290
289
|
- lib/i18n/tasks/command/dsl.rb
|
291
290
|
- lib/i18n/tasks/command/option_parsers/enum.rb
|
292
291
|
- lib/i18n/tasks/command/option_parsers/locale.rb
|
@@ -320,7 +319,6 @@ files:
|
|
320
319
|
- lib/i18n/tasks/rainbow_utils.rb
|
321
320
|
- lib/i18n/tasks/references.rb
|
322
321
|
- lib/i18n/tasks/reports/base.rb
|
323
|
-
- lib/i18n/tasks/reports/spreadsheet.rb
|
324
322
|
- lib/i18n/tasks/reports/terminal.rb
|
325
323
|
- lib/i18n/tasks/scanners/file_scanner.rb
|
326
324
|
- lib/i18n/tasks/scanners/files/caching_file_finder.rb
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module I18n::Tasks
|
4
|
-
module Command
|
5
|
-
module Commands
|
6
|
-
module XLSX
|
7
|
-
include Command::Collection
|
8
|
-
|
9
|
-
cmd :xlsx_report,
|
10
|
-
pos: '[locale...]',
|
11
|
-
desc: t('i18n_tasks.cmd.desc.xlsx_report'),
|
12
|
-
args: [:locales,
|
13
|
-
['-p', '--path PATH', 'Destination path', default: 'tmp/i18n-report.xlsx']]
|
14
|
-
|
15
|
-
def xlsx_report(opt = {})
|
16
|
-
begin
|
17
|
-
require 'axlsx'
|
18
|
-
rescue LoadError
|
19
|
-
message = %(For spreadsheet report please add axlsx gem to Gemfile:\ngem 'axlsx', '~> 2.0')
|
20
|
-
log_stderr Rainbow(message).red.bright
|
21
|
-
exit 1
|
22
|
-
end
|
23
|
-
spreadsheet_report.save_report opt[:path], opt.except(:path)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'i18n/tasks/reports/base'
|
4
|
-
require 'fileutils'
|
5
|
-
|
6
|
-
module I18n::Tasks::Reports
|
7
|
-
class Spreadsheet < Base
|
8
|
-
def save_report(path, _opts)
|
9
|
-
path = path.presence || 'tmp/i18n-report.xlsx'
|
10
|
-
p = Axlsx::Package.new
|
11
|
-
p.use_shared_strings = true # see #159
|
12
|
-
add_missing_sheet p.workbook
|
13
|
-
add_unused_sheet p.workbook
|
14
|
-
add_eq_base_sheet p.workbook
|
15
|
-
FileUtils.mkpath(File.dirname(path))
|
16
|
-
p.serialize(path)
|
17
|
-
$stderr.puts Rainbow("Saved to #{path}").green
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def add_missing_sheet(wb) # rubocop:disable Metrics/AbcSize
|
23
|
-
forest = collapse_missing_tree! task.missing_keys
|
24
|
-
wb.styles do |s|
|
25
|
-
type_cell = s.add_style alignment: { horizontal: :center }
|
26
|
-
locale_cell = s.add_style alignment: { horizontal: :center }
|
27
|
-
regular_style = s.add_style
|
28
|
-
wb.add_worksheet(name: missing_title(forest)) do |sheet|
|
29
|
-
sheet.page_setup.fit_to width: 1
|
30
|
-
sheet.add_row [I18n.t('i18n_tasks.common.type'), I18n.t('i18n_tasks.common.locale'),
|
31
|
-
I18n.t('i18n_tasks.common.key'), I18n.t('i18n_tasks.common.base_value')]
|
32
|
-
style_header sheet
|
33
|
-
forest.keys do |key, node|
|
34
|
-
locale = format_locale(node.root.data[:locale])
|
35
|
-
type = node.data[:type]
|
36
|
-
sheet.add_row [missing_type_info(type)[:summary], locale, key, task.t(key)],
|
37
|
-
styles: [type_cell, locale_cell, regular_style, regular_style]
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def add_eq_base_sheet(wb)
|
44
|
-
keys = task.eq_base_keys.root_key_values(true)
|
45
|
-
add_locale_key_value_table wb, keys, name: eq_base_title(keys)
|
46
|
-
end
|
47
|
-
|
48
|
-
def add_unused_sheet(wb)
|
49
|
-
keys = task.unused_keys.root_key_values(true)
|
50
|
-
add_locale_key_value_table wb, keys, name: unused_title(keys)
|
51
|
-
end
|
52
|
-
|
53
|
-
def add_locale_key_value_table(wb, keys, worksheet_opts = {})
|
54
|
-
wb.add_worksheet worksheet_opts do |sheet|
|
55
|
-
sheet.add_row [I18n.t('i18n_tasks.common.locale'), I18n.t('i18n_tasks.common.key'),
|
56
|
-
I18n.t('i18n_tasks.common.value')]
|
57
|
-
style_header sheet
|
58
|
-
keys.each do |locale_k_v|
|
59
|
-
sheet.add_row locale_k_v
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def style_header(sheet)
|
65
|
-
border_bottom = sheet.workbook.styles.add_style(border: { style: :thin, color: '000000', edges: [:bottom] })
|
66
|
-
sheet.rows.first.style = border_bottom
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|