phrase-ota-i18n 1.0.1 → 1.0.2

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
  SHA256:
3
- metadata.gz: 348aeb752b1b54dd06a06363a1c81235dc799c8f59e1ad735cf85b43dd888f2a
4
- data.tar.gz: de25387546ec36b726e660591cf421a7d994144a9d4e4032a6fa8f555a9e92d5
3
+ metadata.gz: 74730e59204a8113cb5da49b36771f19175d6aabb7cbea47559d20b9a053057f
4
+ data.tar.gz: f184f39f57cfc7c3aa0ee887002ebfb5f0c3fe11471335f8f0db08eb9d9271dd
5
5
  SHA512:
6
- metadata.gz: 5bdcf6a5086b6dc0dba354960e451dd60fbcfdf2caac61370d13abab2ff4ccded7fa77a887ce030c0a6f566ac3cfbf20b093f27556a2e123fdb6fe037b400b56
7
- data.tar.gz: 24ed5ce4b7c8e3dd619ebb47c10063754b66dc9f92986ea784e7c235f1bb0bbd55be7d4671e2fd5505a0f72288641bcf6b7ccf5f1d1c7b1689c5ac05c7f9a789
6
+ metadata.gz: aec2397a8b9f46f0b3442356d4ff8f38d069963d5d452fc7d127b6deee92060a2412864a15f493634e940715b46f632ce23bd497b6103a3bff2fb0f9780300ec
7
+ data.tar.gz: 7264e91c3e4e29f8977fa7fcaec188d08a27558bc630ec4c92c8743a83d51da5a586251f483feff64f9ed17ca3d25e65338e32f8c250d60226d4d193ea68cce7
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ fix: true
2
+ parallel: true
3
+ format: progress
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.2](https://github.com/phrase/phrase-ota-i18n/compare/v1.0.1...v1.0.2) (2023-09-07)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * store current_version per locale ([3d23407](https://github.com/phrase/phrase-ota-i18n/commit/3d234072a8631577280fee280b93abb3e1cd2e2b))
9
+ * use unique cache key per distribution and locale ([ea25cd5](https://github.com/phrase/phrase-ota-i18n/commit/ea25cd5172c41bdaccef57a0f0a66a3a39790b11))
10
+
3
11
  ## [1.0.1](https://github.com/phrase/phrase-ota-i18n/compare/v1.0.0...v1.0.1) (2023-09-04)
4
12
 
5
13
 
data/README.md CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
22
22
 
23
23
  Generate config:
24
24
 
25
- bundle exec rails generate phrase_ota_rails:install --distribution-id <DISTRIBUTION_ID> --secret-token <SECRET>
25
+ bundle exec rails generate phrase_ota:install --distribution-id <DISTRIBUTION_ID> --secret-token <SECRET>
26
26
 
27
27
 
28
28
  ## Development
@@ -6,7 +6,7 @@ module Phrase
6
6
  module Ota
7
7
  class Backend < I18n::Backend::Simple
8
8
  def initialize
9
- @current_version = nil
9
+ @current_locale_versions = {}
10
10
  @initialized = true # initializing immeditaly as we don't want to wait until all OTA translations have been fetched
11
11
  start_polling
12
12
  end
@@ -23,44 +23,52 @@ module Phrase
23
23
  def start_polling
24
24
  Thread.new do
25
25
  loop do
26
- sleep(Phrase::Ota.config.poll_interval_seconds)
26
+ sleep(Phrase::Ota.config.poll_interval)
27
27
  update_translations
28
28
  end
29
29
  end
30
30
  end
31
31
 
32
32
  def update_translations
33
- log("Phrase: Updating translations...")
33
+ log("Updating translations for locales: #{available_locales}")
34
34
 
35
35
  available_locales.each do |locale|
36
- url = "#{Phrase::Ota.config.base_url}/#{Phrase::Ota.config.distribution_id}/#{Phrase::Ota.config.secret_token}/#{locale}/yml"
37
36
  params = {
38
37
  app_version: Phrase::Ota.config.app_version,
39
38
  client: "ruby",
40
39
  sdk_version: Phrase::Ota::VERSION
41
40
  }
42
- params[:current_version] = @current_version unless @current_version.nil?
41
+ current_version = @current_locale_versions[locale_cache_key(locale)]
42
+ params[:current_version] = current_version unless current_version.nil?
43
43
 
44
44
  connection = Faraday.new do |faraday|
45
45
  faraday.use FaradayMiddleware::FollowRedirects
46
46
  faraday.adapter Faraday.default_adapter
47
47
  end
48
48
 
49
- log("Phrase: Fetching URL: #{url}")
49
+ uri = URI("#{Phrase::Ota.config.base_url}/#{Phrase::Ota.config.distribution_id}/#{Phrase::Ota.config.secret_token}/#{locale}/yml")
50
+ uri.query = URI.encode_www_form(params)
51
+ url = uri.to_s
52
+ log("Request URL: #{url}")
50
53
 
51
- response = connection.get(url, params, {"User-Agent" => "phrase-ota-i18n #{Phrase::Ota::VERSION}"})
54
+ response = connection.get(url, {}, {"User-Agent" => "phrase-ota-i18n #{Phrase::Ota::VERSION}"})
52
55
  next unless response.status == 200
53
56
 
54
- @current_version = CGI.parse(URI(response.env.url).query)["version"].first.to_i
57
+ @current_locale_versions[locale_cache_key(locale)] = CGI.parse(URI(response.env.url).query)["version"].first.to_i
55
58
  yaml = YAML.safe_load(response.body)
56
59
  yaml.each do |yaml_locale, tree|
57
- store_translations(yaml_locale, tree || {})
60
+ store_translations(locale, tree || {})
61
+ log("Updated locale: #{locale}")
58
62
  end
59
63
  end
60
64
  end
61
65
 
66
+ def locale_cache_key(locale)
67
+ "#{Phrase::Ota.config.distribution_id}/#{Phrase::Ota.config.secret_token}/#{locale}"
68
+ end
69
+
62
70
  def log(message)
63
- Phrase::Ota.config.logger.info(message) if Phrase::Ota.config.debug
71
+ Phrase::Ota.config.logger.info("Phrase OTA: #{message}") if Phrase::Ota.config.debug
64
72
  end
65
73
  end
66
74
  end
@@ -9,7 +9,7 @@ module Phrase
9
9
  attr_accessor :secret_token
10
10
  attr_accessor :logger
11
11
  attr_accessor :app_version
12
- attr_accessor :poll_interval_seconds
12
+ attr_accessor :poll_interval
13
13
  attr_accessor :datacenter
14
14
  attr_accessor :available_locales
15
15
  attr_accessor :debug
@@ -20,7 +20,7 @@ module Phrase
20
20
  @secret_token = nil
21
21
  @logger = Logger.new($stdout)
22
22
  @app_version = nil
23
- @poll_interval_seconds = 60
23
+ @poll_interval = 60
24
24
  @datacenter = "eu"
25
25
  @available_locales = []
26
26
  @base_url = nil
@@ -1,5 +1,5 @@
1
1
  module Phrase
2
2
  module Ota
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phrase-ota-i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phrase
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-04 00:00:00.000000000 Z
11
+ date: 2023-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -65,6 +65,7 @@ files:
65
65
  - ".github/workflows/test.yml"
66
66
  - ".gitignore"
67
67
  - ".rspec"
68
+ - ".standard.yml"
68
69
  - ".tool-versions"
69
70
  - CHANGELOG.md
70
71
  - Gemfile