i18n_screwdriver 8.0 → 8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/i18n_screwdriver/rails.rb +0 -1
- data/lib/i18n_screwdriver/translation.rb +12 -6
- data/lib/i18n_screwdriver/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bcf4a98f37390d173a9fa6a82f3c595c17c98b4
|
4
|
+
data.tar.gz: 74c3c6b1abf2d63d27c1a081033f782c15af896d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d92d15d612024f28392ebd6bf74f8951826a53842cb70ff0e2d5aeff5f6cbf5354c7893cb2ee8112179fe0d164fab85428a40299cb59a4cd4c7266963448a31d
|
7
|
+
data.tar.gz: d56782ac7f4b2b693b3cd741dfa9acb4f9a7a13d824159390668dc4186137419bb9768d00dea432c4dee2d7178b73591a51b32918377b788baca9d379350bd5b
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module I18nScrewdriver
|
2
2
|
class Translation < String
|
3
|
+
Error = Class.new(StandardError)
|
4
|
+
|
3
5
|
attr_accessor :text, :options
|
4
6
|
|
5
7
|
def self.new(text, options = {}, &block)
|
@@ -10,17 +12,22 @@ module I18nScrewdriver
|
|
10
12
|
if block
|
11
13
|
urls = Array(block.call)
|
12
14
|
urls_to_interpolate_count = translation.scan(/<<.+?>>/).count
|
13
|
-
|
14
|
-
if urls.count > urls_to_interpolate_count
|
15
|
-
raise ArgumentError, "too many urls specified (#{urls.count} <> #{urls_to_interpolate_count})" unless urls.last.is_a?(Hash)
|
16
|
-
translation = new(translation % urls.last, :raw => true)
|
17
|
-
end
|
15
|
+
emit_warning("invalid number of urls specified (#{urls.count} <> #{urls_to_interpolate_count})") unless urls.count == urls_to_interpolate_count
|
18
16
|
translation.linkify(block.binding, urls)
|
19
17
|
end
|
20
18
|
|
21
19
|
translation
|
22
20
|
end
|
23
21
|
|
22
|
+
def self.emit_warning(message)
|
23
|
+
raise Error, message unless ::Rails.env.production?
|
24
|
+
::Rails.logger.warn(%|I18nScrewdriver: #{message}\n#{application_frames(caller).join("\n")}|)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.application_frames(backtrace)
|
28
|
+
backtrace.select{ |path| path.starts_with?(::Rails.root.to_s) }
|
29
|
+
end
|
30
|
+
|
24
31
|
def linkify(binding, urls)
|
25
32
|
context = binding ? eval('self', binding) : self
|
26
33
|
keep_html_safety do
|
@@ -42,4 +49,3 @@ module I18nScrewdriver
|
|
42
49
|
end
|
43
50
|
end
|
44
51
|
end
|
45
|
-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n_screwdriver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '8.
|
4
|
+
version: '8.1'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Miesel
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-02-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
81
|
version: '0'
|
82
82
|
requirements: []
|
83
83
|
rubyforge_project: i18n_screwdriver
|
84
|
-
rubygems_version: 2.4.5
|
84
|
+
rubygems_version: 2.4.5.1
|
85
85
|
signing_key:
|
86
86
|
specification_version: 4
|
87
87
|
summary: make translating with rails i18n fun again
|