tr8n_core 4.0.10 → 4.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tr8n/api_client.rb +13 -4
- data/lib/tr8n/application.rb +34 -23
- data/lib/tr8n/cache.rb +13 -2
- data/lib/tr8n/config.rb +4 -0
- data/lib/tr8n/language.rb +2 -0
- data/lib/tr8n_core/languages/en-US.json +1 -0
- data/lib/tr8n_core/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: a984c2942575807bbf4d7e6b3b340ce2c2428020
|
4
|
+
data.tar.gz: 5cd3e83a8c544fb42a390a9218b1350f4ba66d01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 936c126d175de897ac02f4635c6052db44f4314ec3ed745d4e2a150b5ecc99514f1f64e54d8e58735a85f3dbc5a4a290fd9e3d4162923b67c3a36cf38a77435d
|
7
|
+
data.tar.gz: 91c3092764f4a26a38d9a0b731daac3b1fe686b257a3b53d62889b7c735d6fa47edb771b134a755fcfc6e9d1490caeb8ff16604886eaee55e9adca95b64d9815
|
data/lib/tr8n/api_client.rb
CHANGED
@@ -91,13 +91,22 @@ class Tr8n::ApiClient < Tr8n::Base
|
|
91
91
|
|
92
92
|
def execute_request(path, params = {}, opts = {})
|
93
93
|
response = nil
|
94
|
+
error = nil
|
94
95
|
Tr8n.logger.trace_api_call(path, params) do
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
96
|
+
begin
|
97
|
+
if opts[:method] == :post
|
98
|
+
response = connection.post("#{API_PATH}#{path}", params)
|
99
|
+
else
|
100
|
+
response = connection.get("#{API_PATH}#{path}", params)
|
101
|
+
end
|
102
|
+
rescue Faraday::ConnectionFailed => ex
|
103
|
+
Tr8n.logger.error("Failed to execute request: #{ex}")
|
104
|
+
error = ex
|
105
|
+
nil
|
99
106
|
end
|
100
107
|
end
|
108
|
+
raise Tr8n::Exception.new("Error: #{error}") if error
|
109
|
+
|
101
110
|
data = JSON.parse(response.body)
|
102
111
|
raise Tr8n::Exception.new("Error: #{data["error"]}") unless data["error"].nil?
|
103
112
|
data
|
data/lib/tr8n/application.rb
CHANGED
@@ -38,6 +38,9 @@ class Tr8n::Application < Tr8n::Base
|
|
38
38
|
|
39
39
|
def fetch
|
40
40
|
update_attributes(api_client.get("application", {:definition => true}, {:cache_key => key}))
|
41
|
+
rescue Tr8n::Exception => ex
|
42
|
+
Tr8n.logger.error("Failed to load application: #{ex}")
|
43
|
+
self
|
41
44
|
end
|
42
45
|
|
43
46
|
def update_attributes(attrs)
|
@@ -73,8 +76,24 @@ class Tr8n::Application < Tr8n::Base
|
|
73
76
|
def language(locale = nil)
|
74
77
|
locale ||= default_locale || Tr8n.config.default_locale
|
75
78
|
@languages_by_locale ||= {}
|
76
|
-
|
77
|
-
|
79
|
+
|
80
|
+
unless Tr8n.session.current_translator and Tr8n.session.current_translator.inline?
|
81
|
+
cache_key = "#{locale}/language"
|
82
|
+
end
|
83
|
+
|
84
|
+
@languages_by_locale[locale] ||= api_client.get(
|
85
|
+
'language',
|
86
|
+
{:locale => locale},
|
87
|
+
{
|
88
|
+
:class => Tr8n::Language,
|
89
|
+
:attributes => {:locale => locale, :application => self},
|
90
|
+
:cache_key => cache_key
|
91
|
+
}
|
92
|
+
)
|
93
|
+
rescue Tr8n::Exception => e
|
94
|
+
Tr8n.logger.error(e)
|
95
|
+
Tr8n.logger.error(e.backtrace)
|
96
|
+
@languages_by_locale[locale] = Tr8n.config.default_language
|
78
97
|
end
|
79
98
|
|
80
99
|
# Mostly used for testing
|
@@ -103,19 +122,17 @@ class Tr8n::Application < Tr8n::Base
|
|
103
122
|
cache_key = Tr8n::Source.cache_key(key, locale)
|
104
123
|
end
|
105
124
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
@sources_by_key[key] ||= Tr8n::Source.new(:source => key)
|
118
|
-
end
|
125
|
+
@sources_by_key[key] ||= api_client.get(
|
126
|
+
"source",
|
127
|
+
{:source => key, :locale => locale, :translations => true},
|
128
|
+
{
|
129
|
+
:class => Tr8n::Source,
|
130
|
+
:attributes => {:application => self},
|
131
|
+
:cache_key => cache_key
|
132
|
+
}
|
133
|
+
)
|
134
|
+
rescue
|
135
|
+
@sources_by_key[key] = Tr8n::Source.new(:source => key)
|
119
136
|
end
|
120
137
|
|
121
138
|
def component(key, register = true)
|
@@ -187,16 +204,14 @@ class Tr8n::Application < Tr8n::Base
|
|
187
204
|
|
188
205
|
def featured_languages
|
189
206
|
@featured_languages ||= begin
|
190
|
-
locales =
|
191
|
-
api_client.get("application/featured_locales")
|
192
|
-
end
|
207
|
+
locales = api_client.get("application/featured_locales", {}, {:cache_key => "featured_locales"})
|
193
208
|
# use app languages, there is no need for rules for this call
|
194
209
|
(locales.nil? or locales.empty?) ? [] : languages.select{|l| locales.include?(l.locale)}
|
195
210
|
end
|
196
211
|
end
|
197
212
|
|
198
213
|
def translators
|
199
|
-
api_client.get("application/translators", {}, {:class => Tr8n::Translator, :attributes => {:application => self}})
|
214
|
+
@translators ||= api_client.get("application/translators", {}, {:class => Tr8n::Translator, :attributes => {:application => self}})
|
200
215
|
end
|
201
216
|
|
202
217
|
def default_decoration_token(token)
|
@@ -207,10 +222,6 @@ class Tr8n::Application < Tr8n::Base
|
|
207
222
|
hash_value(tokens, "data.#{token.to_s}")
|
208
223
|
end
|
209
224
|
|
210
|
-
def js_boot_url
|
211
|
-
"#{host}/tr8n/api/proxy/boot.js?client_id=#{key}"
|
212
|
-
end
|
213
|
-
|
214
225
|
def feature_enabled?(key)
|
215
226
|
hash_value(features, key.to_s)
|
216
227
|
end
|
data/lib/tr8n/cache.rb
CHANGED
@@ -36,7 +36,7 @@ module Tr8n
|
|
36
36
|
|
37
37
|
def self.cache
|
38
38
|
@cache ||= begin
|
39
|
-
if Tr8n.config.
|
39
|
+
if Tr8n.config.cache_enabled?
|
40
40
|
klass = Tr8n::CacheAdapters.const_get(Tr8n.config.cache[:adapter].camelcase)
|
41
41
|
klass.new
|
42
42
|
else
|
@@ -55,10 +55,21 @@ module Tr8n
|
|
55
55
|
end
|
56
56
|
v['version']
|
57
57
|
end
|
58
|
+
|
59
|
+
if Tr8n.config.cache[:version] > @version
|
60
|
+
update_version(Tr8n.config.cache[:version])
|
61
|
+
@version = Tr8n.config.cache[:version]
|
62
|
+
end
|
63
|
+
|
64
|
+
@version
|
65
|
+
end
|
66
|
+
|
67
|
+
def update_version(new_version)
|
68
|
+
store(CACHE_VERSION_KEY, {'version' => new_version}, :ttl => 0)
|
58
69
|
end
|
59
70
|
|
60
71
|
def upgrade_version
|
61
|
-
|
72
|
+
update_version(version + 1)
|
62
73
|
@version = nil
|
63
74
|
end
|
64
75
|
|
data/lib/tr8n/config.rb
CHANGED
@@ -314,6 +314,10 @@ module Tr8n
|
|
314
314
|
nested_value(self.translator_options, key)
|
315
315
|
end
|
316
316
|
|
317
|
+
def cache_enabled?
|
318
|
+
cache[:enabled].nil? || Tr8n.config.cache[:enabled]
|
319
|
+
end
|
320
|
+
|
317
321
|
#########################################################
|
318
322
|
## Application
|
319
323
|
#########################################################
|
data/lib/tr8n/language.rb
CHANGED
@@ -37,6 +37,8 @@ class Tr8n::Language < Tr8n::Base
|
|
37
37
|
|
38
38
|
def fetch
|
39
39
|
update_attributes(application.api_client.get("language", {:locale => locale}, {:cache_key => "#{locale}/language"}))
|
40
|
+
rescue Tr8n::Exception => ex
|
41
|
+
Tr8n.logger.error("Failed to load language: #{ex}")
|
40
42
|
self
|
41
43
|
end
|
42
44
|
|
data/lib/tr8n_core/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tr8n_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Berkovich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|