tml 5.1.1 → 5.1.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 +4 -4
- data/lib/tml/api/client.rb +16 -19
- data/lib/tml/application.rb +16 -0
- data/lib/tml/config.rb +1 -1
- data/lib/tml/language.rb +5 -5
- data/lib/tml/session.rb +25 -32
- data/lib/tml/tokens/data.rb +1 -1
- data/lib/tml/translation_key.rb +1 -1
- data/lib/tml/translator.rb +2 -2
- data/lib/tml/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4ae1644d633f0f8ead496d5ac732ccd9dcbc34c
|
4
|
+
data.tar.gz: b92c379114a8878d85a27b997c098319cd756eca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fd13088aa2fbc7f9f02a5c424e62c35111ec4f2edcba5cb2b8e2d02f1a9839e9d199b9545c20ae001ad82190b3546fe1e61e1e0d65ca241f3d7fdd6cb5d81a5
|
7
|
+
data.tar.gz: e4b4cd7014d4c3fb5bc6a8b81f94532ce036054338912d802dce3c8e8c4c249238a1121d7d58e51e903e98531c2485513dd0e021c83247f17c79fb0f8c7ceb10
|
data/lib/tml/api/client.rb
CHANGED
@@ -35,8 +35,6 @@ require 'zlib'
|
|
35
35
|
require 'stringio'
|
36
36
|
|
37
37
|
class Tml::Api::Client < Tml::Base
|
38
|
-
CDN_HOST = 'https://cdn.translationexchange.com'
|
39
|
-
API_HOST = 'https://api.translationexchange.com'
|
40
38
|
API_PATH = '/v1'
|
41
39
|
|
42
40
|
attributes :application
|
@@ -66,16 +64,8 @@ class Tml::Api::Client < Tml::Base
|
|
66
64
|
not data['error'].nil?
|
67
65
|
end
|
68
66
|
|
69
|
-
def host
|
70
|
-
application.host || API_HOST
|
71
|
-
end
|
72
|
-
|
73
|
-
def cdn_host
|
74
|
-
CDN_HOST
|
75
|
-
end
|
76
|
-
|
77
67
|
def connection
|
78
|
-
@connection ||= Faraday.new(:url => host) do |faraday|
|
68
|
+
@connection ||= Faraday.new(:url => application.host) do |faraday|
|
79
69
|
faraday.request(:url_encoded) # form-encode POST params
|
80
70
|
# faraday.response :logger # log requests to STDOUT
|
81
71
|
faraday.adapter(Faraday.default_adapter) # make requests with Net::HTTP
|
@@ -99,7 +89,7 @@ class Tml::Api::Client < Tml::Base
|
|
99
89
|
end
|
100
90
|
|
101
91
|
def cdn_connection
|
102
|
-
@cdn_connection ||= Faraday.new(:url => cdn_host) do |faraday|
|
92
|
+
@cdn_connection ||= Faraday.new(:url => application.cdn_host) do |faraday|
|
103
93
|
faraday.request(:url_encoded) # form-encode POST params
|
104
94
|
faraday.adapter(Faraday.default_adapter) # make requests with Net::HTTP
|
105
95
|
end
|
@@ -109,8 +99,8 @@ class Tml::Api::Client < Tml::Base
|
|
109
99
|
return nil if Tml.cache.version == 'undefined' || Tml.cache.version.to_s == '0'
|
110
100
|
|
111
101
|
response = nil
|
112
|
-
cdn_path = "/#{
|
113
|
-
trace_api_call(cdn_path, params, opts.merge(:host => cdn_host)) do
|
102
|
+
cdn_path = "/#{application.key}/#{Tml.cache.version}/#{key}.json.gz"
|
103
|
+
trace_api_call(cdn_path, params, opts.merge(:host => application.cdn_host)) do
|
114
104
|
begin
|
115
105
|
response = cdn_connection.get do |request|
|
116
106
|
prepare_request(request, cdn_path, params)
|
@@ -138,10 +128,19 @@ class Tml::Api::Client < Tml::Base
|
|
138
128
|
data
|
139
129
|
end
|
140
130
|
|
131
|
+
def enable_cache?(opts)
|
132
|
+
return false unless opts[:method] == :get
|
133
|
+
return false if opts[:cache_key].nil?
|
134
|
+
return false unless Tml.cache.enabled?
|
135
|
+
return false if Tml.session.inline_mode?
|
136
|
+
return false if Tml.session.block_option(:live)
|
137
|
+
true
|
138
|
+
end
|
139
|
+
|
141
140
|
def api(path, params = {}, opts = {})
|
142
141
|
# inline mode should always bypass API calls
|
143
142
|
# get request uses local cache, then CDN, the API
|
144
|
-
if opts
|
143
|
+
if enable_cache?(opts)
|
145
144
|
verify_cache_version
|
146
145
|
data = Tml.cache.fetch(opts[:cache_key]) do
|
147
146
|
if Tml.cache.read_only?
|
@@ -195,18 +194,16 @@ class Tml::Api::Client < Tml::Base
|
|
195
194
|
response = nil
|
196
195
|
error = nil
|
197
196
|
|
198
|
-
token = Tml.config.application ? Tml.config.application[:token] : ''
|
199
|
-
|
200
197
|
# oauth path is separate from versioned APIs
|
201
198
|
path = prepare_api_path(path)
|
202
|
-
params = params.merge(:access_token => token) unless path.index('oauth')
|
199
|
+
params = params.merge(:access_token => application.token) unless path.index('oauth')
|
203
200
|
|
204
201
|
if opts[:method] == :post
|
205
202
|
params = params.merge(:api_key => application.key)
|
206
203
|
end
|
207
204
|
|
208
205
|
@compressed = false
|
209
|
-
trace_api_call(path, params, opts.merge(:host => host)) do
|
206
|
+
trace_api_call(path, params, opts.merge(:host => application.host)) do
|
210
207
|
begin
|
211
208
|
if opts[:method] == :post
|
212
209
|
response = connection.post(path, params)
|
data/lib/tml/application.rb
CHANGED
@@ -33,6 +33,10 @@
|
|
33
33
|
require 'faraday'
|
34
34
|
|
35
35
|
class Tml::Application < Tml::Base
|
36
|
+
|
37
|
+
CDN_HOST = 'https://cdn.translationexchange.com'
|
38
|
+
API_HOST = 'https://api.translationexchange.com'
|
39
|
+
|
36
40
|
attributes :host, :id, :key, :access_token, :name, :description, :threshold, :default_locale, :default_level, :tools
|
37
41
|
has_many :features, :languages, :languages_by_locale, :sources, :tokens, :css, :shortcuts, :translations, :extensions
|
38
42
|
|
@@ -46,6 +50,18 @@ class Tml::Application < Tml::Base
|
|
46
50
|
"#{locale}/translations"
|
47
51
|
end
|
48
52
|
|
53
|
+
def token
|
54
|
+
access_token
|
55
|
+
end
|
56
|
+
|
57
|
+
def host
|
58
|
+
super || API_HOST
|
59
|
+
end
|
60
|
+
|
61
|
+
def cdn_host
|
62
|
+
CDN_HOST
|
63
|
+
end
|
64
|
+
|
49
65
|
# Fetches application definition from the service
|
50
66
|
def fetch
|
51
67
|
data = api_client.get('projects/current/definition',{
|
data/lib/tml/config.rb
CHANGED
data/lib/tml/language.rb
CHANGED
@@ -109,7 +109,7 @@ class Tml::Language < Tml::Base
|
|
109
109
|
end
|
110
110
|
|
111
111
|
def current_source(options)
|
112
|
-
(options[:source] || Tml.session.
|
112
|
+
(options[:source] || Tml.session.block_option(:source) || Tml.session.current_source || 'undefined').to_s
|
113
113
|
end
|
114
114
|
|
115
115
|
#######################################################################################################
|
@@ -137,8 +137,8 @@ class Tml::Language < Tml::Base
|
|
137
137
|
:application => application,
|
138
138
|
:label => params[:label],
|
139
139
|
:description => params[:description],
|
140
|
-
:locale => hash_value(params[:options], :locale) ||
|
141
|
-
:level => hash_value(params[:options], :level) ||
|
140
|
+
:locale => hash_value(params[:options], :locale) || Tml.session.block_option(:locale) || Tml.config.default_locale,
|
141
|
+
:level => hash_value(params[:options], :level) || Tml.session.block_option(:level) || Tml.config.default_level,
|
142
142
|
:translations => []
|
143
143
|
})
|
144
144
|
|
@@ -166,13 +166,13 @@ class Tml::Language < Tml::Base
|
|
166
166
|
current_source_path = source_path
|
167
167
|
|
168
168
|
# Dynamic sources are never registered under the parent source
|
169
|
-
if
|
169
|
+
if Tml.session.block_option(:dynamic)
|
170
170
|
current_source_path = source_key
|
171
171
|
else
|
172
172
|
application.verify_source_path(source_key, current_source_path)
|
173
173
|
end
|
174
174
|
|
175
|
-
# Tml.logger.debug("#{params[:label]}
|
175
|
+
# Tml.logger.debug("#{params[:label]} : #{source_key}")
|
176
176
|
|
177
177
|
source = application.source(source_key, locale)
|
178
178
|
cached_translations = source.cached_translations(locale, translation_key.key)
|
data/lib/tml/session.rb
CHANGED
@@ -41,9 +41,11 @@ module Tml
|
|
41
41
|
attr_accessor :current_user, :current_locale, :current_language, :current_translator, :current_source
|
42
42
|
|
43
43
|
def init(opts = {})
|
44
|
-
return
|
44
|
+
return if Tml.config.disabled?
|
45
45
|
|
46
|
-
|
46
|
+
key = opts[:key] || Tml.config.application[:key]
|
47
|
+
token = opts[:token] || Tml.config.application[:token]
|
48
|
+
host = opts[:host] || Tml.config.application[:host]
|
47
49
|
|
48
50
|
Tml.cache.reset_version
|
49
51
|
|
@@ -52,13 +54,7 @@ module Tml
|
|
52
54
|
self.current_locale = opts[:locale]
|
53
55
|
self.current_translator = opts[:translator]
|
54
56
|
|
55
|
-
self.application = Tml::Application.new(:host => host).fetch
|
56
|
-
|
57
|
-
# if inline mode don't use any app cache
|
58
|
-
# if inline_mode?
|
59
|
-
# self.application = self.application.dup
|
60
|
-
# self.application.reset_translation_cache
|
61
|
-
# end
|
57
|
+
self.application = Tml::Application.new(:key => key, :access_token => token, :host => host).fetch
|
62
58
|
|
63
59
|
if self.current_translator
|
64
60
|
self.current_translator.application = self.application
|
@@ -97,19 +93,13 @@ module Tml
|
|
97
93
|
end
|
98
94
|
|
99
95
|
def source_language
|
100
|
-
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
application.language
|
96
|
+
locale = block_option(:locale)
|
97
|
+
locale ? application.language(locale) : application.language
|
105
98
|
end
|
106
99
|
|
107
100
|
def target_language
|
108
|
-
|
109
|
-
|
110
|
-
end
|
111
|
-
|
112
|
-
current_language
|
101
|
+
target_locale = block_option(:target_locale)
|
102
|
+
target_locale ? application.language(target_locale) : current_language
|
113
103
|
end
|
114
104
|
|
115
105
|
def inline_mode?
|
@@ -120,8 +110,19 @@ module Tml
|
|
120
110
|
## Block Options
|
121
111
|
#########################################################
|
122
112
|
|
113
|
+
def block_option(key, lookup = true)
|
114
|
+
if lookup
|
115
|
+
block_options_queue.reverse.each do |options|
|
116
|
+
value = options[key.to_s] || options[key.to_sym]
|
117
|
+
return value if value
|
118
|
+
end
|
119
|
+
return nil
|
120
|
+
end
|
121
|
+
block_options[key]
|
122
|
+
end
|
123
|
+
|
123
124
|
def push_block_options(opts)
|
124
|
-
|
125
|
+
block_options_queue.push(opts)
|
125
126
|
end
|
126
127
|
|
127
128
|
def pop_block_options
|
@@ -129,12 +130,12 @@ module Tml
|
|
129
130
|
@block_options.pop
|
130
131
|
end
|
131
132
|
|
132
|
-
def
|
133
|
-
|
133
|
+
def block_options_queue
|
134
|
+
@block_options ||= []
|
134
135
|
end
|
135
136
|
|
136
|
-
def
|
137
|
-
|
137
|
+
def block_options
|
138
|
+
block_options_queue.last || {}
|
138
139
|
end
|
139
140
|
|
140
141
|
def with_block_options(opts)
|
@@ -146,13 +147,5 @@ module Tml
|
|
146
147
|
ret
|
147
148
|
end
|
148
149
|
|
149
|
-
def current_source_from_block_options
|
150
|
-
arr = @block_options || []
|
151
|
-
arr.reverse.each do |opts|
|
152
|
-
return application.source_by_key(opts[:source]) unless opts[:source].blank?
|
153
|
-
end
|
154
|
-
nil
|
155
|
-
end
|
156
|
-
|
157
150
|
end
|
158
151
|
end
|
data/lib/tml/tokens/data.rb
CHANGED
@@ -333,7 +333,7 @@ module Tml
|
|
333
333
|
def sanitize(value, object, language, options)
|
334
334
|
value = value.to_s
|
335
335
|
|
336
|
-
unless Tml.session.
|
336
|
+
unless Tml.session.block_option(:skip_html_escaping)
|
337
337
|
if options[:safe] == false
|
338
338
|
value = CGI.escapeHTML(value)
|
339
339
|
end
|
data/lib/tml/translation_key.rb
CHANGED
@@ -41,7 +41,7 @@ class Tml::TranslationKey < Tml::Base
|
|
41
41
|
super
|
42
42
|
|
43
43
|
self.attributes[:key] ||= self.class.generate_key(label, description)
|
44
|
-
self.attributes[:locale] ||= Tml.session.
|
44
|
+
self.attributes[:locale] ||= Tml.session.block_option(:locale) || (application ? application.default_locale : Tml.config.default_locale)
|
45
45
|
self.attributes[:language] ||= application ? application.language(locale) : Tml.config.default_language
|
46
46
|
self.attributes[:translations] = {}
|
47
47
|
|
data/lib/tml/translator.rb
CHANGED
data/lib/tml/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.1.
|
4
|
+
version: 5.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Berkovich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|