i18n_checker 0.8.1 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '00138b291e22894b6beffebb4ab1332f98d5bae0'
4
- data.tar.gz: ac641342d31374cd17b9292ff78808760ade2cf5
3
+ metadata.gz: 6a836e6d5da915e6a4067a784687348ed8cd980d
4
+ data.tar.gz: b3ab5d76dda32cb5924b96d99b0c5bfae393168b
5
5
  SHA512:
6
- metadata.gz: 5a7be1b6c288c48ebf122d8797f7b49c951f247c52480fb420d0452cfcc5121ab31f1c0db0b53ddd54d7a665eea7ece23f4caa2f3e053bfe50d57ae0289d0cc9
7
- data.tar.gz: 995d236b18d1c362e5a93fd322e64fa0b624ad3251ea677d1078ded0ca38594cf971a3d048863c3b487f14b1941dc46828709814b31d715d3a51147202769a12
6
+ metadata.gz: b47f50dcc54c37ec5ad1542dabce3fe8712814008cddb7d2b59d990a87f9d4f55f2dd778538961edcb99ca5b25f6d23c4c3ea8bbe4c12f570974262fe97e6230
7
+ data.tar.gz: 4ed1f941e6a9dd720d593157751d3d4dbb45daeebac9a447a59c7026d7b7ace59b7b3804b46499c0f1da22bf392de9c17ccb069f99d292321ef398bab5a92b37
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- i18n_checker (0.8.1)
4
+ i18n_checker (0.8.2)
5
5
  colorator (~> 1.1.0)
6
6
  haml_parser (~> 0.4)
7
7
  parser
@@ -111,8 +111,8 @@ module I18nChecker
111
111
  content[range.first - 1, range.last]
112
112
  end
113
113
 
114
- def start_of(text)
115
- content.index(text)
114
+ def start_of(text, at = 0)
115
+ content.index(text, at)
116
116
  end
117
117
 
118
118
  def to_s
@@ -43,26 +43,50 @@ module I18nChecker
43
43
  end
44
44
 
45
45
  def locale_text_from_script(script_node)
46
- translate_script = script_node.script.match(/^t\(\'+(.+)\'+\)$/)
47
- return unless translate_script
46
+ return if script_node.script == '""'
47
+ translate_scripts = translate_scripts_from_script(script_node)
48
+ return if translate_scripts.empty?
48
49
 
49
- locale_text_key = translate_script[1]
50
- file_cache = file_caches.read(script_node.filename)
51
- column = file_cache[script_node.lineno].start_of(locale_text_key)
50
+ translate_scripts.map do |script_params|
51
+ (text_key, line, column) = script_params
52
+
53
+ locale_text = if text_key =~ /^\.(.+)/
54
+ action_view = action_view_name_from_script(script_node)
55
+ "#{action_view}#{text_key}"
56
+ else
57
+ text_key
58
+ end
52
59
 
53
- locale_text = if locale_text_key =~ /^\.(.+)/
54
- action_view = action_view_name_from_script(script_node)
55
- "#{action_view}#{locale_text_key}"
56
- else
57
- locale_text_key
58
- end
60
+ I18nChecker::Locale::Text.new(
61
+ file: script_node.filename,
62
+ line: line,
63
+ column: column,
64
+ text: locale_text,
65
+ )
66
+ end
67
+ end
59
68
 
60
- I18nChecker::Locale::Text.new(
61
- file: script_node.filename,
62
- line: script_node.lineno,
63
- column: column,
64
- text: locale_text,
65
- )
69
+ def translate_scripts_from_script(script_node)
70
+ results = []
71
+ file_cache = file_caches.read(script_node.filename)
72
+ script_lines = script_node.script.split('\n')
73
+ script_lines.each_with_index do |script_line, i|
74
+ offset_at = 0
75
+ translate_scripts = script_line.scan(/t\('[^']+'\)/)
76
+ map_results = translate_scripts.map do |script|
77
+ line = script_node.lineno + i
78
+ text_key = script.gsub!(/t\('|'\)/, '')
79
+ column = file_cache[line].start_of(text_key, offset_at)
80
+ offset_at = column + 1
81
+ [
82
+ text_key,
83
+ line,
84
+ column
85
+ ]
86
+ end
87
+ results.concat(map_results)
88
+ end
89
+ results
66
90
  end
67
91
 
68
92
  # Translation key for lazy lookup
@@ -1,3 +1,3 @@
1
1
  module I18nChecker
2
- VERSION = '0.8.1'.freeze
2
+ VERSION = '0.8.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n_checker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - holyshared