i18n-tasks 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,14 +5,14 @@ module I18n::Tasks::Scanners
5
5
  #
6
6
  class PatternScanner < BaseScanner
7
7
  # Extract i18n keys from file based on the pattern which must capture the key literal.
8
- # @return [String] keys found in file
8
+ # @return [Array<Key>] keys found in file
9
9
  def scan_file(path, text = read_file(path))
10
10
  keys = []
11
11
  text.scan(pattern) do |match|
12
12
  src_pos = Regexp.last_match.offset(0).first
13
13
  key = match_to_key(match, path)
14
14
  next unless valid_key?(key)
15
- keys << ::I18n::Tasks::Key.new(key, usage_context(text, src_pos))
15
+ keys << ::I18n::Tasks::Key.new(key, src_location(text, src_pos))
16
16
  end
17
17
  keys
18
18
  end
@@ -7,21 +7,24 @@ module I18n
7
7
  # @return [Array<[String, String]>] all the unused translations as an array of [key, value] pairs
8
8
  def unused_keys(locale = base_locale)
9
9
  @unused_keys ||= {}
10
- @unused_keys[locale] ||= ::I18n::Tasks::KeyGroup.new(
11
- traverse_map_if(data[locale]) { |key, value|
12
- next if used_in_expr?(key) || ignore_key?(key, :unused)
13
- key = depluralize_key(locale, key)
14
- [key, value] unless used_key?(key)
15
- }.uniq, locale: locale, type: :unused)
10
+ @unused_keys[locale] ||= begin
11
+ keys = data[locale].traverse_map_if { |key, value|
12
+ next if used_in_expr?(key) || ignore_key?(key, :unused)
13
+ key = depluralize_key(locale, key)
14
+ [key, value] unless used_key?(key)
15
+ }.uniq
16
+ KeyGroup.new keys, locale: locale, type: :unused
17
+ end
16
18
  end
17
19
 
18
20
  def remove_unused!(locales = nil)
19
21
  locales ||= self.locales
20
- unused = unused_keys
22
+ unused = unused_keys
21
23
  locales.each do |locale|
22
- data[locale] = list_to_tree traverse_map_if(data[locale]) { |key, value|
24
+ used_key_values = data[locale].traverse_map_if { |key, value|
23
25
  [key, value] unless unused.include?(depluralize_key(locale, key))
24
26
  }
27
+ data[locale] = used_key_values
25
28
  end
26
29
  end
27
30
  end
@@ -2,18 +2,27 @@ require 'find'
2
2
  require 'i18n/tasks/scanners/pattern_with_scope_scanner'
3
3
 
4
4
  module I18n::Tasks::UsedKeys
5
+
5
6
  # find all keys in the source (relative keys are absolutized)
7
+ # @option opts [false|true] :src_locations
8
+ # @option opts [String] :key_filter
6
9
  # @return [Array<String>]
7
- def used_keys(with_usages = false)
8
- if with_usages
9
- used_keys_group scanner.keys_with_usages
10
+ def used_keys(opts = {})
11
+ if opts[:key_filter]
12
+ scanner.with_key_filter(opts[:key_filter]) do
13
+ return used_keys(opts.except(:key_filter))
14
+ end
10
15
  else
11
- @used_keys ||= used_keys_group scanner.keys
16
+ if opts[:src_locations]
17
+ used_keys_group scanner.keys_with_src_locations
18
+ else
19
+ @used_keys ||= used_keys_group scanner.keys
20
+ end
12
21
  end
13
22
  end
14
23
 
15
- def used_keys_group(keys, opts = {})
16
- ::I18n::Tasks::KeyGroup.new(keys, {type: :used, key_filter: scanner.key_filter}.merge(opts))
24
+ def used_keys_group(keys)
25
+ ::I18n::Tasks::KeyGroup.new keys, type: :used, key_filter: scanner.key_filter
17
26
  end
18
27
 
19
28
  def scanner
@@ -1,5 +1,5 @@
1
1
  module I18n
2
2
  module Tasks
3
- VERSION = '0.3.6'
3
+ VERSION = '0.3.7'
4
4
  end
5
5
  end
@@ -45,7 +45,7 @@ describe 'File system i18n' do
45
45
  'c.yml' => {en: {c: 1}}.stringify_keys.to_yaml
46
46
  )
