i18n_checker 0.8.3 → 0.8.4
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/locale/collector/haml.rb +31 -11
- data/lib/i18n_checker/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3aa0725f4c247f4ab4ed612ecb97dec782c73b4
|
4
|
+
data.tar.gz: 8b5c1d22ca006e77bccabb050db792846e622765
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a8a1898e458c0951ab6f31731c8b286837670621b18060ad595addbd73f16183bddc195ed85118843c10c61bb15b96340f583ca5690b23f5a50e08b4f4f3837
|
7
|
+
data.tar.gz: aad50cda3a20a0213b6c9c4007a5f3000e5ceebce318862df5667f8857fa2c14cce24029e7a0f6aab49a9adf08166acab4878ac7a395f1067f1e2af9de28bf01
|
data/Gemfile.lock
CHANGED
@@ -36,29 +36,43 @@ module I18nChecker
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def collect_locale_text(ast)
|
39
|
+
return locale_text_from_text(ast) if ast.is_a?(HamlParser::Ast::Text)
|
39
40
|
return locale_text_from_script(ast) if ast.is_a?(HamlParser::Ast::Script)
|
40
41
|
return unless ast.respond_to?(:oneline_child)
|
41
|
-
|
42
|
-
|
42
|
+
if ast.oneline_child.is_a?(HamlParser::Ast::Text)
|
43
|
+
locale_text_from_text(ast.oneline_child)
|
44
|
+
elsif ast.oneline_child.is_a?(HamlParser::Ast::Script)
|
45
|
+
locale_text_from_script(ast.oneline_child)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def locale_text_from_text(text_node)
|
50
|
+
return if text_node.text == '""'
|
51
|
+
translate_scripts = translate_scripts_from_node(text_node)
|
52
|
+
return if translate_scripts.empty?
|
53
|
+
create_node_result(text_node, translate_scripts)
|
43
54
|
end
|
44
55
|
|
45
56
|
def locale_text_from_script(script_node)
|
46
57
|
return if script_node.script == '""'
|
47
|
-
translate_scripts =
|
58
|
+
translate_scripts = translate_scripts_from_node(script_node)
|
48
59
|
return if translate_scripts.empty?
|
60
|
+
create_node_result(script_node, translate_scripts)
|
61
|
+
end
|
49
62
|
|
63
|
+
def create_node_result(ast_node, translate_scripts)
|
50
64
|
translate_scripts.map do |script_params|
|
51
65
|
(text_key, line, column) = script_params
|
52
66
|
|
53
67
|
locale_text = if text_key =~ /^\.(.+)/
|
54
|
-
action_view = action_view_name_from_script(
|
68
|
+
action_view = action_view_name_from_script(ast_node)
|
55
69
|
"#{action_view}#{text_key}"
|
56
70
|
else
|
57
71
|
text_key
|
58
72
|
end
|
59
73
|
|
60
74
|
I18nChecker::Locale::Text.new(
|
61
|
-
file:
|
75
|
+
file: ast_node.filename,
|
62
76
|
line: line,
|
63
77
|
column: column,
|
64
78
|
text: locale_text,
|
@@ -66,15 +80,21 @@ module I18nChecker
|
|
66
80
|
end
|
67
81
|
end
|
68
82
|
|
69
|
-
def
|
83
|
+
def translate_scripts_from_node(ast_node)
|
70
84
|
results = []
|
71
|
-
file_cache = file_caches.read(
|
72
|
-
|
73
|
-
|
85
|
+
file_cache = file_caches.read(ast_node.filename)
|
86
|
+
|
87
|
+
node_lines = if ast_node.is_a?(HamlParser::Ast::Text)
|
88
|
+
ast_node.text.split("\n")
|
89
|
+
elsif ast_node.is_a?(HamlParser::Ast::Script)
|
90
|
+
ast_node.script.split("\n")
|
91
|
+
end
|
92
|
+
|
93
|
+
node_lines.each_with_index do |node_line, i|
|
74
94
|
offset_at = 0
|
75
|
-
translate_scripts =
|
95
|
+
translate_scripts = node_line.scan(/t\('[^']+'\)/)
|
76
96
|
map_results = translate_scripts.map do |script|
|
77
|
-
line =
|
97
|
+
line = ast_node.lineno + i
|
78
98
|
text_key = script.gsub!(/t\('|'\)/, '')
|
79
99
|
column = file_cache[line].start_of(text_key, offset_at)
|
80
100
|
offset_at = column + 1
|
data/lib/i18n_checker/version.rb
CHANGED