i18n-tasks 0.7.12 → 0.7.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -4
- data/CHANGES.md +6 -0
- data/Gemfile +2 -1
- data/README.md +1 -1
- data/config/locales/en.yml +4 -2
- data/config/locales/ru.yml +3 -3
- data/lib/i18n/tasks/command/commands/tree.rb +5 -6
- data/lib/i18n/tasks/command/options/locales.rb +3 -3
- data/lib/i18n/tasks/configuration.rb +1 -1
- data/lib/i18n/tasks/data/file_formats.rb +1 -1
- data/lib/i18n/tasks/missing_keys.rb +4 -2
- data/lib/i18n/tasks/reports/spreadsheet.rb +0 -1
- data/lib/i18n/tasks/reports/terminal.rb +19 -15
- data/lib/i18n/tasks/scanners/base_scanner.rb +7 -6
- data/lib/i18n/tasks/scanners/pattern_scanner.rb +1 -1
- data/lib/i18n/tasks/scanners/relative_keys.rb +2 -1
- data/lib/i18n/tasks/used_keys.rb +1 -2
- data/lib/i18n/tasks/version.rb +1 -1
- data/spec/commands/tree_commands_spec.rb +7 -6
- data/spec/file_system_data_spec.rb +1 -1
- data/spec/fixtures/app/views/index.html.slim +2 -0
- data/spec/i18n_tasks_spec.rb +33 -41
- data/spec/relative_keys_spec.rb +13 -0
- data/spec/support/i18n_tasks_output_matcher.rb +0 -1
- data/spec/support/test_codebase.rb +1 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f23b45a33ecdc2b1ff1ce24733bbfc7561e64462
|
4
|
+
data.tar.gz: 4b09900b186afbf6ee67276cca45847f0d8e15f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b1cca5e5a2f5ede2defb56fe16bf9f15ba1546c2b610ebaeb282538611a800ad93f8cfb7521b13888cbecda2ca73e2718e2624250f989ffd0a7ad7350a557cf
|
7
|
+
data.tar.gz: d42a79921370c760f5fc557c9344d47e921580abf198fb00e19138474825b609f80104965eb7fc753de3ecacbf01a5e46390e8898e44c5a71c6806b2524c24ba
|
data/.travis.yml
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.2.
|
4
|
-
- 2.1.5
|
5
|
-
- 2.0.0
|
3
|
+
- 2.2.1
|
6
4
|
- 1.9.3
|
7
5
|
- jruby
|
8
|
-
- rbx
|
6
|
+
- rbx
|
7
|
+
# travis uses old bundler (https://travis-ci.org/glebm/i18n-tasks/jobs/53485782)
|
8
|
+
before_install: gem install bundler
|
9
|
+
cache: bundler
|
10
|
+
script: bundle exec rspec
|
9
11
|
env:
|
10
12
|
global:
|
11
13
|
- TRAVIS=1
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 0.7.13
|
2
|
+
|
3
|
+
* Fix relative keys when controller name consists of more than one word by [Yuji Nakayama](https://github.com/yujinakayama) [#132](https://github.com/glebm/i18n-tasks/pull/132).
|
4
|
+
* Support keys with UTF8 word characters in the name. [#133](https://github.com/glebm/i18n-tasks/issues/133).
|
5
|
+
* Change missing report column title from "Details" to "Value in other locales or source", display the locale [#130](https://github.com/glebm/i18n-tasks/issues/130).
|
6
|
+
|
1
7
|
## 0.7.12
|
2
8
|
|
3
9
|
* Handle relative keys in controllers nested in modules by [Alexander Tipugin](https://github.com/atipugin). [#128](https://github.com/glebm/i18n-tasks/issues/128).
|
data/Gemfile
CHANGED
@@ -4,7 +4,8 @@ source 'https://rubygems.org'
|
|
4
4
|
gemspec
|
5
5
|
|
6
6
|
group :development do
|
7
|
-
gem 'byebug',
|
7
|
+
gem 'byebug', platforms: [:mri_21, :mri_22], require: false
|
8
|
+
gem 'rubinius-debugger', platform: :rbx, require: false
|
8
9
|
end
|
9
10
|
|
10
11
|
gem 'codeclimate-test-reporter', group: :test, require: nil
|
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 it to the Gemfile:
|
23
23
|
|
24
24
|
```ruby
|
25
|
-
gem 'i18n-tasks', '~> 0.7.
|
25
|
+
gem 'i18n-tasks', '~> 0.7.13'
|
26
26
|
```
|
27
27
|
|
28
28
|
Copy default [configuration file](#configuration) (optional):
|
data/config/locales/en.yml
CHANGED
@@ -2,7 +2,9 @@
|
|
2
2
|
en:
|
3
3
|
i18n_tasks:
|
4
4
|
add_missing:
|
5
|
-
added:
|
5
|
+
added:
|
6
|
+
one: Added %{count} key
|
7
|
+
other: Added %{count} keys
|
6
8
|
cmd:
|
7
9
|
args:
|
8
10
|
default_all: 'Default: all'
|
@@ -67,7 +69,6 @@ en:
|
|
67
69
|
common:
|
68
70
|
base_value: Base Value
|
69
71
|
continue_q: Continue?
|
70
|
-
details: Details
|
71
72
|
key: Key
|
72
73
|
locale: Locale
|
73
74
|
n_more: "%{count} more"
|
@@ -88,6 +89,7 @@ en:
|
|
88
89
|
health:
|
89
90
|
no_keys_detected: No keys detected. Check data.read in config/i18n-tasks.yml.
|
90
91
|
missing:
|
92
|
+
details_title: Value in other locales or source
|
91
93
|
none: No translations are missing.
|
92
94
|
remove_unused:
|
93
95
|
confirm:
|
data/config/locales/ru.yml
CHANGED
@@ -68,7 +68,6 @@ ru:
|
|
68
68
|
common:
|
69
69
|
base_value: "Исходное значение"
|
70
70
|
continue_q: "Продолжить?"
|
71
|
-
details: "Детали"
|
72
71
|
key: "Ключ"
|
73
72
|
locale: "Язык"
|
74
73
|
n_more: "ещё %{count}"
|
@@ -82,13 +81,14 @@ ru:
|
|
82
81
|
title: "Данные (%{locales}):"
|
83
82
|
google_translate:
|
84
83
|
errors:
|
85
|
-
no_api_key: Задайте ключ API Google через переменную окружения GOOGLE_TRANSLATE_API_KEY
|
86
|
-
|
84
|
+
no_api_key: "Задайте ключ API Google через переменную окружения GOOGLE_TRANSLATE_API_KEY или
|
85
|
+
translation.api_key в config/i18n-tasks.yml. Получите ключ через https://code.google.com/apis/console."
|
87
86
|
no_results: Google Translate не дал результатов. Убедитесь в том, что платежная информация
|
88
87
|
добавлена в https://code.google.com/apis/console.
|
89
88
|
health:
|
90
89
|
no_keys_detected: "Ключи не обнаружены. Проверьте data.read в config/i18n-tasks.yml."
|
91
90
|
missing:
|
91
|
+
details_title: "На других языках или в коде"
|
92
92
|
none: "Всё переведено."
|
93
93
|
remove_unused:
|
94
94
|
confirm:
|
@@ -43,12 +43,11 @@ module I18n::Tasks
|
|
43
43
|
cmd :tree_rename_key,
|
44
44
|
args: '<key> <name> [tree]',
|
45
45
|
desc: t('i18n_tasks.cmd.desc.tree_rename_key'),
|
46
|
-
opt: [
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
] + cmd_opts(:data_format)
|
46
|
+
opt: [cmd_opt(:pattern).merge(short: :k, long: :key=,
|
47
|
+
desc: t('i18n_tasks.cmd.args.desc.key_pattern_to_rename')),
|
48
|
+
cmd_opt(:pattern).merge(short: :n, long: :name=,
|
49
|
+
desc: t('i18n_tasks.cmd.args.desc.new_key_name')),
|
50
|
+
*cmd_opts(:data_format)]
|
52
51
|
|
53
52
|
def tree_rename_key(opt = {})
|
54
53
|
key = opt_or_arg! :key, opt
|
@@ -43,10 +43,10 @@ module I18n::Tasks
|
|
43
43
|
opt[key]
|
44
44
|
end
|
45
45
|
|
46
|
-
VALID_LOCALE_RE = /\A\w[\w\-\.]*\z/i
|
47
|
-
|
48
46
|
def validate_locale!(locale)
|
49
|
-
|
47
|
+
if Common::VALID_LOCALE_RE !~ locale
|
48
|
+
raise CommandError.new(I18n.t('i18n_tasks.cmd.errors.invalid_locale', invalid: locale))
|
49
|
+
end
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -13,7 +13,7 @@ module I18n::Tasks::Configuration
|
|
13
13
|
|
14
14
|
def file_config
|
15
15
|
file = CONFIG_FILES.detect { |f| File.exist?(f) }
|
16
|
-
config = file && YAML.load(Erubis::Eruby.new(File.read(file)).result)
|
16
|
+
config = file && YAML.load(Erubis::Eruby.new(File.read(file, encoding: 'UTF-8')).result)
|
17
17
|
if config.present?
|
18
18
|
config.with_indifferent_access.tap do |c|
|
19
19
|
if c[:relative_roots]
|
@@ -69,10 +69,12 @@ module I18n::Tasks
|
|
69
69
|
data[compared_to].select_keys { |key, _node|
|
70
70
|
locale_key_missing? locale, depluralize_key(key, compared_to)
|
71
71
|
}.set_root_key!(locale, type: :missing_diff).keys { |_key, node|
|
72
|
+
# change path and locale to base
|
73
|
+
data = {locale: locale, missing_diff_locale: node.data[:locale]}
|
72
74
|
if node.data.key?(:path)
|
73
|
-
|
74
|
-
node.data.update path: LocalePathname.replace_locale(node.data[:path], node.data[:locale], locale), locale: locale
|
75
|
+
data[:path] = LocalePathname.replace_locale(node.data[:path], node.data[:locale], locale)
|
75
76
|
end
|
77
|
+
node.data.update data
|
76
78
|
}
|
77
79
|
end
|
78
80
|
|
@@ -11,7 +11,6 @@ module I18n::Tasks::Reports
|
|
11
11
|
add_missing_sheet p.workbook
|
12
12
|
add_unused_sheet p.workbook
|
13
13
|
add_eq_base_sheet p.workbook
|
14
|
-
p.use_shared_strings = true
|
15
14
|
FileUtils.mkpath(File.dirname(path))
|
16
15
|
p.serialize(path)
|
17
16
|
$stderr.puts Term::ANSIColor.green "Saved to #{path}"
|
@@ -11,9 +11,11 @@ module I18n
|
|
11
11
|
forest = task.collapse_plural_nodes!(forest)
|
12
12
|
if forest.present?
|
13
13
|
print_title missing_title(forest)
|
14
|
-
print_table headings: [cyan(bold(I18n.t('i18n_tasks.common.locale'))),
|
14
|
+
print_table headings: [cyan(bold(I18n.t('i18n_tasks.common.locale'))),
|
15
|
+
cyan(bold I18n.t('i18n_tasks.common.key')),
|
16
|
+
I18n.t('i18n_tasks.missing.details_title')] do |t|
|
15
17
|
t.rows = sort_by_attr!(forest_to_attr(forest)).map do |a|
|
16
|
-
[{value: cyan(a[:locale]), alignment: :center}, cyan(a[:key]),
|
18
|
+
[{value: cyan(a[:locale]), alignment: :center}, cyan(a[:key]), missing_key_info(a)]
|
17
19
|
end
|
18
20
|
end
|
19
21
|
else
|
@@ -74,6 +76,14 @@ module I18n
|
|
74
76
|
|
75
77
|
private
|
76
78
|
|
79
|
+
def missing_key_info(leaf)
|
80
|
+
if leaf[:type] == :missing_used
|
81
|
+
first_occurrence leaf
|
82
|
+
else
|
83
|
+
"#{cyan leaf[:data][:missing_diff_locale]} #{leaf[:value].to_s.strip}"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
77
87
|
def print_occurrences(node, full_key = node.full_key)
|
78
88
|
occurrences = node.data[:source_occurrences]
|
79
89
|
puts "#{bold "#{full_key}"} #{green(occurrences.size.to_s) if occurrences.size > 1}"
|
@@ -84,8 +94,12 @@ module I18n
|
|
84
94
|
|
85
95
|
def print_locale_key_value_table(locale_key_values)
|
86
96
|
if locale_key_values.present?
|
87
|
-
print_table headings: [bold(cyan(I18n.t('i18n_tasks.common.locale'))),
|
88
|
-
|
97
|
+
print_table headings: [bold(cyan(I18n.t('i18n_tasks.common.locale'))),
|
98
|
+
bold(cyan(I18n.t('i18n_tasks.common.key'))),
|
99
|
+
I18n.t('i18n_tasks.common.value')] do |t|
|
100
|
+
t.rows = locale_key_values.map { |(locale, k, v)|
|
101
|
+
[{value: cyan(locale), alignment: :center}, cyan(k), v.to_s]
|
102
|
+
}
|
89
103
|
end
|
90
104
|
else
|
91
105
|
puts 'ø'
|
@@ -124,17 +138,7 @@ module I18n
|
|
124
138
|
end
|
125
139
|
|
126
140
|
def highlight_key(full_key, line, range = (0..-1))
|
127
|
-
|
128
|
-
result[range] = result[range].sub(full_key) { |m| underline m }
|
129
|
-
result
|
130
|
-
end
|
131
|
-
|
132
|
-
def key_info(leaf)
|
133
|
-
if leaf[:type] == :missing_used
|
134
|
-
first_occurrence leaf
|
135
|
-
else
|
136
|
-
leaf[:value].to_s.strip
|
137
|
-
end
|
141
|
+
line.dup.tap { |s| s[range] = s[range].sub(full_key) { |m| underline m } }
|
138
142
|
end
|
139
143
|
|
140
144
|
def first_occurrence(leaf)
|
@@ -27,10 +27,11 @@ module I18n::Tasks::Scanners
|
|
27
27
|
conf[:ignore_lines] = nil
|
28
28
|
end
|
29
29
|
conf[:ignore_lines] ||= {
|
30
|
-
'rb'
|
31
|
-
'haml'
|
32
|
-
'slim'
|
33
|
-
'
|
30
|
+
'rb' => %q(^\s*#(?!\si18n-tasks-use)),
|
31
|
+
'haml' => %q(^\s*-\s*#(?!\si18n-tasks-use)),
|
32
|
+
'slim' => %q(^\s*(?:-#|/)(?!\si18n-tasks-use)),
|
33
|
+
'coffee' => %q(^\s*#(?!\si18n-tasks-use)),
|
34
|
+
'erb' => %q(^\s*<%\s*#(?!\si18n-tasks-use)),
|
34
35
|
}
|
35
36
|
@ignore_lines_res = conf[:ignore_lines].inject({}) { |h, (ext, re)| h.update(ext => Regexp.new(re)) }
|
36
37
|
@key_filter = nil
|
@@ -59,7 +60,7 @@ module I18n::Tasks::Scanners
|
|
59
60
|
|
60
61
|
def read_file(path)
|
61
62
|
result = nil
|
62
|
-
File.open(path, 'rb') { |f| result = f.read }
|
63
|
+
File.open(path, 'rb', encoding: 'UTF-8') { |f| result = f.read }
|
63
64
|
result
|
64
65
|
end
|
65
66
|
|
@@ -126,7 +127,7 @@ module I18n::Tasks::Scanners
|
|
126
127
|
key
|
127
128
|
end
|
128
129
|
|
129
|
-
VALID_KEY_CHARS = /[
|
130
|
+
VALID_KEY_CHARS = /(?:[[:word:]]|[-.?!;À-ž])/
|
130
131
|
VALID_KEY_RE_STRICT = /^#{VALID_KEY_CHARS}+$/
|
131
132
|
VALID_KEY_RE = /^(#{VALID_KEY_CHARS}|[:\#{@}\[\]])+$/
|
132
133
|
|
@@ -60,7 +60,7 @@ module I18n::Tasks::Scanners
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def closest_method(location)
|
63
|
-
method = File.readlines(location[:src_path]).first(location[:line_num] - 1).reverse_each.find { |x| x=~ /\bdef\b/ }
|
63
|
+
method = File.readlines(location[:src_path], encoding: 'UTF-8').first(location[:line_num] - 1).reverse_each.find { |x| x=~ /\bdef\b/ }
|
64
64
|
method &&= method.strip.sub(/^def\s*/, '').sub(/[\(\s;].*$/, '')
|
65
65
|
method
|
66
66
|
end
|
@@ -42,7 +42,8 @@ module I18n
|
|
42
42
|
file_name = normalized_path.gsub(%r(#{path_root(normalized_path, roots)}/|(\.[^/]+)*$), '')
|
43
43
|
|
44
44
|
if options[:closest_method].present?
|
45
|
-
|
45
|
+
controller_name = file_name.sub(/_controller$/, '')
|
46
|
+
"#{controller_name}.#{options[:closest_method]}".tr('/', '.')
|
46
47
|
else
|
47
48
|
file_name.tr('/', '.').gsub(%r(\._), '.')
|
48
49
|
end
|
data/lib/i18n/tasks/used_keys.rb
CHANGED
@@ -11,11 +11,10 @@ module I18n::Tasks
|
|
11
11
|
# @return [Array<String>]
|
12
12
|
def used_tree(opts = {})
|
13
13
|
return scanner.with_key_filter(opts[:key_filter]) { used_tree(opts.except(:key_filter)) } if opts[:key_filter]
|
14
|
-
key_attrs = scanner.keys(opts.slice(:strict))
|
15
14
|
Data::Tree::Node.new(
|
16
15
|
key: 'used',
|
17
16
|
data: {key_filter: scanner.key_filter},
|
18
|
-
children: Data::Tree::Siblings.from_key_attr(
|
17
|
+
children: Data::Tree::Siblings.from_key_attr(scanner.keys(opts.slice(:strict)))
|
19
18
|
).to_siblings
|
20
19
|
end
|
21
20
|
|
data/lib/i18n/tasks/version.rb
CHANGED
@@ -41,17 +41,18 @@ describe 'Tree commands' do
|
|
41
41
|
{'a' => {'b' => {'a' => '1'}}}
|
42
42
|
end
|
43
43
|
|
44
|
+
def rename_key(from, to)
|
45
|
+
JSON.parse run_cmd(:tree_rename_key, key: from, name: to, format: 'json', arguments: [forest.to_json])
|
46
|
+
end
|
47
|
+
|
44
48
|
it 'renames root node' do
|
45
|
-
|
46
|
-
expect(renamed).to eq(forest.tap { |f| f['x'] = f.delete('a') })
|
49
|
+
expect(rename_key('a', 'x')).to eq(forest.tap { |f| f['x'] = f.delete('a') })
|
47
50
|
end
|
48
51
|
it 'renames node' do
|
49
|
-
|
50
|
-
expect(renamed).to eq(forest.tap { |f| f['a']['x'] = f['a'].delete('b') })
|
52
|
+
expect(rename_key('a.b', 'x')).to eq(forest.tap { |f| f['a']['x'] = f['a'].delete('b') })
|
51
53
|
end
|
52
54
|
it 'renames leaf' do
|
53
|
-
|
54
|
-
expect(renamed).to eq(forest.tap { |f| f['a']['b']['x'] = f['a']['b'].delete('a') })
|
55
|
+
expect(rename_key('a.b.a', 'x')).to eq(forest.tap { |f| f['a']['b']['x'] = f['a']['b'].delete('a') })
|
55
56
|
end
|
56
57
|
end
|
57
58
|
|
@@ -95,7 +95,7 @@ describe 'File system i18n' do
|
|
95
95
|
data[:en] = data[:en].merge!('en' => locale_data)
|
96
96
|
files = %w(pizza.en.json sushi.en.json)
|
97
97
|
expect(Dir['*.json'].sort).to eq(files.sort)
|
98
|
-
files.each { |f| expect(JSON.parse(File.read
|
98
|
+
files.each { |f| expect(JSON.parse(File.read(f, encoding: 'UTF-8'))['en']).to eq({File.basename(f, '.en.json') => keys}) }
|
99
99
|
}
|
100
100
|
end
|
101
101
|
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
/ t(:fp_comment)
|
4
4
|
/ i18n-tasks-use t(:fn_comment)
|
5
5
|
= t 'only_in_es'
|
6
|
+
#x = t 'not_a_comment'
|
6
7
|
p #{t('ca.a')} #{t 'ca.b'} #{t "ca.c"}
|
7
8
|
p #{t 'ca.d'} #{t 'ca.f', i: 'world'} #{t 'ca.e', i: 'world'}
|
8
9
|
p #{t 'missing_in_es.a'} #{t 'same_in_es.a'} #{t 'blank_in_es.a'}
|
@@ -25,3 +26,4 @@ p = t 'devise.a'
|
|
25
26
|
p = t :missing_symbol_key
|
26
27
|
p #{t :"missing_symbol.key_two"} #{t :'missing_symbol.key_three'}
|
27
28
|
= t 'present_in_es_but_not_en.a'
|
29
|
+
= t 'latin_extra.çüéö'
|
data/spec/i18n_tasks_spec.rb
CHANGED
@@ -3,13 +3,13 @@ require 'spec_helper'
|
|
3
3
|
require 'fileutils'
|
4
4
|
|
5
5
|
describe 'i18n-tasks' do
|
6
|
-
delegate :run_cmd, :i18n_task, :in_test_app_dir, to: :TestCodebase
|
6
|
+
delegate :run_cmd, :i18n_task, :in_test_app_dir, :i18n_cmd, to: :TestCodebase
|
7
7
|
|
8
8
|
describe 'health' do
|
9
9
|
it 'outputs stats' do
|
10
10
|
t = i18n_task
|
11
11
|
stats = in_test_app_dir { t.forest_stats(t.data_forest t.locales) }
|
12
|
-
out = capture_stderr {
|
12
|
+
out = in_test_app_dir { capture_stderr { capture_stdout { i18n_cmd.run(:health) } } }
|
13
13
|
stats.values.each do |v|
|
14
14
|
expect(out).to include(v.to_s)
|
15
15
|
end
|
@@ -37,26 +37,22 @@ describe 'i18n-tasks' do
|
|
37
37
|
)
|
38
38
|
}
|
39
39
|
it 'detects missing' do
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
expect(run_cmd :missing, arguments: %w(es)).to be_i18n_keys es_keys
|
46
|
-
end
|
40
|
+
es_keys = expected_missing_keys.grep(/^es\./)
|
41
|
+
expect(run_cmd :missing).to be_i18n_keys expected_missing_keys
|
42
|
+
# locale argument
|
43
|
+
expect(run_cmd :missing, locales: %w(es)).to be_i18n_keys es_keys
|
44
|
+
expect(run_cmd :missing, arguments: %w(es)).to be_i18n_keys es_keys
|
47
45
|
end
|
48
46
|
end
|
49
47
|
|
50
48
|
describe 'eq_base' do
|
51
49
|
it 'detects eq_base' do
|
52
|
-
|
53
|
-
expect(run_cmd :eq_base).to be_i18n_keys %w(es.same_in_es.a)
|
54
|
-
end
|
50
|
+
expect(run_cmd :eq_base).to be_i18n_keys %w(es.same_in_es.a)
|
55
51
|
end
|
56
52
|
end
|
57
53
|
|
58
54
|
let(:expected_unused_keys) do
|
59
|
-
|
55
|
+
%w(unused.a unused.numeric unused.plural).map do |k|
|
60
56
|
%w(en es).map { |l| "#{l}.#{k}" }
|
61
57
|
end.reduce(:+)
|
62
58
|
end
|
@@ -69,31 +65,25 @@ describe 'i18n-tasks' do
|
|
69
65
|
|
70
66
|
describe 'unused' do
|
71
67
|
it 'detects unused' do
|
72
|
-
|
73
|
-
expect(run_cmd :unused).to be_i18n_keys expected_unused_keys
|
74
|
-
end
|
68
|
+
expect(run_cmd :unused).to be_i18n_keys expected_unused_keys
|
75
69
|
end
|
76
70
|
|
77
71
|
it 'detects unused (--strict)' do
|
78
|
-
|
79
|
-
expect(run_cmd :unused, strict: true).to be_i18n_keys expected_unused_keys_strict
|
80
|
-
end
|
72
|
+
expect(run_cmd :unused, strict: true).to be_i18n_keys expected_unused_keys_strict
|
81
73
|
end
|
82
74
|
end
|
83
75
|
|
84
76
|
describe 'remove_unused' do
|
85
77
|
it 'removes unused' do
|
86
78
|
in_test_app_dir do
|
87
|
-
t
|
79
|
+
t = i18n_task
|
88
80
|
unused = expected_unused_keys.map { |k| ::I18n::Tasks::SplitKey.split_key(k, 2)[1] }
|
89
81
|
unused.each do |key|
|
90
82
|
expect(t.key_value?(key, :en)).to be true
|
91
83
|
expect(t.key_value?(key, :es)).to be true
|
92
84
|
end
|
93
85
|
ENV['CONFIRM'] = '1'
|
94
|
-
|
95
|
-
run_cmd :remove_unused
|
96
|
-
}
|
86
|
+
run_cmd :remove_unused
|
97
87
|
t.data.reload
|
98
88
|
unused.each do |key|
|
99
89
|
expect(t.key_value?(key, :en)).to be false
|
@@ -131,7 +121,7 @@ describe 'i18n-tasks' do
|
|
131
121
|
describe 'xlsx_report' do
|
132
122
|
it 'saves' do
|
133
123
|
in_test_app_dir {
|
134
|
-
|
124
|
+
run_cmd :xlsx_report
|
135
125
|
expect(File).to exist 'tmp/i18n-report.xlsx'
|
136
126
|
FileUtils.cp('tmp/i18n-report.xlsx', '..')
|
137
127
|
}
|
@@ -197,20 +187,18 @@ describe 'i18n-tasks' do
|
|
197
187
|
|
198
188
|
describe 'find' do
|
199
189
|
it 'prints usages' do
|
200
|
-
|
201
|
-
|
202
|
-
expect(result).to eq(<<-TXT)
|
190
|
+
result = Term::ANSIColor.uncolor(run_cmd :find, arguments: ['used.*'])
|
191
|
+
expect(result).to eq(<<-TXT)
|
203
192
|
used.a 2
|
204
193
|
app/views/usages.html.slim:1 p = t 'used.a'
|
205
194
|
app/views/usages.html.slim:2 b = t 'used.a'
|
206
|
-
|
207
|
-
end
|
195
|
+
TXT
|
208
196
|
end
|
209
197
|
end
|
210
198
|
|
211
199
|
|
212
200
|
# --- setup ---
|
213
|
-
BENCH_KEYS =
|
201
|
+
BENCH_KEYS = ENV['BENCH_KEYS'].to_i
|
214
202
|
before(:each) do
|
215
203
|
gen_data = ->(v) {
|
216
204
|
v_num = v.chars.map(&:ord).join('').to_i
|
@@ -242,21 +230,25 @@ used.a 2
|
|
242
230
|
'devise' => {'a' => v},
|
243
231
|
'scoped' => {'x' => v},
|
244
232
|
'very' => {'scoped' => {'x' => v}},
|
245
|
-
'used' => {'a' => v}
|
233
|
+
'used' => {'a' => v},
|
234
|
+
'latin_extra' => {'çüéö' => v},
|
235
|
+
'not_a_comment' => v
|
246
236
|
}.tap { |r|
|
247
|
-
|
248
|
-
|
237
|
+
if BENCH_KEYS > 0
|
238
|
+
gen = r['bench'] = {}
|
239
|
+
BENCH_KEYS.times { |i| gen["key#{i}"] = v }
|
240
|
+
end
|
249
241
|
}
|
250
242
|
}
|
251
243
|
|
252
|
-
en_data
|
253
|
-
es_data
|
254
|
-
|
255
|
-
es_data['same_in_es']['a']
|
256
|
-
es_data['blank_in_es']['a']
|
257
|
-
es_data['ignore_eq_base_all']['a']
|
258
|
-
es_data['ignore_eq_base_es']['a']
|
259
|
-
es_data['only_in_es']
|
244
|
+
en_data = gen_data.('EN_TEXT')
|
245
|
+
es_data = gen_data.('ES_TEXT').except('missing_in_es', 'missing_in_es_plural_1', 'missing_in_es_plural_2')
|
246
|
+
|
247
|
+
es_data['same_in_es']['a'] = 'EN_TEXT'
|
248
|
+
es_data['blank_in_es']['a'] = ''
|
249
|
+
es_data['ignore_eq_base_all']['a'] = 'EN_TEXT'
|
250
|
+
es_data['ignore_eq_base_es']['a'] = 'EN_TEXT'
|
251
|
+
es_data['only_in_es'] = 1
|
260
252
|
es_data['present_in_es_but_not_en'] = {'a' => 'ES_TEXT'}
|
261
253
|
|
262
254
|
fs = fixtures_contents.merge(
|
data/spec/relative_keys_spec.rb
CHANGED
@@ -29,6 +29,19 @@ describe 'Relative keys' do
|
|
29
29
|
expect(key).to eq('users.create.success')
|
30
30
|
end
|
31
31
|
|
32
|
+
context 'multiple words in controller name' do
|
33
|
+
it 'works' do
|
34
|
+
key = scanner.absolutize_key(
|
35
|
+
'.success',
|
36
|
+
'app/controllers/admin_users_controller.rb',
|
37
|
+
%w(app/controllers),
|
38
|
+
'create'
|
39
|
+
)
|
40
|
+
|
41
|
+
expect(key).to eq('admin_users.create.success')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
32
45
|
context 'nested in module' do
|
33
46
|
it 'works' do
|
34
47
|
key = scanner.absolutize_key(
|
@@ -22,11 +22,7 @@ module TestCodebase
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def run_cmd(name, *args, &block)
|
25
|
-
in_test_app_dir
|
26
|
-
silence_stream($stderr) {
|
27
|
-
capture_stdout { i18n_cmd.run(name, *args, &block) }
|
28
|
-
}
|
29
|
-
end
|
25
|
+
in_test_app_dir { capture_stdout { capture_stderr { i18n_cmd.run(name, *args, &block) } } }
|
30
26
|
end
|
31
27
|
|
32
28
|
def setup(files = {})
|
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.7.
|
4
|
+
version: 0.7.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- glebm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erubis
|
@@ -333,7 +333,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
333
333
|
version: '0'
|
334
334
|
requirements: []
|
335
335
|
rubyforge_project:
|
336
|
-
rubygems_version: 2.4.
|
336
|
+
rubygems_version: 2.4.6
|
337
337
|
signing_key:
|
338
338
|
specification_version: 4
|
339
339
|
summary: Manage localization and translation with the awesome power of static analysis
|