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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 498b874a47bd3849b2b910180113ddbce2bdecaf
4
- data.tar.gz: fc2622bab03ff94006fa2c3a970a05a58834ff68
3
+ metadata.gz: eb36f44885cef5545e9df7361ab089e45bee2b80
4
+ data.tar.gz: b4df90289442d36754e104d8179b11d8a2711e29
5
5
  SHA512:
6
- metadata.gz: b52e523013ea5d167280451c3b0d4b86a27b4a7ddff708ce00f8f9631448b6a3b9614e66ad4849ba70e3aa6eacec69bae7767dddb66677326c724c879f6c623d
7
- data.tar.gz: 5d178901b241444101fd1d705e74a431a9a99db90e2113e2b9e21fe98a6b4a078fbb202e9f629c795140d88d6e00be1c17c99fb2fdc24ce6181e28b3037e7291
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
- update_translations unless assets_request?(env)
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
- send_translations(env)
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module TranslationEngine
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
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
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-01-12 00:00:00.000000000 Z
11
+ date: 2017-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails