i18n-tasks 0.9.8 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/i18n/tasks/cli.rb +17 -17
- data/lib/i18n/tasks/data/file_system_base.rb +2 -2
- data/lib/i18n/tasks/data/router/pattern_router.rb +1 -1
- data/lib/i18n/tasks/logging.rb +10 -2
- data/lib/i18n/tasks/scanners/pattern_mapper.rb +2 -2
- data/lib/i18n/tasks/scanners/pattern_with_scope_scanner.rb +38 -12
- data/lib/i18n/tasks/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 264a1871764cc205f99b56f5c303f6b174d16ee8
|
4
|
+
data.tar.gz: c7431a8401c9cc313c67ea03b276b627e9c950f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d5db9a5e118f6c410aa43b263835b160c101f615fe56d9fedc269b0269f5458d7398d034fdc895cd6f38e1f26eb04ecea998b1fa6317d01c745348040458a83
|
7
|
+
data.tar.gz: 654a287a7ffd39c309c75e9ec0456ad28f2ebac32ecf112a7e3adbcd757367a7afe092b6ebb7497f03a013471718807b1b69cb2aa7157b06f261b3a0eaab8bc6
|
data/README.md
CHANGED
@@ -24,7 +24,7 @@ i18n-tasks can be used with any project using the ruby [i18n gem][i18n-gem] (def
|
|
24
24
|
Add i18n-tasks to the Gemfile:
|
25
25
|
|
26
26
|
```ruby
|
27
|
-
gem 'i18n-tasks', '~> 0.9.
|
27
|
+
gem 'i18n-tasks', '~> 0.9.9'
|
28
28
|
```
|
29
29
|
|
30
30
|
Copy the default [configuration file](#configuration):
|
@@ -369,13 +369,13 @@ Custom tasks can be added easily, see the examples [on the wiki](https://github.
|
|
369
369
|
|
370
370
|
[MIT license]: /LICENSE.txt
|
371
371
|
[travis]: https://travis-ci.org/glebm/i18n-tasks
|
372
|
-
[badge-travis]:
|
372
|
+
[badge-travis]: https://img.shields.io/travis/glebm/i18n-tasks.svg
|
373
373
|
[coverage]: https://codeclimate.com/github/glebm/i18n-tasks
|
374
374
|
[badge-coverage]: https://img.shields.io/codeclimate/coverage/github/glebm/i18n-tasks.svg
|
375
375
|
[gemnasium]: https://gemnasium.com/glebm/i18n-tasks
|
376
376
|
[badge-gemnasium]: https://gemnasium.com/glebm/i18n-tasks.svg
|
377
377
|
[code-climate]: https://codeclimate.com/github/glebm/i18n-tasks
|
378
|
-
[badge-code-climate]:
|
378
|
+
[badge-code-climate]: https://img.shields.io/codeclimate/github/glebm/i18n-tasks.svg
|
379
379
|
[config]: https://github.com/glebm/i18n-tasks/blob/master/templates/config/i18n-tasks.yml
|
380
380
|
[wiki]: https://github.com/glebm/i18n-tasks/wiki "i18n-tasks wiki"
|
381
381
|
[i18n-gem]: https://github.com/svenfuchs/i18n "svenfuchs/i18n on Github"
|
data/lib/i18n/tasks/cli.rb
CHANGED
@@ -13,23 +13,21 @@ class I18n::Tasks::CLI
|
|
13
13
|
def initialize; end
|
14
14
|
|
15
15
|
def start(argv)
|
16
|
-
|
17
|
-
|
16
|
+
auto_output_coloring do
|
17
|
+
begin
|
18
|
+
exit 1 if run(argv) == :exit_1
|
19
|
+
rescue OptionParser::ParseError => e
|
20
|
+
error e.message, 64
|
21
|
+
rescue I18n::Tasks::CommandError => e
|
18
22
|
begin
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
rescue I18n::Tasks::CommandError => e
|
23
|
-
begin
|
24
|
-
error e.message, 78
|
25
|
-
ensure
|
26
|
-
log_verbose e.backtrace * "\n"
|
27
|
-
end
|
28
|
-
rescue Errno::EPIPE
|
29
|
-
# ignore Errno::EPIPE which is throw when pipe breaks, e.g.:
|
30
|
-
# i18n-tasks missing | head
|
31
|
-
exit 1
|
23
|
+
error e.message, 78
|
24
|
+
ensure
|
25
|
+
log_verbose e.backtrace * "\n"
|
32
26
|
end
|
27
|
+
rescue Errno::EPIPE
|
28
|
+
# ignore Errno::EPIPE which is throw when pipe breaks, e.g.:
|
29
|
+
# i18n-tasks missing | head
|
30
|
+
exit 1
|
33
31
|
end
|
34
32
|
end
|
35
33
|
rescue ExecutionError => e
|
@@ -37,8 +35,10 @@ class I18n::Tasks::CLI
|
|
37
35
|
end
|
38
36
|
|
39
37
|
def run(argv)
|
40
|
-
|
41
|
-
|
38
|
+
I18n.with_locale(base_task.internal_locale) do
|
39
|
+
name, *options = parse!(argv.dup)
|
40
|
+
context.run(name, *options)
|
41
|
+
end
|
42
42
|
end
|
43
43
|
|
44
44
|
def context
|
@@ -88,7 +88,7 @@ module I18n::Tasks
|
|
88
88
|
@available_locales ||= begin
|
89
89
|
locales = Set.new
|
90
90
|
Array(config[:read]).map do |pattern|
|
91
|
-
[pattern, Dir.glob(pattern
|
91
|
+
[pattern, Dir.glob(format(pattern, locale: '*'))] if pattern.include?('%{locale}')
|
92
92
|
end.compact.each do |pattern, paths|
|
93
93
|
p = pattern.gsub('\\', '\\\\').gsub('/', '\/').gsub('.', '\.')
|
94
94
|
p = p.gsub(/(\*+)/) { Regexp.last_match(1) == '**' ? '.*' : '[^/]*?' }.gsub('%{locale}', '([^/.]+)')
|
@@ -138,7 +138,7 @@ module I18n::Tasks
|
|
138
138
|
|
139
139
|
def read_locale(locale)
|
140
140
|
Array(config[:read]).map do |path|
|
141
|
-
Dir.glob path
|
141
|
+
Dir.glob format(path, locale: locale)
|
142
142
|
end.reduce(:+).map do |path|
|
143
143
|
[path.freeze, load_file(path) || {}]
|
144
144
|
end.map do |path, data|
|
@@ -32,7 +32,7 @@ module I18n::Tasks
|
|
32
32
|
pattern, path = routes.detect { |route| route[0] =~ key }
|
33
33
|
if pattern
|
34
34
|
key_match = $~
|
35
|
-
path = path
|
35
|
+
path = format(path, locale: locale)
|
36
36
|
path.gsub!(/\\\d+/) { |m| key_match[m[1..-1].to_i] }
|
37
37
|
(out[path] ||= Set.new) << "#{locale}.#{key}"
|
38
38
|
else
|
data/lib/i18n/tasks/logging.rb
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
module I18n::Tasks::Logging
|
3
3
|
module_function
|
4
4
|
|
5
|
+
MUTEX = Mutex.new
|
6
|
+
PROGRAM_NAME = File.basename($PROGRAM_NAME)
|
7
|
+
|
5
8
|
def warn_deprecated(message)
|
6
9
|
log_stderr Term::ANSIColor.yellow Term::ANSIColor.bold "#{program_name}: [DEPRECATED] #{message}"
|
7
10
|
end
|
@@ -21,10 +24,15 @@ module I18n::Tasks::Logging
|
|
21
24
|
end
|
22
25
|
|
23
26
|
def log_stderr(*args)
|
24
|
-
|
27
|
+
MUTEX.synchronize do
|
28
|
+
# 1. We don't want output from different threads to get intermixed.
|
29
|
+
# 2. StringIO is currently not thread-safe (blows up) on JRuby:
|
30
|
+
# https://github.com/jruby/jruby/issues/4417
|
31
|
+
$stderr.puts(*args)
|
32
|
+
end
|
25
33
|
end
|
26
34
|
|
27
35
|
def program_name
|
28
|
-
|
36
|
+
PROGRAM_NAME
|
29
37
|
end
|
30
38
|
end
|
@@ -39,7 +39,7 @@ module I18n::Tasks::Scanners
|
|
39
39
|
matches[:key] = strip_literal(matches[:key])
|
40
40
|
next unless valid_key?(matches[:key])
|
41
41
|
end
|
42
|
-
result << [absolute_key(key
|
42
|
+
result << [absolute_key(format(key, matches), path),
|
43
43
|
occurrence_from_position(path, text, match.offset(0).first)]
|
44
44
|
end
|
45
45
|
result
|
@@ -52,7 +52,7 @@ module I18n::Tasks::Scanners
|
|
52
52
|
|
53
53
|
def configure_patterns(patterns)
|
54
54
|
patterns.map do |(pattern, key)|
|
55
|
-
[pattern.is_a?(Regexp) ? pattern : Regexp.new(pattern
|
55
|
+
[pattern.is_a?(Regexp) ? pattern : Regexp.new(format(pattern, key: KEY_GROUP)), key]
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
@@ -23,18 +23,14 @@ module I18n::Tasks::Scanners
|
|
23
23
|
key = super
|
24
24
|
scope = match[1]
|
25
25
|
if scope
|
26
|
-
|
27
|
-
|
26
|
+
scope_parts = extract_literal_or_array_of_literals(scope)
|
27
|
+
return nil if scope_parts.nil? || scope_parts.empty?
|
28
|
+
"#{scope_parts.join('.')}.#{key}"
|
28
29
|
else
|
29
30
|
key unless match[0] =~ /\A\w/
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
|
-
# also parse expressions with literals
|
34
|
-
def literal_re
|
35
|
-
/(?: (?: #{super} ) | #{expr_re} )/x
|
36
|
-
end
|
37
|
-
|
38
34
|
# strip literals, convert expressions to #{interpolations}
|
39
35
|
def strip_literal(val)
|
40
36
|
if val =~ /\A\w/
|
@@ -49,7 +45,7 @@ module I18n::Tasks::Scanners
|
|
49
45
|
/(?:
|
50
46
|
:scope\s*=>\s* | (?# :scope => :home )
|
51
47
|
scope:\s* (?# scope: :home )
|
52
|
-
) (
|
48
|
+
) ([^\n]*)/x
|
53
49
|
end
|
54
50
|
|
55
51
|
# match code expression
|
@@ -59,10 +55,40 @@ module I18n::Tasks::Scanners
|
|
59
55
|
/[\w():"'.\s]+/x
|
60
56
|
end
|
61
57
|
|
62
|
-
#
|
63
|
-
|
64
|
-
|
65
|
-
|
58
|
+
# extract literal or array of literals
|
59
|
+
# returns nil on any other input
|
60
|
+
# rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
61
|
+
def extract_literal_or_array_of_literals(s)
|
62
|
+
literals = []
|
63
|
+
braces_stack = []
|
64
|
+
acc = []
|
65
|
+
consume_literal = proc do
|
66
|
+
acc_str = acc.join
|
67
|
+
if acc_str =~ literal_re
|
68
|
+
literals << strip_literal(acc_str)
|
69
|
+
acc = []
|
70
|
+
else
|
71
|
+
return nil
|
72
|
+
end
|
73
|
+
end
|
74
|
+
s.each_char.with_index do |c, i|
|
75
|
+
if c == '['
|
76
|
+
return nil unless braces_stack.empty?
|
77
|
+
braces_stack.push(i)
|
78
|
+
elsif c == ']'
|
79
|
+
break
|
80
|
+
elsif c == ','
|
81
|
+
consume_literal.call
|
82
|
+
break if braces_stack.empty?
|
83
|
+
elsif c =~ VALID_KEY_CHARS || /['":]/ =~ c
|
84
|
+
acc << c
|
85
|
+
elsif c != ' '
|
86
|
+
return nil
|
87
|
+
end
|
88
|
+
end
|
89
|
+
consume_literal.call unless acc.empty?
|
90
|
+
literals
|
66
91
|
end
|
92
|
+
# rubocop:enable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
67
93
|
end
|
68
94
|
end
|
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.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- glebm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|