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 CHANGED
@@ -5,6 +5,7 @@ gem "activesupport", :require => "active_support"
5
5
 
6
6
  group :test do
7
7
  gem 'rspec'
8
+ gem 'i18n'
8
9
  gem 'webmock', '~>1.7.0'
9
- gem 'vcr'
10
+ gem 'vcr', '~>1.11'
10
11
  end
@@ -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)
@@ -3,7 +3,9 @@
3
3
  require 'active_support/all'
4
4
 
5
5
  module Phrase
6
- autoload :Config, 'phrase/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 default_locale available_locales prefix suffix).each do |method|
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 :Helpers, 'phrase/helpers'
35
- require 'phrase/engine'
36
- require 'phrase/backend'
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 translate(*args)
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
@@ -3,8 +3,12 @@
3
3
  module Phrase::Backend::Base
4
4
 
5
5
  def translate(*args)
6
- key = lookup_normalized_key(*args)
7
- decorate_translation(key[:key])
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
@@ -2,16 +2,26 @@
2
2
 
3
3
  module Phrase
4
4
  class Config
5
- def enabled?
6
- ENV['TRANSLATABLE'] == "true" || (defined?(Rails) == true && Rails.env == "staging")
5
+ def client_version
6
+ Phrase::CLIENT_VERSION
7
7
  end
8
8
 
9
- def locale
10
- I18n.locale
9
+ def auth_token
10
+ @@auth_token = "" if !defined? @@auth_token or @@auth_token.nil?
11
+ @@auth_token
11
12
  end
12
-
13
- def default_locale
14
- @@default_locale ||= I18n.default_locale
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
@@ -15,6 +15,8 @@ if defined? Rails
15
15
  ActiveSupport.on_load(:action_controller) do
16
16
  ::ActionController::Base.send :include, Phrase::Extensions::Base
17
17
  end
18
+
19
+ ActionView::Base.send :include, Phrase::ViewHelpers
18
20
  end
19
21
  end
20
22
  end
@@ -1,4 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
+
2
3
  module Phrase::Extensions::Base
3
4
  extend ActiveSupport::Concern
4
5
 
@@ -1,4 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
+
2
3
  module Phrase::Extensions::String
3
4
  extend ActiveSupport::Concern
4
5
 
@@ -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
@@ -4,7 +4,7 @@ $:.unshift lib unless $:.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "phrase"
7
- s.version = "0.0.8"
7
+ s.version = "0.1"
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Dynport GmbH"]
10
10
  s.email = ["info@phraseapp.com"]
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.0.8
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-04-18 00:00:00.000000000Z
12
+ date: 2012-06-05 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70124418301040 !ruby/object:Gem::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: *70124418301040
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: []