47
47
  TestCodebase.in_test_app_dir {
48
- expect(data[:en].symbolize_keys).to eq(a: 1, b: 1, c: 1)
48
+ expect(data[:en].data.symbolize_keys).to eq(a: 1, b: 1, c: 1)
49
49
  }
50
50
  end
51
51
 
@@ -80,7 +80,7 @@ describe 'File system i18n' do
80
80
  'c.json' => {en: {c: 1}}.stringify_keys.to_json
81
81
  )
82
82
  TestCodebase.in_test_app_dir {
83
- expect(data[:en].symbolize_keys).to eq(a: 1, b: 1, c: 1)
83
+ expect(data[:en].data.symbolize_keys).to eq(a: 1, b: 1, c: 1)
84
84
  }
85
85
  end
86
86
 
@@ -35,7 +35,7 @@ describe 'Google Translation' do
35
35
  in_test_app_dir do
36
36
  task.data[:en] = {'common' => {'hello' => TEST_STRING}}
37
37
  cmd.translate_missing
38
- expect(task.data[:es]['common']['hello']).to eq(TEST_RESULT)
38
+ expect(task.data[:es].t('common.hello')).to eq(TEST_RESULT)
39
39
  end
40
40
  end
41
41
  end
@@ -9,13 +9,13 @@ describe 'Pattern Scanner' do
9
9
  "t :a_b", "t :'a.b'", 't :"a.b"', "t(:ab)", "t(:'a.b')", 't(:"a.b")',
10
10
  'I18n.t("a.b")', 'I18n.translate("a.b")'].each do |s|
11
11
  it "matches #{s}" do
12
- pattern.should match s
12
+ expect(pattern).to match s
13
13
  end
14
14
  end
15
15
 
16
16
  ["t \"a.b'", "t a.b"].each do |s|
17
17
  it "does not match #{s}" do
18
- pattern.should_not match s
18
+ expect(pattern).to_not match s
19
19
  end
20
20
  end
21
21
  end
@@ -1,18 +1,18 @@
1
1
  require 'spec_helper'
2
2
  describe 'Relative keys' do
3
- let(:task) { I18n::Tasks::BaseTask.new }
3
+ let(:scanner) { I18n::Tasks::Scanners::BaseScanner.new }
4
4
 
5
5
  describe 'absolutize_key' do
6
6
 
7
7
  context 'default settings' do
8
8
  it 'works' do
9
- task.absolutize_key('.title', 'app/views/movies/show.html.slim').should == 'movies.show.title'
9
+ scanner.absolutize_key('.title', 'app/views/movies/show.html.slim', %w(app/views)).should == 'movies.show.title'
10
10
  end
11
11
  end
12
12
 
13
13
  context 'custom roots' do
14
14
  it 'works' do
15
- task.absolutize_key('.title', 'app/views-mobile/movies/show.html.slim', %w(app/views-mobile)).should == 'movies.show.title'
15
+ scanner.absolutize_key('.title', 'app/views-mobile/movies/show.html.slim', %w(app/views app/views-mobile)).should == 'movies.show.title'
16
16
  end
17
17
  end
18
18
 
@@ -14,8 +14,8 @@ h1 = t 'b'
14
14
  TestCodebase.teardown
15
15
  end
16
16
 
17
- it '#used_keys(true) finds usages' do
18
- used_keys = task.used_keys(true)
17
+ it '#used_keys(src_locations: true)' do
18
+ used_keys = task.used_keys(src_locations: true)
19
19
  expect(used_keys.size).to eq 2
