i18n-tasks 0.9.0.rc1 → 0.9.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -47
- data/bin/i18n-tasks +4 -0
- data/config/locales/en.yml +103 -103
- data/config/locales/ru.yml +1 -1
- data/i18n-tasks.gemspec +6 -5
- data/lib/i18n/tasks/cli.rb +10 -6
- data/lib/i18n/tasks/command/commander.rb +2 -2
- data/lib/i18n/tasks/command/commands/missing.rb +17 -5
- data/lib/i18n/tasks/command/option_parsers/locale.rb +8 -1
- data/lib/i18n/tasks/command_error.rb +1 -1
- data/lib/i18n/tasks/configuration.rb +12 -5
- data/lib/i18n/tasks/data.rb +5 -2
- data/lib/i18n/tasks/data/file_system_base.rb +7 -5
- data/lib/i18n/tasks/data/tree/siblings.rb +3 -3
- data/lib/i18n/tasks/data/tree/traversal.rb +9 -3
- data/lib/i18n/tasks/google_translation.rb +2 -2
- data/lib/i18n/tasks/key_pattern_matching.rb +9 -9
- data/lib/i18n/tasks/logging.rb +2 -2
- data/lib/i18n/tasks/missing_keys.rb +5 -5
- data/lib/i18n/tasks/scanners/file_scanner.rb +62 -0
- data/lib/i18n/tasks/scanners/files/caching_file_finder_provider.rb +10 -2
- data/lib/i18n/tasks/scanners/files/file_finder.rb +3 -3
- data/lib/i18n/tasks/scanners/occurrence_from_position.rb +25 -0
- data/lib/i18n/tasks/scanners/pattern_scanner.rb +18 -62
- data/lib/i18n/tasks/scanners/pattern_with_scope_scanner.rb +3 -10
- data/lib/i18n/tasks/scanners/relative_keys.rb +28 -28
- data/lib/i18n/tasks/scanners/results/key_occurrences.rb +53 -0
- data/lib/i18n/tasks/scanners/results/occurrence.rb +59 -0
- data/lib/i18n/tasks/scanners/ruby_ast_call_finder.rb +62 -0
- data/lib/i18n/tasks/scanners/ruby_ast_scanner.rb +193 -0
- data/lib/i18n/tasks/scanners/scanner.rb +3 -3
- data/lib/i18n/tasks/scanners/scanner_multiplexer.rb +2 -12
- data/lib/i18n/tasks/scanners/slim_temple_scanner.rb +24 -0
- data/lib/i18n/tasks/scanners/temple_scanner.rb +33 -0
- data/lib/i18n/tasks/used_keys.rb +67 -43
- data/lib/i18n/tasks/version.rb +1 -1
- data/templates/config/i18n-tasks.yml +2 -5
- metadata +46 -108
- data/.coveralls.yml +0 -1
- data/.gitattributes +0 -2
- data/.gitignore +0 -35
- data/.travis.yml +0 -18
- data/CHANGES.md +0 -351
- data/Gemfile +0 -13
- data/config/i18n-tasks.yml +0 -22
- data/lib/i18n/tasks/scanners/key_occurrences.rb +0 -35
- data/lib/i18n/tasks/scanners/occurence.rb +0 -50
- data/spec/commands/data_commands_spec.rb +0 -38
- data/spec/commands/tree_commands_spec.rb +0 -69
- data/spec/conservative_router_spec.rb +0 -50
- data/spec/file_system_data_spec.rb +0 -101
- data/spec/fixtures/app/assets/javascripts/application.js +0 -3
- data/spec/fixtures/app/controllers/events_controller.rb +0 -38
- data/spec/fixtures/app/views/index.html.slim +0 -29
- data/spec/fixtures/app/views/relative/index.html.slim +0 -3
- data/spec/fixtures/app/views/usages.html.slim +0 -2
- data/spec/fixtures/config/i18n-tasks.yml +0 -63
- data/spec/fixtures/lib/test_i18n_plugin.rb +0 -12
- data/spec/google_translate_spec.rb +0 -69
- data/spec/i18n_spec.rb +0 -17
- data/spec/i18n_tasks_spec.rb +0 -302
- data/spec/key_pattern_matching_spec.rb +0 -63
- data/spec/locale_pathname_spec.rb +0 -24
- data/spec/locale_tree/siblings_spec.rb +0 -115
- data/spec/pattern_scanner_spec.rb +0 -57
- data/spec/plural_keys_spec.rb +0 -44
- data/spec/readme_spec.rb +0 -9
- data/spec/relative_keys_spec.rb +0 -103
- data/spec/scanners/files/caching_file_finder_provider_spec.rb +0 -18
- data/spec/scanners/files/caching_file_finder_spec.rb +0 -39
- data/spec/scanners/files/caching_file_reader_spec.rb +0 -18
- data/spec/scanners/files/file_finder_spec.rb +0 -52
- data/spec/scanners/files/file_reader_spec.rb +0 -15
- data/spec/scanners/scanner_multiplexer_spec.rb +0 -26
- data/spec/spec_helper.rb +0 -24
- data/spec/split_key_spec.rb +0 -33
- data/spec/support/capture_std.rb +0 -22
- data/spec/support/fixtures.rb +0 -14
- data/spec/support/i18n_tasks_output_matcher.rb +0 -37
- data/spec/support/key_pattern_matcher.rb +0 -7
- data/spec/support/keys_and_occurrences.rb +0 -27
- data/spec/support/test_codebase.rb +0 -82
- data/spec/support/trees.rb +0 -20
- data/spec/used_keys_spec.rb +0 -74
@@ -1,12 +0,0 @@
|
|
1
|
-
# An i18n-tasks plugin to test that the plugin system works.
|
2
|
-
module TestI18nPlugin
|
3
|
-
include ::I18n::Tasks::Command::Collection
|
4
|
-
|
5
|
-
cmd :greet,
|
6
|
-
desc: 'print "Hello, %{name}"',
|
7
|
-
args: [['-n', '--name NAME', 'name']]
|
8
|
-
|
9
|
-
def greet(opts = {})
|
10
|
-
puts "Hello, #{opts[:name]}"
|
11
|
-
end
|
12
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'i18n/tasks/commands'
|
3
|
-
|
4
|
-
RSpec.describe 'Google Translation' do
|
5
|
-
include I18n::Tasks::GoogleTranslation
|
6
|
-
|
7
|
-
tests = [
|
8
|
-
nil_value_test = ['nil-value-key', nil, nil],
|
9
|
-
text_test = ['key', "Hello - %{user} O'neill!", "Hola - %{user} O'neill!"],
|
10
|
-
html_test = ['html-key.html', "Hello - <b>%{user} O'neill</b>", "Hola - <b>%{user} O'neill</b>"],
|
11
|
-
array_test = ['array-key', ['Hello.', nil, '', 'Goodbye.'], ['Hola.', nil, '', 'Adiós.']],
|
12
|
-
fixnum_test = ['numeric-key', 1, 1],
|
13
|
-
]
|
14
|
-
|
15
|
-
if ENV['GOOGLE_TRANSLATE_API_KEY']
|
16
|
-
describe 'real world test' do
|
17
|
-
delegate :i18n_task, :in_test_app_dir, :run_cmd, to: :TestCodebase
|
18
|
-
|
19
|
-
context '#google_translate_list' do
|
20
|
-
it "works with #{tests.map(&:first)}" do
|
21
|
-
# Just one test with all the cases to lower the Google bill
|
22
|
-
translations = google_translate_list(
|
23
|
-
tests.map { |t| t[0..1] }, from: :en, to: :es, key: ENV['GOOGLE_TRANSLATE_API_KEY'])
|
24
|
-
expect(translations).to eq(tests.map { |t| [t[0], t[2]] })
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
before do
|
29
|
-
TestCodebase.setup('config/locales/en.yml' => '', 'config/locales/es.yml' => '')
|
30
|
-
end
|
31
|
-
|
32
|
-
after do
|
33
|
-
TestCodebase.teardown
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'command' do
|
37
|
-
let(:task) { i18n_task }
|
38
|
-
|
39
|
-
it 'works' do
|
40
|
-
in_test_app_dir do
|
41
|
-
task.data[:en] = build_tree('en' => {
|
42
|
-
'common' => {
|
43
|
-
'a' => 'λ',
|
44
|
-
'hello' => text_test[1],
|
45
|
-
'hello_html' => html_test[1],
|
46
|
-
'array_key' => array_test[1],
|
47
|
-
'nil-value-key' => nil_value_test[1],
|
48
|
-
'fixnum-key' => fixnum_test[1]
|
49
|
-
}
|
50
|
-
})
|
51
|
-
task.data[:es] = build_tree('es' => {
|
52
|
-
'common' => {
|
53
|
-
'a' => 'λ',
|
54
|
-
}
|
55
|
-
})
|
56
|
-
|
57
|
-
run_cmd 'translate-missing'
|
58
|
-
expect(task.t('common.hello', 'es')).to eq(text_test[2])
|
59
|
-
expect(task.t('common.hello_html', 'es')).to eq(html_test[2])
|
60
|
-
expect(task.t('common.array_key', 'es')).to eq(array_test[2])
|
61
|
-
expect(task.t('common.nil-value-key', 'es')).to eq(nil_value_test[2])
|
62
|
-
expect(task.t('common.fixnum-key', 'es')).to eq(fixnum_test[2])
|
63
|
-
expect(task.t('common.a', 'es')).to eq('λ')
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
data/spec/i18n_spec.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'i18n/tasks'
|
2
|
-
|
3
|
-
RSpec.describe 'I18n' do
|
4
|
-
let(:i18n) { I18n::Tasks::BaseTask.new }
|
5
|
-
let(:missing_keys) { i18n.missing_keys }
|
6
|
-
let(:unused_keys) { i18n.unused_keys }
|
7
|
-
|
8
|
-
it 'does not have missing keys' do
|
9
|
-
expect(missing_keys).to be_empty,
|
10
|
-
"Missing #{missing_keys.leaves.count} i18n keys, run `i18n-tasks missing' to show them"
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'does not have unused keys' do
|
14
|
-
expect(unused_keys).to be_empty,
|
15
|
-
"#{unused_keys.leaves.count} unused i18n keys, run `i18n-tasks unused' to show them"
|
16
|
-
end
|
17
|
-
end
|
data/spec/i18n_tasks_spec.rb
DELETED
@@ -1,302 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'fileutils'
|
3
|
-
require 'open3'
|
4
|
-
|
5
|
-
# Integration tests
|
6
|
-
RSpec.describe 'i18n-tasks' do
|
7
|
-
delegate :run_cmd, :run_cmd_capture_stdout_and_result, :run_cmd_capture_stderr, :i18n_task, :in_test_app_dir,
|
8
|
-
to: :TestCodebase
|
9
|
-
|
10
|
-
describe 'bin/i18n-tasks' do
|
11
|
-
it 'shows help when invoked with no arguments, shows version on --version' do
|
12
|
-
next if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
|
13
|
-
# These bin/i18n-tasks tests are executed in parallel for performance
|
14
|
-
in_test_app_dir do
|
15
|
-
[
|
16
|
-
proc {
|
17
|
-
out, err, status = Open3.capture3('../../bin/i18n-tasks')
|
18
|
-
expect(status).to be_success
|
19
|
-
expect(out).to be_empty
|
20
|
-
expect(err).to start_with('Usage: i18n-tasks [command] [options]')
|
21
|
-
expect(err).to include('Available commands', 'add-missing')
|
22
|
-
# a task from a plugin
|
23
|
-
expect(err).to include('greet')
|
24
|
-
},
|
25
|
-
proc {
|
26
|
-
expect(%x[bundle exec ../../bin/i18n-tasks --version].chomp).to eq(I18n::Tasks::VERSION)
|
27
|
-
}
|
28
|
-
].map { |test| Thread.start(&test) }.each(&:join)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# Tests execute i18n-tasks using I18n::Tasks::CLI directly, via #run_cmd(task, *arguments).
|
34
|
-
# This avoid launching a process for each command.
|
35
|
-
|
36
|
-
describe 'health' do
|
37
|
-
it 'outputs stats' do
|
38
|
-
t = i18n_task
|
39
|
-
out = run_cmd_capture_stderr('health')
|
40
|
-
in_test_app_dir { t.forest_stats(t.data_forest t.locales) }.values.each do |v|
|
41
|
-
expect(out).to include(v.to_s)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe 'missing' do
|
47
|
-
let (:expected_missing_keys_in_source) {
|
48
|
-
%w(
|
49
|
-
used_but_missing.key
|
50
|
-
relative.index.missing
|
51
|
-
hash.pattern_missing.a
|
52
|
-
hash.pattern_missing.b
|
53
|
-
missing_symbol_key
|
54
|
-
missing_symbol.key_two
|
55
|
-
missing_symbol.key_three
|
56
|
-
missing-key-with-a-dash.key
|
57
|
-
missing-key-question?.key
|
58
|
-
fn_comment
|
59
|
-
events.show.success
|
60
|
-
)
|
61
|
-
}
|
62
|
-
let (:expected_missing_keys_diff) {
|
63
|
-
%w(
|
64
|
-
es.missing_in_es.a
|
65
|
-
en.present_in_es_but_not_en.a
|
66
|
-
es.missing_in_es_plural_1.a
|
67
|
-
es.missing_in_es_plural_2.a
|
68
|
-
en.only_in_es
|
69
|
-
)
|
70
|
-
}
|
71
|
-
it 'detects missing' do
|
72
|
-
es_keys = expected_missing_keys_diff.grep(/^es\./) + expected_missing_keys_in_source.map { |k| "es.#{k}" }
|
73
|
-
out, result = run_cmd_capture_stdout_and_result 'missing'
|
74
|
-
expect(result).to eq :exit_1
|
75
|
-
expect(out).to be_i18n_keys(expected_missing_keys_diff +
|
76
|
-
expected_missing_keys_in_source.map { |k| "all.#{k}" })
|
77
|
-
expect(run_cmd 'missing', '-les').to be_i18n_keys es_keys
|
78
|
-
expect(run_cmd 'missing', 'es').to be_i18n_keys es_keys
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
describe 'eq_base' do
|
83
|
-
it 'detects eq-base' do
|
84
|
-
expect(run_cmd 'eq-base').to be_i18n_keys %w(es.same_in_es.a)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
let(:expected_unused_keys) do
|
89
|
-
%w(unused.a unused.numeric unused.plural).map do |k|
|
90
|
-
%w(en es).map { |l| "#{l}.#{k}" }
|
91
|
-
end.reduce(:+)
|
92
|
-
end
|
93
|
-
|
94
|
-
let(:expected_unused_keys_strict) do
|
95
|
-
expected_unused_keys + %w(hash.pattern.a hash.pattern2.a).map do |k|
|
96
|
-
%w(en es).map { |l| "#{l}.#{k}" }
|
97
|
-
end.reduce(:+)
|
98
|
-
end
|
99
|
-
|
100
|
-
describe 'unused' do
|
101
|
-
it 'detects unused (--no-strict)' do
|
102
|
-
out, result = run_cmd_capture_stdout_and_result('unused', '--no-strict')
|
103
|
-
expect(result).to eq :exit_1
|
104
|
-
expect(out).to be_i18n_keys expected_unused_keys
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'detects unused (--strict)' do
|
108
|
-
expect(run_cmd 'unused', '--strict').to be_i18n_keys expected_unused_keys_strict
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
describe 'remove_unused' do
|
113
|
-
it 'removes unused' do
|
114
|
-
in_test_app_dir do
|
115
|
-
t = i18n_task
|
116
|
-
unused = expected_unused_keys.map { |k| ::I18n::Tasks::SplitKey.split_key(k, 2)[1] }
|
117
|
-
unused.each do |key|
|
118
|
-
expect(t.key_value?(key, :en)).to be true
|
119
|
-
expect(t.key_value?(key, :es)).to be true
|
120
|
-
end
|
121
|
-
ENV['CONFIRM'] = '1'
|
122
|
-
run_cmd 'remove-unused'
|
123
|
-
t.data.reload
|
124
|
-
unused.each do |key|
|
125
|
-
expect(t.key_value?(key, :en)).to be false
|
126
|
-
expect(t.key_value?(key, :es)).to be false
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
describe 'normalize' do
|
133
|
-
it 'sorts the keys' do
|
134
|
-
in_test_app_dir do
|
135
|
-
run_cmd 'normalize'
|
136
|
-
en_yml_data = i18n_task.data.reload['en'].select_keys { |_k, node|
|
137
|
-
node.data[:path] == 'config/locales/en.yml'
|
138
|
-
}
|
139
|
-
expect(en_yml_data).to be_present
|
140
|
-
en_yml_data.nodes { |nodes|
|
141
|
-
next unless nodes.children
|
142
|
-
keys = nodes.children.map(&:key)
|
143
|
-
expect(keys).to eq keys.sort
|
144
|
-
}
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
it 'moves keys to the corresponding files as per data.write' do
|
149
|
-
in_test_app_dir {
|
150
|
-
expect(File).to_not exist 'config/locales/devise.en.yml'
|
151
|
-
run_cmd 'normalize', '--pattern_router'
|
152
|
-
expect(YAML.load_file('config/locales/devise.en.yml')['en']['devise']['a']).to eq 'EN_TEXT'
|
153
|
-
}
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
describe 'xlsx_report' do
|
158
|
-
it 'saves' do
|
159
|
-
in_test_app_dir {
|
160
|
-
run_cmd 'xlsx-report'
|
161
|
-
expect(File).to exist 'tmp/i18n-report.xlsx'
|
162
|
-
FileUtils.cp('tmp/i18n-report.xlsx', '..')
|
163
|
-
}
|
164
|
-
end
|
165
|
-
|
166
|
-
end
|
167
|
-
|
168
|
-
describe 'add_missing' do
|
169
|
-
it 'default placeholder: key.humanize for base_locale' do
|
170
|
-
in_test_app_dir {
|
171
|
-
expect(YAML.load_file('config/locales/en.yml')['en']['used_but_missing']).to be_nil
|
172
|
-
}
|
173
|
-
run_cmd 'add-missing', 'base'
|
174
|
-
in_test_app_dir {
|
175
|
-
expect(YAML.load_file('config/locales/en.yml')['en']['used_but_missing']['key']).to eq 'Key'
|
176
|
-
expect(YAML.load_file('config/locales/en.yml')['en']['present_in_es_but_not_en']['a']).to eq 'ES_TEXT'
|
177
|
-
}
|
178
|
-
end
|
179
|
-
|
180
|
-
it 'default value: base_value for non-base locale' do
|
181
|
-
in_test_app_dir {
|
182
|
-
expect(YAML.load_file('config/locales/es.yml')['es']['missing_in_es']).to be_nil
|
183
|
-
}
|
184
|
-
run_cmd 'add-missing', 'es'
|
185
|
-
in_test_app_dir {
|
186
|
-
expect(YAML.load_file('config/locales/es.yml')['es']['missing_in_es']['a']).to eq 'EN_TEXT'
|
187
|
-
expect(YAML.load_file('config/locales/es.yml')['es']['missing_in_es_plural_1']['a']['one']).to eq 'EN_TEXT'
|
188
|
-
}
|
189
|
-
end
|
190
|
-
|
191
|
-
it '--value' do
|
192
|
-
in_test_app_dir {
|
193
|
-
expect(YAML.load_file('config/locales/es.yml')['es']['missing_in_es']).to be_nil
|
194
|
-
}
|
195
|
-
run_cmd 'normalize', '--pattern_router'
|
196
|
-
run_cmd 'add-missing', '-v', 'TRME'
|
197
|
-
in_test_app_dir {
|
198
|
-
expect(YAML.load_file('config/locales/es.yml')['es']['missing_in_es']['a']).to eq 'TRME'
|
199
|
-
expect(YAML.load_file('config/locales/devise.es.yml')['es']['devise']['a']).to eq 'ES_TEXT'
|
200
|
-
expect(YAML.load_file('config/locales/en.yml')['en']['present_in_es_but_not_en']['a']).to eq 'TRME'
|
201
|
-
}
|
202
|
-
end
|
203
|
-
|
204
|
-
it '--value with %{value}' do
|
205
|
-
in_test_app_dir {
|
206
|
-
expect(YAML.load_file('config/locales/es.yml')['es']['missing_in_es']).to be_nil
|
207
|
-
}
|
208
|
-
run_cmd 'add-missing', '-v', 'TRME %{value}'
|
209
|
-
in_test_app_dir {
|
210
|
-
expect(YAML.load_file('config/locales/es.yml')['es']['missing_in_es']['a']).to eq 'TRME EN_TEXT'
|
211
|
-
expect(YAML.load_file('config/locales/en.yml')['en']['present_in_es_but_not_en']['a']).to eq 'TRME ES_TEXT'
|
212
|
-
}
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
describe 'config' do
|
217
|
-
it 'prints config' do
|
218
|
-
expect(YAML.load(Term::ANSIColor.uncolor(run_cmd 'config'))).to(
|
219
|
-
eq(in_test_app_dir { i18n_task.config_for_inspect })
|
220
|
-
)
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
describe 'find' do
|
225
|
-
it 'prints usages' do
|
226
|
-
result = Term::ANSIColor.uncolor(run_cmd 'find', 'used.*')
|
227
|
-
expect(result).to eq(<<-TXT)
|
228
|
-
used.a 2
|
229
|
-
app/views/usages.html.slim:1 p = t 'used.a'
|
230
|
-
app/views/usages.html.slim:2 b = t 'used.a'
|
231
|
-
TXT
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
# --- setup ---
|
236
|
-
BENCH_KEYS = ENV['BENCH_KEYS'].to_i
|
237
|
-
before(:each) do
|
238
|
-
gen_data = ->(v) {
|
239
|
-
v_num = v.chars.map(&:ord).join('').to_i
|
240
|
-
{
|
241
|
-
'ca' => {'a' => v, 'b' => v, 'c' => v, 'd' => v, 'e' => "#{v}%{i}", 'f' => "#{v}%{i}"},
|
242
|
-
'cb' => {'a' => v, 'b' => "#{v}%{i}"},
|
243
|
-
'hash' => {
|
244
|
-
'pattern' => {'a' => v},
|
245
|
-
'pattern2' => {'a' => v},
|
246
|
-
},
|
247
|
-
'unused' => {'a' => v, 'numeric' => v_num, 'plural' => {'one' => v, 'other' => v}},
|
248
|
-
'ignore_unused' => {'a' => v},
|
249
|
-
'missing_in_es' => {'a' => v},
|
250
|
-
'missing_in_es_plural_1' => {'a' => {'one' => v, 'other' => v}},
|
251
|
-
'missing_in_es_plural_2' => {'a' => {'one' => v, 'other' => v}},
|
252
|
-
'same_in_es' => {'a' => v},
|
253
|
-
'ignore_eq_base_all' => {'a' => v},
|
254
|
-
'ignore_eq_base_es' => {'a' => v},
|
255
|
-
'blank_in_es' => {'a' => v},
|
256
|
-
'relative' => {
|
257
|
-
'index' => {
|
258
|
-
'title' => v,
|
259
|
-
'description' => v,
|
260
|
-
'summary' => v,
|
261
|
-
}
|
262
|
-
},
|
263
|
-
'numeric' => {'a' => v_num},
|
264
|
-
'plural' => {'a' => {'one' => v, 'other' => "%{count} #{v}s"}},
|
265
|
-
'devise' => {'a' => v},
|
266
|
-
'scoped' => {'x' => v},
|
267
|
-
'very' => {'scoped' => {'x' => v}},
|
268
|
-
'used' => {'a' => v},
|
269
|
-
'latin_extra' => {'çüéö' => v},
|
270
|
-
'not_a_comment' => v
|
271
|
-
}.tap { |r|
|
272
|
-
if BENCH_KEYS > 0
|
273
|
-
gen = r['bench'] = {}
|
274
|
-
BENCH_KEYS.times { |i| gen["key#{i}"] = v }
|
275
|
-
end
|
276
|
-
}
|
277
|
-
}
|
278
|
-
|
279
|
-
en_data = gen_data.('EN_TEXT')
|
280
|
-
es_data = gen_data.('ES_TEXT').except('missing_in_es', 'missing_in_es_plural_1', 'missing_in_es_plural_2')
|
281
|
-
|
282
|
-
es_data['same_in_es']['a'] = 'EN_TEXT'
|
283
|
-
es_data['blank_in_es']['a'] = ''
|
284
|
-
es_data['ignore_eq_base_all']['a'] = 'EN_TEXT'
|
285
|
-
es_data['ignore_eq_base_es']['a'] = 'EN_TEXT'
|
286
|
-
es_data['only_in_es'] = 1
|
287
|
-
es_data['present_in_es_but_not_en'] = {'a' => 'ES_TEXT'}
|
288
|
-
|
289
|
-
fs = fixtures_contents.merge(
|
290
|
-
'config/locales/en.yml' => {'en' => en_data}.to_yaml,
|
291
|
-
'config/locales/es.yml' => {'es' => es_data}.to_yaml,
|
292
|
-
# test that our algorithms can scale to the order of {BENCH_KEYS} keys.
|
293
|
-
'vendor/heavy.file' => BENCH_KEYS.times.map { |i| "t('bench.key#{i}') " }.join
|
294
|
-
)
|
295
|
-
|
296
|
-
TestCodebase.setup fs
|
297
|
-
end
|
298
|
-
|
299
|
-
after do
|
300
|
-
TestCodebase.teardown
|
301
|
-
end
|
302
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe 'Key pattern' do
|
4
|
-
include I18n::Tasks::KeyPatternMatching
|
5
|
-
describe 'matching' do
|
6
|
-
describe '*' do
|
7
|
-
it 'as suffix' do
|
8
|
-
expect('devise.*').to match_key 'devise.some.key'
|
9
|
-
end
|
10
|
-
it 'as prefix' do
|
11
|
-
expect('*.some.key').to match_key 'devise.some.key'
|
12
|
-
end
|
13
|
-
it 'as infix' do
|
14
|
-
expect('*.some.*').to match_key 'devise.some.key'
|
15
|
-
end
|
16
|
-
it 'matches multiple namespaces' do
|
17
|
-
expect('a.*.e*').to match_key 'a.b.c.d.eeee'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe ':' do
|
22
|
-
it 'as suffix' do
|
23
|
-
expect('a.b.:').to match_key 'a.b.c'
|
24
|
-
expect('a.b.:').not_to match_key 'a.b.c.d'
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'as prefix' do
|
28
|
-
expect(':.b.c').to match_key 'a.b.c'
|
29
|
-
expect(':.b.c').not_to match_key 'x.a.b.c'
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'as infix' do
|
33
|
-
expect('a.:.c').to match_key 'a.b.c'
|
34
|
-
expect('a.:.c').not_to match_key 'a.b.x.c'
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe '{sets}' do
|
39
|
-
it 'matches' do
|
40
|
-
p = 'a.{x,y}.b'
|
41
|
-
expect(p).to match_key 'a.x.b'
|
42
|
-
expect(p).to match_key 'a.y.b'
|
43
|
-
expect(p).not_to match_key 'a.z.b'
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'supports :' do
|
47
|
-
expect('a.{:}.c').to match_key 'a.b.c'
|
48
|
-
expect('a.{:}.c').not_to match_key 'a.b.x.c'
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'supports *' do
|
52
|
-
expect('a.{*}.c').to match_key 'a.b.c'
|
53
|
-
expect('a.{*}.c').to match_key 'a.b.x.y.c'
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'captures' do
|
57
|
-
p = 'a.{x,y}.{:}'
|
58
|
-
compile_key_pattern(p) =~ 'a.x.c'
|
59
|
-
expect([$1, $2]).to eq(['x', 'c'])
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|