i18n-tasks 0.5.4 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +9 -0
- data/README.md +46 -36
- data/Rakefile +2 -2
- data/lib/i18n/tasks/base_task.rb +2 -0
- data/lib/i18n/tasks/commands.rb +55 -35
- data/lib/i18n/tasks/commands_base.rb +36 -9
- data/lib/i18n/tasks/configuration.rb +14 -13
- data/lib/i18n/tasks/console_context.rb +0 -1
- data/lib/i18n/tasks/data.rb +2 -2
- data/lib/i18n/tasks/data/adapter/json_adapter.rb +6 -2
- data/lib/i18n/tasks/data/file_formats.rb +19 -4
- data/lib/i18n/tasks/data/file_system_base.rb +1 -1
- data/lib/i18n/tasks/data/tree/node.rb +11 -37
- data/lib/i18n/tasks/data/tree/nodes.rb +6 -2
- data/lib/i18n/tasks/data/tree/siblings.rb +53 -29
- data/lib/i18n/tasks/data/tree/traversal.rb +4 -2
- data/lib/i18n/tasks/fill_tasks.rb +5 -2
- data/lib/i18n/tasks/ignore_keys.rb +1 -1
- data/lib/i18n/tasks/locale_pathname.rb +1 -1
- data/lib/i18n/tasks/logging.rb +2 -0
- data/lib/i18n/tasks/missing_keys.rb +74 -31
- data/lib/i18n/tasks/plural_keys.rb +4 -3
- data/lib/i18n/tasks/reports/base.rb +8 -5
- data/lib/i18n/tasks/reports/spreadsheet.rb +15 -3
- data/lib/i18n/tasks/reports/terminal.rb +62 -23
- data/lib/i18n/tasks/scanners/base_scanner.rb +4 -2
- data/lib/i18n/tasks/scanners/relative_keys.rb +21 -0
- data/lib/i18n/tasks/split_key.rb +39 -0
- data/lib/i18n/tasks/used_keys.rb +1 -1
- data/lib/i18n/tasks/version.rb +1 -1
- data/spec/fixtures/app/views/index.html.slim +2 -0
- data/spec/i18n_tasks_spec.rb +19 -5
- data/spec/locale_pathname_spec.rb +24 -0
- data/spec/locale_tree/siblings_spec.rb +41 -4
- data/spec/split_key_spec.rb +27 -0
- data/spec/support/i18n_tasks_output_matcher.rb +7 -13
- data/spec/support/trees.rb +4 -0
- data/templates/config/i18n-tasks.yml +82 -0
- data/templates/rspec/i18n_spec.rb +18 -0
- metadata +10 -3
- data/lib/i18n/tasks/relative_keys.rb +0 -19
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'SplitKey' do
|
4
|
+
include SplitKey
|
5
|
+
|
6
|
+
[['', %w()],
|
7
|
+
['a', %w(a)],
|
8
|
+
['a.b', %w(a b)],
|
9
|
+
['a.b.', %w(a b)],
|
10
|
+
['a.b.c', %w(a b c)],
|
11
|
+
['a.#{b.c}', %w(a #{b.c})],
|
12
|
+
['a.#{b.c}.', %w(a #{b.c})],
|
13
|
+
['a.#{b.c}.d', %w(a #{b.c} d)],
|
14
|
+
['a.#{b.c}.d.[e.f]', %w(a #{b.c} d [e.f])],
|
15
|
+
].each do |(arg, ret)|
|
16
|
+
it "#{arg} is split into #{ret.inspect}" do
|
17
|
+
expect(split_key arg).to eq(ret)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'limits results to second argument' do
|
22
|
+
expect(split_key 'a.b.c', 1).to eq(['a.b.c'])
|
23
|
+
expect(split_key 'a.b.c', 2).to eq(['a', 'b.c'])
|
24
|
+
expect(split_key 'a.b.c.', 2).to eq(['a', 'b.c.'])
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -6,23 +6,17 @@ RSpec::Matchers.define :be_i18n_keys do |expected|
|
|
6
6
|
|
7
7
|
def extract_keys(actual)
|
8
8
|
actual = Term::ANSIColor.uncolor(actual).split("\n").map(&:presence).compact
|
9
|
-
actual = actual[3..-2]
|
9
|
+
actual = actual[3..-2]
|
10
10
|
actual = actual.map { |row|
|
11
|
+
next if row =~ /^\|\s+\|/
|
11
12
|
row.gsub(/(?:\s|^)\|(?:\s|$)/, ' ').gsub(/\s+/, ' ').strip.split(' ').map(&:presence).compact
|
12
|
-
}
|
13
|
+
}.compact
|
13
14
|
return [] if actual.empty?
|
14
|
-
|
15
|
-
|
16
|
-
key_col = 2
|
17
|
-
elsif actual[0].length == 3
|
18
|
-
locale_col = 0
|
19
|
-
key_col = 1
|
20
|
-
else
|
21
|
-
key_col = 0
|
22
|
-
end
|
15
|
+
locale_col = 0
|
16
|
+
key_col = 1
|
23
17
|
actual.map { |row|
|
24
|
-
key =
|
25
|
-
key = row[locale_col]
|
18
|
+
key =
|
19
|
+
key = "#{row[locale_col]}.#{row[key_col]}"
|
26
20
|
key = key[0..-2] if key.end_with?(':')
|
27
21
|
key
|
28
22
|
}.compact
|
data/spec/support/trees.rb
CHANGED
@@ -0,0 +1,82 @@
|
|
1
|
+
# i18n-tasks find and manage missing and unused translations ⚙ https://github.com/glebm/i18n-tasks
|
2
|
+
|
3
|
+
base_locale: en
|
4
|
+
## i18n-tasks detects locales automatically from the existing locale files
|
5
|
+
## uncomment to set locales explicitly
|
6
|
+
# locales: [en, es, fr]
|
7
|
+
|
8
|
+
# Read and write locale data
|
9
|
+
data:
|
10
|
+
## by default, translation data are read from the file system, or you can provide a custom data adapter
|
11
|
+
# adapter: I18n::Tasks::Data::FileSystem
|
12
|
+
|
13
|
+
# Locale files to read from
|
14
|
+
read:
|
15
|
+
- config/locales/%{locale}.yml
|
16
|
+
# - config/locales/*.%{locale}.yml
|
17
|
+
# - config/locales/**/*.%{locale}.yml
|
18
|
+
|
19
|
+
# key => file routes, matched top to bottom
|
20
|
+
write:
|
21
|
+
## E.g., write devise and simple form keys to their respective files
|
22
|
+
# - ['{devise, simple_form}.*', 'config/locales/\1.%{locale.yml}']
|
23
|
+
# Catch-all
|
24
|
+
- config/locales/%{locale}.yml
|
25
|
+
# `i18n-tasks normalize -p` will force move the keys according to these rules
|
26
|
+
|
27
|
+
# YAML / JSON serializer options, passed to load / dump / parse / serialize
|
28
|
+
yaml:
|
29
|
+
write:
|
30
|
+
## do not wrap lines at 80 characters (override default)
|
31
|
+
# line_width: -1
|
32
|
+
json:
|
33
|
+
write:
|
34
|
+
# pretty print JSON
|
35
|
+
indent: ' '
|
36
|
+
space: ' '
|
37
|
+
object_nl: "\n"
|
38
|
+
array_nl: "\n"
|
39
|
+
|
40
|
+
# Find translate calls
|
41
|
+
search:
|
42
|
+
## Default scanner finds t() and I18n.t() calls
|
43
|
+
# scanner: I18n::Tasks::Scanners::PatternWithScopeScanner
|
44
|
+
|
45
|
+
## Paths to search in, passed to File.find
|
46
|
+
paths:
|
47
|
+
- app/
|
48
|
+
|
49
|
+
## Root for resolving relative keys (default)
|
50
|
+
# relative_roots:
|
51
|
+
# - app/views
|
52
|
+
|
53
|
+
## File.fnmatch patterns to exclude from search (default)
|
54
|
+
# exclude: ["*.jpg", "*.png", "*.gif", "*.svg", "*.ico", "*.eot", "*.ttf", "*.woff", "*.pdf"]
|
55
|
+
|
56
|
+
## Or, File.fnmatch patterns to include
|
57
|
+
# include: ["*.rb", "*.html.slim"]
|
58
|
+
|
59
|
+
## Lines starting with # or / are ignored by default
|
60
|
+
# ignore_lines:
|
61
|
+
# - "^\\s*[#/](?!\\si18n-tasks-use)"
|
62
|
+
|
63
|
+
## Consider these keys not missing
|
64
|
+
# ignore_missing:
|
65
|
+
# - pagination.views.*
|
66
|
+
|
67
|
+
## Consider these keys used
|
68
|
+
# ignore_unused:
|
69
|
+
# - 'simple_form.{yes,no}'
|
70
|
+
# - 'simple_form.{placeholders,hints,labels}.*'
|
71
|
+
# - 'simple_form.{error_notification,required}.:'
|
72
|
+
|
73
|
+
## Exclude these keys from `i18n-tasks eq-base' report
|
74
|
+
# ignore_eq_base:
|
75
|
+
# all:
|
76
|
+
# - common.ok
|
77
|
+
# fr,es:
|
78
|
+
# - common.brand
|
79
|
+
|
80
|
+
## Exclude these keys from all of the reports
|
81
|
+
# ignore:
|
82
|
+
# - kaminari.*
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'i18n/tasks'
|
3
|
+
|
4
|
+
describe 'I18n' do
|
5
|
+
let(:i18n) { I18n::Tasks::BaseTask.new }
|
6
|
+
let(:missing_keys) { i18n.missing_keys }
|
7
|
+
let(:unused_keys) { i18n.unused_keys }
|
8
|
+
|
9
|
+
it 'does not have missing keys' do
|
10
|
+
expect(missing_keys).to be_empty,
|
11
|
+
"Missing #{missing_keys.leaves.count} i18n keys, run `i18n-tasks missing' to show them"
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'does not have unused keys' do
|
15
|
+
expect(i18n.unused_keys).to be_empty,
|
16
|
+
"#{unused_keys.leaves.count} unused i18n keys, run `i18n-tasks unused' to show them"
|
17
|
+
end
|
18
|
+
end
|
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.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- glebm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erubis
|
@@ -229,13 +229,14 @@ files:
|
|
229
229
|
- lib/i18n/tasks/logging.rb
|
230
230
|
- lib/i18n/tasks/missing_keys.rb
|
231
231
|
- lib/i18n/tasks/plural_keys.rb
|
232
|
-
- lib/i18n/tasks/relative_keys.rb
|
233
232
|
- lib/i18n/tasks/reports/base.rb
|
234
233
|
- lib/i18n/tasks/reports/spreadsheet.rb
|
235
234
|
- lib/i18n/tasks/reports/terminal.rb
|
236
235
|
- lib/i18n/tasks/scanners/base_scanner.rb
|
237
236
|
- lib/i18n/tasks/scanners/pattern_scanner.rb
|
238
237
|
- lib/i18n/tasks/scanners/pattern_with_scope_scanner.rb
|
238
|
+
- lib/i18n/tasks/scanners/relative_keys.rb
|
239
|
+
- lib/i18n/tasks/split_key.rb
|
239
240
|
- lib/i18n/tasks/unused_keys.rb
|
240
241
|
- lib/i18n/tasks/used_keys.rb
|
241
242
|
- lib/i18n/tasks/version.rb
|
@@ -250,12 +251,14 @@ files:
|
|
250
251
|
- spec/google_translate_spec.rb
|
251
252
|
- spec/i18n_tasks_spec.rb
|
252
253
|
- spec/key_pattern_matching_spec.rb
|
254
|
+
- spec/locale_pathname_spec.rb
|
253
255
|
- spec/locale_tree/siblings_spec.rb
|
254
256
|
- spec/pattern_scanner_spec.rb
|
255
257
|
- spec/plural_keys_spec.rb
|
256
258
|
- spec/readme_spec.rb
|
257
259
|
- spec/relative_keys_spec.rb
|
258
260
|
- spec/spec_helper.rb
|
261
|
+
- spec/split_key_spec.rb
|
259
262
|
- spec/support/capture_std.rb
|
260
263
|
- spec/support/fixtures.rb
|
261
264
|
- spec/support/i18n_tasks_output_matcher.rb
|
@@ -263,6 +266,8 @@ files:
|
|
263
266
|
- spec/support/test_codebase.rb
|
264
267
|
- spec/support/trees.rb
|
265
268
|
- spec/used_keys_spec.rb
|
269
|
+
- templates/config/i18n-tasks.yml
|
270
|
+
- templates/rspec/i18n_spec.rb
|
266
271
|
homepage: https://github.com/glebm/i18n-tasks
|
267
272
|
licenses:
|
268
273
|
- MIT
|
@@ -301,12 +306,14 @@ test_files:
|
|
301
306
|
- spec/google_translate_spec.rb
|
302
307
|
- spec/i18n_tasks_spec.rb
|
303
308
|
- spec/key_pattern_matching_spec.rb
|
309
|
+
- spec/locale_pathname_spec.rb
|
304
310
|
- spec/locale_tree/siblings_spec.rb
|
305
311
|
- spec/pattern_scanner_spec.rb
|
306
312
|
- spec/plural_keys_spec.rb
|
307
313
|
- spec/readme_spec.rb
|
308
314
|
- spec/relative_keys_spec.rb
|
309
315
|
- spec/spec_helper.rb
|
316
|
+
- spec/split_key_spec.rb
|
310
317
|
- spec/support/capture_std.rb
|
311
318
|
- spec/support/fixtures.rb
|
312
319
|
- spec/support/i18n_tasks_output_matcher.rb
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
module I18n
|
3
|
-
module Tasks
|
4
|
-
module RelativeKeys
|
5
|
-
# @param key [String] relative i18n key (starts with a .)
|
6
|
-
# @param path [String] path to the file containing the key
|
7
|
-
# @return [String] absolute version of the key
|
8
|
-
def absolutize_key(key, path, roots = relative_roots)
|
9
|
-
# normalized path
|
10
|
-
path = File.expand_path path
|
11
|
-
(path_root = roots.map { |path| File.expand_path path }.sort.reverse.detect { |root| path.start_with?(root + '/') }) or
|
12
|
-
raise CommandError.new("Error scanning #{path}: cannot resolve relative key \"#{key}\".\nSet relative_roots in config/i18n-tasks.yml (currently #{relative_roots.inspect})")
|
13
|
-
# key prefix based on path
|
14
|
-
prefix = path.gsub(%r(#{path_root}/|(\.[^/]+)*$), '').tr('/', '.').gsub(%r(\._), '.')
|
15
|
-
"#{prefix}#{key}"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|