20
20
  expect(used_keys[0].own_attr).to(
21
21
  eq(key: 'a',
@@ -28,10 +28,8 @@ h1 = t 'b'
28
28
  )
29
29
  end
30
30
 
31
- it '#used_keys(true) finds usages with filter' do
32
- used_keys = task.scanner.with_key_filter('b*') {
33
- task.used_keys(true)
34
- }
31
+ it '#used_keys(src_locations: true, key_filter: "b*")' do
32
+ used_keys = task.used_keys(key_filter: 'b*', src_locations: true)
35
33
  expect(used_keys.size).to eq 1
36
34
  expect(used_keys[0].own_attr).to(
37
35
  eq(key: 'b',
metadata CHANGED
@@ -1,194 +1,189 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - glebm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-28 00:00:00.000000000 Z
11
+ date: 2014-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubis
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: easy_translate
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: 0.4.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.4.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: term-ansicolor
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: terminal-table
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: highline
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: slop
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: 3.4.7
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: 3.4.7
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: axlsx
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ~>
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
117
  version: '2.0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ~>
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '2.0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: bundler
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ~>
129
+ - - "~>"
130
130
  - !ruby/object:Gem::Version
131
131
  version: '1.3'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ~>
136
+ - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '1.3'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rake
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - '>='
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - '>='
150
+ - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: rspec
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - '>='
157
+ - - ">="
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - '>='
164
+ - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: yard
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - '>='
171
+ - - ">="
172
172
  - !ruby/object:Gem::Version
173
173
  version: '0'
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - '>='
178
+ - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  description: |2
182
182
 
183
183
  i18n-tasks finds and manages missing and unused translations in your application.
184
184
 
185
- The basic approach to i18n key management in frameworks such as Rails is far from perfect.
186
- If you use a key that does not exist, this will only blow up at runtime. Keys left over from removed code accumulate
187
- in the resource files, introducing unnecessary overhead on the translators. Translation files can quickly turn to disarray.
188
-
189
- i18n-tasks improves this by using static analysis. It scans calls such as `I18n.t('some.key')` and uses this information to
190
- provide reports on key usage, missing and unused keys, and can prefill missing keys, including from Google Translate,
191
- and can also remove unused keys.
185
+ It scans calls such as `I18n.t('some.key')` and provides reports on key usage, missing, and unused keys.
186
+ It can also can pre-fill missing keys, including from Google Translate, and it can remove unused keys as well.
192
187
  email:
193
188
  - glex.spb@gmail.com
194
189
  executables:
@@ -196,9 +191,9 @@ executables:
196
191
  extensions: []
197
192
  extra_rdoc_files: []
198
193
  files:
199
- - .coveralls.yml
200
- - .gitignore
201
- - .travis.yml
194
+ - ".coveralls.yml"
195
+ - ".gitignore"
196
+ - ".travis.yml"
202
197
  - CHANGES.md
203
198
  - Gemfile
204
199
  - LICENSE.txt
@@ -211,11 +206,14 @@ files:
211
206
  - lib/i18n/tasks/commands.rb
212
207
  - lib/i18n/tasks/commands_base.rb
213
208
  - lib/i18n/tasks/configuration.rb
209
+ - lib/i18n/tasks/data.rb
214
210
  - lib/i18n/tasks/data/adapter/json_adapter.rb
215
211
  - lib/i18n/tasks/data/adapter/yaml_adapter.rb
212
+ - lib/i18n/tasks/data/file_formats.rb
216
213
  - lib/i18n/tasks/data/file_system.rb
217
- - lib/i18n/tasks/data/storage/file_storage.rb
218
- - lib/i18n/tasks/data_traversal.rb
214
+ - lib/i18n/tasks/data/file_system_base.rb
215
+ - lib/i18n/tasks/data/locale_tree.rb
216
+ - lib/i18n/tasks/data/router.rb
219
217
  - lib/i18n/tasks/fill_tasks.rb
220
218
  - lib/i18n/tasks/google_translation.rb
221
219
  - lib/i18n/tasks/ignore_keys.rb
@@ -235,7 +233,6 @@ files:
235
233
  - lib/i18n/tasks/scanners/base_scanner.rb
236
234
  - lib/i18n/tasks/scanners/pattern_scanner.rb
237
235
  - lib/i18n/tasks/scanners/pattern_with_scope_scanner.rb
238
- - lib/i18n/tasks/translation_data.rb
239
236
  - lib/i18n/tasks/unused_keys.rb
240
237
  - lib/i18n/tasks/used_keys.rb
241
238
  - lib/i18n/tasks/version.rb
@@ -272,17 +269,17 @@ require_paths:
272
269
  - lib
273
270
  required_ruby_version: !ruby/object:Gem::Requirement
274
271
  requirements:
275
- - - '>='
272
+ - - ">="
276
273
  - !ruby/object:Gem::Version
277
274
  version: '0'
278
275
  required_rubygems_version: !ruby/object:Gem::Requirement
279
276
  requirements:
280
- - - '>='
277
+ - - ">="
281
278
  - !ruby/object:Gem::Version
282
279
  version: '0'
283
280
  requirements: []
284
281
  rubyforge_project:
285
- rubygems_version: 2.0.14
282
+ rubygems_version: 2.2.0
286
283
  signing_key:
287
284
  specification_version: 4
288
285
  summary: Manage translations in ruby applications with the awesome power of static