phrase 0.0.8 → 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -1
- data/Gemfile.lock +3 -1
- data/lib/phrase.rb +15 -7
- data/lib/phrase/backend/base.rb +6 -2
- data/lib/phrase/config.rb +35 -18
- data/lib/phrase/engine.rb +2 -0
- data/lib/phrase/extensions/base.rb +1 -0
- data/lib/phrase/extensions/string.rb +1 -0
- data/lib/phrase/view_helpers.rb +18 -0
- data/phrase.gemspec +1 -1
- metadata +5 -4
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -5,6 +5,7 @@ GEM
|
|
5
5
|
addressable (2.2.7)
|
6
6
|
crack (0.3.1)
|
7
7
|
diff-lcs (1.1.3)
|
8
|
+
i18n (0.6.0)
|
8
9
|
json (1.6.5)
|
9
10
|
rspec (2.8.0)
|
10
11
|
rspec-core (~> 2.8.0)
|
@@ -24,7 +25,8 @@ PLATFORMS
|
|
24
25
|
|
25
26
|
DEPENDENCIES
|
26
27
|
activesupport
|
28
|
+
i18n
|
27
29
|
json
|
28
30
|
rspec
|
29
|
-
vcr
|
31
|
+
vcr (~> 1.11)
|
30
32
|
webmock (~> 1.7.0)
|
data/lib/phrase.rb
CHANGED
@@ -3,7 +3,9 @@
|
|
3
3
|
require 'active_support/all'
|
4
4
|
|
5
5
|
module Phrase
|
6
|
-
autoload :Config,
|
6
|
+
autoload :Config, 'phrase/config'
|
7
|
+
|
8
|
+
CLIENT_VERSION = "0.1"
|
7
9
|
|
8
10
|
class << self
|
9
11
|
|
@@ -15,7 +17,7 @@ module Phrase
|
|
15
17
|
Thread.current[:phrase_config] = value
|
16
18
|
end
|
17
19
|
|
18
|
-
%w(backend
|
20
|
+
%w(enabled backend prefix suffix auth_token client_version js_host js_use_ssl).each do |method|
|
19
21
|
module_eval <<-DELEGATORS, __FILE__, __LINE__ + 1
|
20
22
|
def #{method}
|
21
23
|
config.#{method}
|
@@ -28,19 +30,25 @@ module Phrase
|
|
28
30
|
end
|
29
31
|
DELEGATORS
|
30
32
|
end
|
33
|
+
|
34
|
+
def enabled?
|
35
|
+
enabled
|
36
|
+
end
|
31
37
|
end
|
32
38
|
|
33
39
|
autoload :Extensions, 'phrase/extensions'
|
34
|
-
autoload :
|
35
|
-
|
36
|
-
require
|
40
|
+
autoload :ViewHelpers, 'phrase/view_helpers'
|
41
|
+
|
42
|
+
require 'phrase/engine'
|
43
|
+
require 'phrase/backend'
|
37
44
|
end
|
38
45
|
|
39
46
|
module I18n
|
40
47
|
class << self
|
41
|
-
def
|
48
|
+
def translate_with_phrase(*args)
|
42
49
|
Phrase.backend.translate(*args)
|
43
50
|
end
|
51
|
+
alias_method_chain :translate, :phrase
|
44
52
|
alias_method :t, :translate
|
45
53
|
end
|
46
|
-
end
|
54
|
+
end
|
data/lib/phrase/backend/base.rb
CHANGED
@@ -3,8 +3,12 @@
|
|
3
3
|
module Phrase::Backend::Base
|
4
4
|
|
5
5
|
def translate(*args)
|
6
|
-
|
7
|
-
|
6
|
+
if Phrase.enabled?
|
7
|
+
key = lookup_normalized_key(*args)
|
8
|
+
decorate_translation(key[:key])
|
9
|
+
else
|
10
|
+
I18n.translate_without_phrase(*args)
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
14
|
protected
|
data/lib/phrase/config.rb
CHANGED
@@ -2,16 +2,26 @@
|
|
2
2
|
|
3
3
|
module Phrase
|
4
4
|
class Config
|
5
|
-
def
|
6
|
-
|
5
|
+
def client_version
|
6
|
+
Phrase::CLIENT_VERSION
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
|
9
|
+
def auth_token
|
10
|
+
@@auth_token = "" if !defined? @@auth_token or @@auth_token.nil?
|
11
|
+
@@auth_token
|
11
12
|
end
|
12
|
-
|
13
|
-
def
|
14
|
-
@@
|
13
|
+
|
14
|
+
def auth_token=(auth_token)
|
15
|
+
@@auth_token = auth_token
|
16
|
+
end
|
17
|
+
|
18
|
+
def enabled
|
19
|
+
@@enabled = true if !defined? @@enabled or @@enabled.nil?
|
20
|
+
@@enabled
|
21
|
+
end
|
22
|
+
|
23
|
+
def enabled=(enabled)
|
24
|
+
@@enabled = enabled
|
15
25
|
end
|
16
26
|
|
17
27
|
def backend
|
@@ -22,16 +32,6 @@ module Phrase
|
|
22
32
|
@@backend = backend
|
23
33
|
end
|
24
34
|
|
25
|
-
def available_locales
|
26
|
-
@@available_locales ||= nil
|
27
|
-
@@available_locales ||= I18n.available_locales
|
28
|
-
end
|
29
|
-
|
30
|
-
def available_locales=(locales)
|
31
|
-
@@available_locales = Array(locales).map { |locale| locale.to_sym }
|
32
|
-
@@available_locales = nil if @@available_locales.empty?
|
33
|
-
end
|
34
|
-
|
35
35
|
def prefix
|
36
36
|
@@prefix ||= "{{__"
|
37
37
|
end
|
@@ -47,5 +47,22 @@ module Phrase
|
|
47
47
|
def suffix=(suffix)
|
48
48
|
@@suffix = suffix
|
49
49
|
end
|
50
|
+
|
51
|
+
def js_host
|
52
|
+
@@js_host ||= 'phraseapp.com'
|
53
|
+
end
|
54
|
+
|
55
|
+
def js_host=(js_host)
|
56
|
+
@@js_host = js_host
|
57
|
+
end
|
58
|
+
|
59
|
+
def js_use_ssl
|
60
|
+
@@js_use_ssl = true if !defined? @@js_use_ssl or @@js_use_ssl.nil?
|
61
|
+
@@js_use_ssl
|
62
|
+
end
|
63
|
+
|
64
|
+
def js_use_ssl=(js_use_ssl)
|
65
|
+
@@js_use_ssl = js_use_ssl
|
66
|
+
end
|
50
67
|
end
|
51
|
-
end
|
68
|
+
end
|
data/lib/phrase/engine.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Phrase::ViewHelpers
|
2
|
+
|
3
|
+
def phrase_javascript(auth_token=nil)
|
4
|
+
auth_token ||= Phrase.auth_token
|
5
|
+
js =
|
6
|
+
%{<script>
|
7
|
+
//<![CDATA[
|
8
|
+
var phrase_auth_token = '#{auth_token}';
|
9
|
+
(function() {
|
10
|
+
var phraseapp = document.createElement('script'); phraseapp.type = 'text/javascript'; phraseapp.async = true;
|
11
|
+
phraseapp.src = ['#{Phrase.js_use_ssl ? 'https' : 'http'}://', '#{Phrase.js_host}/assets/phrase/#{Phrase.client_version}/app.js?', new Date().getTime()].join('');
|
12
|
+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(phraseapp, s);
|
13
|
+
})();
|
14
|
+
//]]>
|
15
|
+
</script>}
|
16
|
+
js.html_safe
|
17
|
+
end
|
18
|
+
end
|
data/phrase.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phrase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.1'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-05 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &70121408406900 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '3.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70121408406900
|
25
25
|
description: phrase allows you to edit translations inline, on the page itself. More
|
26
26
|
information at phraseapp.com
|
27
27
|
email:
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- lib/phrase/extensions/string.rb
|
50
50
|
- lib/phrase/tool.rb
|
51
51
|
- lib/phrase/tool_config.rb
|
52
|
+
- lib/phrase/view_helpers.rb
|
52
53
|
- phrase.gemspec
|
53
54
|
homepage: http://phraseapp.com
|
54
55
|
licenses: []
|