i18n_checker 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/i18n_checker/cache.rb +123 -0
- data/lib/i18n_checker/detector/locale_text_not_found.rb +1 -1
- data/lib/i18n_checker/detector/text_result.rb +21 -0
- data/lib/i18n_checker/locale/collector/haml.rb +14 -3
- data/lib/i18n_checker/locale/collector/ruby.rb +8 -1
- data/lib/i18n_checker/locale.rb +6 -4
- data/lib/i18n_checker/locale_text_not_found_checker.rb +1 -1
- data/lib/i18n_checker/rake_task.rb +1 -0
- data/lib/i18n_checker/reporter/default_reporter.rb +3 -3
- data/lib/i18n_checker/version.rb +1 -1
- data/lib/i18n_checker.rb +2 -1
- metadata +4 -3
- data/lib/i18n_checker/detector/locale_text_result.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8cc0a9bda5cd2dd6ec90141387fdf63601481d8
|
4
|
+
data.tar.gz: 7ae32cf03e242ba9887f66066221499c8a6738ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49d3701f3164df63479d64256a589788761832649ef75507e827dd674d416f60048961d896ac7c728e8ab9b70eb954c17cf888cca151c94e282fcce47e5652c7
|
7
|
+
data.tar.gz: 739df006a0076e099d3740c96d8d83f49ee84c544676f1e0c6296faa26c609da5c8d08e503aad3d7bc29e7466f9fe3f55da7623c64becee18b91aefcf70c4148
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module I18nChecker
|
4
|
+
module Cache
|
5
|
+
class Files
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
include Enumerable
|
9
|
+
|
10
|
+
attr_reader :files
|
11
|
+
|
12
|
+
def_delegators :files, :size, :each
|
13
|
+
|
14
|
+
def initialize(files = {})
|
15
|
+
@files = files
|
16
|
+
end
|
17
|
+
|
18
|
+
def read(file)
|
19
|
+
return files[file] if files.key?(file)
|
20
|
+
files[file] = I18nChecker::Cache::File::of(file)
|
21
|
+
files[file]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class File
|
26
|
+
attr_reader :file, :lines
|
27
|
+
|
28
|
+
class << self
|
29
|
+
def of(file)
|
30
|
+
new(file, Lines::of(::File.read(file)))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def initialize(file, lines)
|
35
|
+
@file = file
|
36
|
+
@lines = lines
|
37
|
+
end
|
38
|
+
|
39
|
+
def [](scope)
|
40
|
+
lines[scope]
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_s
|
44
|
+
lines.to_s
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class Lines
|
49
|
+
extend Forwardable
|
50
|
+
|
51
|
+
include Enumerable
|
52
|
+
|
53
|
+
attr_reader :lines
|
54
|
+
|
55
|
+
def_delegators :lines, :size, :each
|
56
|
+
|
57
|
+
class << self
|
58
|
+
def of(source)
|
59
|
+
lines = {}
|
60
|
+
source.split("\n").each_with_index do |content, i|
|
61
|
+
line_number = i + 1
|
62
|
+
lines[line_number] = Line.new(line_number, content)
|
63
|
+
end
|
64
|
+
last_key = lines.keys.last
|
65
|
+
lines.delete last_key if lines[last_key] == ''
|
66
|
+
new(lines)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def initialize(lines = {})
|
71
|
+
@lines = lines
|
72
|
+
end
|
73
|
+
|
74
|
+
def [](scope)
|
75
|
+
return lines_of(scope) if scope.kind_of?(Range)
|
76
|
+
return line_of(scope) if scope.kind_of?(Integer)
|
77
|
+
end
|
78
|
+
|
79
|
+
def line_of(line_number)
|
80
|
+
lines[line_number]
|
81
|
+
end
|
82
|
+
|
83
|
+
def lines_of(range)
|
84
|
+
results = {}
|
85
|
+
raise StandardError, "invalid line number #{range.first}" if range.first <= 0
|
86
|
+
raise StandardError, "invalid line number #{range.last}" if lines.size < range.last
|
87
|
+
range.each do |i|
|
88
|
+
results[i] = lines[i]
|
89
|
+
end
|
90
|
+
self.class.new(results)
|
91
|
+
end
|
92
|
+
|
93
|
+
def to_s
|
94
|
+
lines.values.join("\n")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
class Line
|
99
|
+
attr_reader :line, :content
|
100
|
+
|
101
|
+
def initialize(line_number, content)
|
102
|
+
@line = line_number
|
103
|
+
@content = content
|
104
|
+
end
|
105
|
+
|
106
|
+
def [](range)
|
107
|
+
columns_of(range)
|
108
|
+
end
|
109
|
+
|
110
|
+
def columns_of(range)
|
111
|
+
content[range.first - 1, range.last]
|
112
|
+
end
|
113
|
+
|
114
|
+
def start_of(text)
|
115
|
+
content.index(text)
|
116
|
+
end
|
117
|
+
|
118
|
+
def to_s
|
119
|
+
content
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -16,7 +16,7 @@ module I18nChecker
|
|
16
16
|
locale_files = @locale_files.dup
|
17
17
|
locale_files.delete_if { |locale_file| locale_file.include?(locale_text) }
|
18
18
|
locale_files.map do |locale_file|
|
19
|
-
|
19
|
+
TextResult.new(
|
20
20
|
locale_text: locale_text,
|
21
21
|
locale_file: locale_file
|
22
22
|
)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module I18nChecker
|
4
|
+
module Detector
|
5
|
+
class TextResult
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
def_delegators :locale_file, :lang
|
9
|
+
def_delegators :locale_text, :file, :line, :column, :text
|
10
|
+
|
11
|
+
def initialize(locale_file:, locale_text:)
|
12
|
+
@locale_text = locale_text
|
13
|
+
@locale_file = locale_file
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :locale_file, :locale_text
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -9,6 +9,12 @@ module I18nChecker
|
|
9
9
|
class Haml
|
10
10
|
include I18nChecker::Collectible
|
11
11
|
|
12
|
+
attr_reader :file_caches
|
13
|
+
|
14
|
+
def initialize(file_caches = I18nChecker::Cache::Files.new)
|
15
|
+
@file_caches = file_caches
|
16
|
+
end
|
17
|
+
|
12
18
|
def collect(template_file)
|
13
19
|
template = read_template_file(template_file)
|
14
20
|
parser = HamlParser::Parser.new(filename: template_file)
|
@@ -18,7 +24,7 @@ module I18nChecker
|
|
18
24
|
private
|
19
25
|
|
20
26
|
def read_template_file(template_file)
|
21
|
-
|
27
|
+
file_caches.read(template_file).to_s
|
22
28
|
end
|
23
29
|
|
24
30
|
def collect_locale_texts(ast)
|
@@ -38,11 +44,16 @@ module I18nChecker
|
|
38
44
|
|
39
45
|
def locale_text_from_script(script_node)
|
40
46
|
return unless translate_script = script_node.script.match(/^t\(\'+(.+)\'+\)$/)
|
47
|
+
|
48
|
+
locale_text = translate_script[1]
|
49
|
+
file_cache = file_caches.read(script_node.filename)
|
50
|
+
column = file_cache[script_node.lineno].start_of(locale_text)
|
51
|
+
|
41
52
|
I18nChecker::Locale::Text.new(
|
42
53
|
file: script_node.filename,
|
43
54
|
line: script_node.lineno,
|
44
|
-
column:
|
45
|
-
text:
|
55
|
+
column: column,
|
56
|
+
text: locale_text
|
46
57
|
)
|
47
58
|
end
|
48
59
|
end
|
@@ -10,6 +10,12 @@ module I18nChecker
|
|
10
10
|
class Ruby
|
11
11
|
include I18nChecker::Collectible
|
12
12
|
|
13
|
+
attr_reader :file_caches
|
14
|
+
|
15
|
+
def initialize(file_caches = I18nChecker::Cache::Files.new)
|
16
|
+
@file_caches = file_caches
|
17
|
+
end
|
18
|
+
|
13
19
|
def collect(source_file)
|
14
20
|
I18nChecker::Locale::Texts.new(process(source_file))
|
15
21
|
end
|
@@ -17,8 +23,9 @@ module I18nChecker
|
|
17
23
|
private
|
18
24
|
|
19
25
|
def buffer_of(source_file)
|
26
|
+
source = file_caches.read(source_file).to_s
|
20
27
|
source_buffer = Parser::Source::Buffer.new('(string)')
|
21
|
-
source_buffer.source =
|
28
|
+
source_buffer.source = source
|
22
29
|
source_buffer
|
23
30
|
end
|
24
31
|
|
data/lib/i18n_checker/locale.rb
CHANGED
@@ -12,20 +12,22 @@ module I18nChecker
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def texts_of(resources)
|
15
|
+
caches = I18nChecker::Cache::Files.new
|
16
|
+
|
15
17
|
files = resources.delete_if { |resource| ::File.directory?(resource) }.to_a
|
16
18
|
grouped_files = files.group_by { |file| ::File.extname(file) }
|
17
19
|
grouped_locale_texts = grouped_files.map do |k, v|
|
18
|
-
text_collector_of(k).collect_all(v)
|
20
|
+
text_collector_of(k, caches: caches).collect_all(v)
|
19
21
|
end
|
20
22
|
grouped_locale_texts.reduce { |locale_texts, n| locale_texts.concat(n) }.uniq!
|
21
23
|
end
|
22
24
|
|
23
|
-
def text_collector_of(file_extname)
|
25
|
+
def text_collector_of(file_extname, caches:)
|
24
26
|
case file_extname
|
25
27
|
when '.haml'
|
26
|
-
I18nChecker::Locale::Collector::Haml.new
|
28
|
+
I18nChecker::Locale::Collector::Haml.new(caches)
|
27
29
|
when '.rb'
|
28
|
-
I18nChecker::Locale::Collector::Ruby.new
|
30
|
+
I18nChecker::Locale::Collector::Ruby.new(caches)
|
29
31
|
else
|
30
32
|
raise StandardError, "not support #{extname} file" # FIXME: throw custom error!!
|
31
33
|
end
|
@@ -17,10 +17,10 @@ module I18nChecker
|
|
17
17
|
|
18
18
|
def failed(result)
|
19
19
|
logger.info CHECK_COMPLETED.red
|
20
|
-
logger.info
|
20
|
+
logger.info "There are settings where translated text can not be found\n".red
|
21
21
|
result.locale_texts.each do |locale_text|
|
22
|
-
logger.info "
|
23
|
-
logger.info "
|
22
|
+
logger.info "#{locale_text.file.cyan}"
|
23
|
+
logger.info " line:#{locale_text.line}, column:#{locale_text.column} - #{locale_text.lang}.#{locale_text.text}"
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
data/lib/i18n_checker/version.rb
CHANGED
data/lib/i18n_checker.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "i18n_checker/version"
|
2
2
|
require "i18n_checker/rake_task"
|
3
3
|
require "i18n_checker/collectible"
|
4
|
+
require "i18n_checker/cache"
|
4
5
|
require "i18n_checker/locale"
|
5
6
|
require "i18n_checker/locale/text_processor"
|
6
7
|
require "i18n_checker/locale/collector/haml"
|
@@ -11,7 +12,7 @@ require "i18n_checker/locale/key_path"
|
|
11
12
|
require "i18n_checker/locale/file"
|
12
13
|
require "i18n_checker/locale/files"
|
13
14
|
require "i18n_checker/detector/locale_text_not_found"
|
14
|
-
require "i18n_checker/detector/
|
15
|
+
require "i18n_checker/detector/text_result"
|
15
16
|
require "i18n_checker/detector/detected_result"
|
16
17
|
require "i18n_checker/reporter/detect_result_reporter"
|
17
18
|
require "i18n_checker/reporter/default_reporter"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n_checker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- holyshared
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: haml_parser
|
@@ -155,10 +155,11 @@ files:
|
|
155
155
|
- Rakefile
|
156
156
|
- i18n-checker.gemspec
|
157
157
|
- lib/i18n_checker.rb
|
158
|
+
- lib/i18n_checker/cache.rb
|
158
159
|
- lib/i18n_checker/collectible.rb
|
159
160
|
- lib/i18n_checker/detector/detected_result.rb
|
160
161
|
- lib/i18n_checker/detector/locale_text_not_found.rb
|
161
|
-
- lib/i18n_checker/detector/
|
162
|
+
- lib/i18n_checker/detector/text_result.rb
|
162
163
|
- lib/i18n_checker/locale.rb
|
163
164
|
- lib/i18n_checker/locale/collector.rb
|
164
165
|
- lib/i18n_checker/locale/collector/haml.rb
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module I18nChecker
|
2
|
-
module Detector
|
3
|
-
class LocaleTextResult
|
4
|
-
def initialize(locale_file:, locale_text:)
|
5
|
-
@locale_text = locale_text
|
6
|
-
@locale_file = locale_file
|
7
|
-
end
|
8
|
-
|
9
|
-
def file_name
|
10
|
-
@locale_text.file
|
11
|
-
end
|
12
|
-
|
13
|
-
def lang
|
14
|
-
@locale_file.lang
|
15
|
-
end
|
16
|
-
|
17
|
-
def line
|
18
|
-
@locale_text.line
|
19
|
-
end
|
20
|
-
|
21
|
-
def text
|
22
|
-
@locale_text.text
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|