translation_engine 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/middlewares/translation_engine/catcher_middleware.rb +12 -2
- data/app/models/translation_engine/backend.rb +2 -2
- data/app/models/translation_engine/connection.rb +1 -1
- data/app/models/translation_engine/downloader.rb +4 -2
- data/config/initializers/translation_engine.rb +2 -0
- data/lib/translation_engine.rb +2 -1
- data/lib/translation_engine/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: eb36f44885cef5545e9df7361ab089e45bee2b80
|
4
|
+
data.tar.gz: b4df90289442d36754e104d8179b11d8a2711e29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ac92beba66ec7ac5e2ce84286d850e37d3264134d0c0ab97779b839c0d434f81d19f0a3970821d5f50edbab75b6f7f11b0d8ed7d8070d4a7a64931dbfc73f98
|
7
|
+
data.tar.gz: 41e21bdad0790d639ffec1878c01ead3467e86cda7c59de4a4bb0d0b7238a3006ccad36cfb49a1c43f8f8f827a03d4063eda2fbaf3cc4d34995e7c15a97a36d9
|
@@ -26,11 +26,21 @@ module TranslationEngine
|
|
26
26
|
I18n.backend.release = params(env)['translation_release']
|
27
27
|
end
|
28
28
|
|
29
|
-
|
29
|
+
begin
|
30
|
+
update_translations unless assets_request?(env)
|
31
|
+
rescue StandardError => e
|
32
|
+
puts "Unable to update translations #{e.class} #{e.message}"
|
33
|
+
end
|
30
34
|
|
31
35
|
response = @app.call(env)
|
32
36
|
|
33
|
-
|
37
|
+
unless TranslationEngine.disable_sending_translations
|
38
|
+
begin
|
39
|
+
send_translations(env)
|
40
|
+
rescue StandardError => e
|
41
|
+
puts "Unable to send new translations #{e.class} #{e.message}"
|
42
|
+
end
|
43
|
+
end
|
34
44
|
|
35
45
|
response
|
36
46
|
end
|
@@ -33,7 +33,7 @@ class TranslationEngine::Backend < I18n::Backend::Simple
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def download_master
|
36
|
-
if (yml_data = connection.get_translations.body)
|
36
|
+
if (yml_data = connection.get_translations.try(:body))
|
37
37
|
Rails.logger.info { 'Updating from translation server - master' }
|
38
38
|
YAML.load(yml_data).each do |locale, translations|
|
39
39
|
store_translations locale, translations
|
@@ -42,7 +42,7 @@ class TranslationEngine::Backend < I18n::Backend::Simple
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def download_release
|
45
|
-
if (yml_data = connection.get_release(release).body)
|
45
|
+
if (yml_data = connection.get_release(release).try(:body))
|
46
46
|
Rails.logger.info { "Updating from translation server - #{release}" }
|
47
47
|
YAML.load(yml_data).each do |locale, translations|
|
48
48
|
store_translations locale, translations
|
@@ -5,7 +5,7 @@ class TranslationEngine::Connection
|
|
5
5
|
NotFound = Class.new(Exception)
|
6
6
|
|
7
7
|
def send_images(data, ip_address = nil)
|
8
|
-
connection.post do |req|
|
8
|
+
connection(60).post do |req|
|
9
9
|
req.url '/api/v1/images'
|
10
10
|
req.headers['Content-Type'] = 'application/json'
|
11
11
|
req.headers['Authorization'] = api_token
|
@@ -6,10 +6,12 @@ class TranslationEngine::Downloader
|
|
6
6
|
response = @current_etag == etag
|
7
7
|
Rails.logger.info { "Translations are up to date" } if response
|
8
8
|
@current_etag = etag
|
9
|
+
@cache_timeout = Time.now + TranslationEngine.cache_timeout
|
9
10
|
response
|
10
11
|
end
|
11
12
|
|
12
13
|
def update
|
14
|
+
return nil if @cache_timeout && Time.now < @cache_timeout
|
13
15
|
return nil if self.class.etag?(connection.get_translations_head[:etag])
|
14
16
|
I18n.backend.reload!
|
15
17
|
end
|
@@ -26,7 +28,7 @@ class TranslationEngine::Downloader
|
|
26
28
|
def store_release(release)
|
27
29
|
locale = release.split('_')[0...-1].join('_')
|
28
30
|
filename = releases_dir.join("#{locale.downcase}.yml")
|
29
|
-
if (yml_data = connection.get_release(release).body)
|
31
|
+
if (yml_data = connection.get_release(release).try(:body))
|
30
32
|
Rails.logger.info { "Storing release #{release} to #{filename}" }
|
31
33
|
write(filename, yml_data)
|
32
34
|
end
|
@@ -55,7 +57,7 @@ class TranslationEngine::Downloader
|
|
55
57
|
def receive_translations
|
56
58
|
return if self.class.etag?(connection.get_translations_head[:etag])
|
57
59
|
|
58
|
-
connection.get_translations.body
|
60
|
+
connection.get_translations.try(:body)
|
59
61
|
end
|
60
62
|
|
61
63
|
def releases_dir
|
@@ -3,6 +3,8 @@ TranslationEngine.config do |config|
|
|
3
3
|
config.api_host = 'http://127.0.0.1:3000'
|
4
4
|
config.use_screenshots = false
|
5
5
|
config.use_catcher = false
|
6
|
+
config.disable_sending_translations = false
|
6
7
|
config.timeout = 5
|
8
|
+
config.cache_timeout = 0
|
7
9
|
config.raise_exceptions = Rails.env.development?
|
8
10
|
end
|
data/lib/translation_engine.rb
CHANGED
@@ -2,7 +2,8 @@ require "translation_engine/engine"
|
|
2
2
|
|
3
3
|
module TranslationEngine
|
4
4
|
mattr_accessor :api_key, :api_host, :timeout,
|
5
|
-
:use_screenshots, :use_catcher, :raise_exceptions
|
5
|
+
:use_screenshots, :use_catcher, :raise_exceptions,
|
6
|
+
:disable_sending_translations, :cache_timeout
|
6
7
|
|
7
8
|
def self.config
|
8
9
|
yield self
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: translation_engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ondrej Bartas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|