phrase-ota-i18n 1.0.0 → 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: 2f9c7981adbdad2b7ccda60036861f500c4855dc3793cb536d3282845af6197e
4
- data.tar.gz: 7a41b105cf56b98f410faefd85b938a83988f7d0d82e79e7fd8d374bea52aabc
3
+ metadata.gz: 74730e59204a8113cb5da49b36771f19175d6aabb7cbea47559d20b9a053057f
4
+ data.tar.gz: f184f39f57cfc7c3aa0ee887002ebfb5f0c3fe11471335f8f0db08eb9d9271dd
5
5
  SHA512:
6
- metadata.gz: c622e6fbf7ed2b806ed4d6466ba6e48c0917e1c184dfcd39e7af0d01aee6fa02a02947f0c4873f8da394d72a0a2e36c76164e335f79317469da834c98a263e2c
7
- data.tar.gz: 4c14fe8da857858018ff49d457657d361224d3c42af94578b1caed6090357f452ce774081a87241436daf3c66de153a2f610103cf33cbca1971e50c836cd8263
6
+ metadata.gz: aec2397a8b9f46f0b3442356d4ff8f38d069963d5d452fc7d127b6deee92060a2412864a15f493634e940715b46f632ce23bd497b6103a3bff2fb0f9780300ec
7
+ data.tar.gz: 7264e91c3e4e29f8977fa7fcaec188d08a27558bc630ec4c92c8743a83d51da5a586251f483feff64f9ed17ca3d25e65338e32f8c250d60226d4d193ea68cce7
@@ -9,6 +9,7 @@ jobs:
9
9
  runs-on: ubuntu-latest
10
10
  steps:
11
11
  - uses: GoogleCloudPlatform/release-please-action@ca6063f4ed81b55db15b8c42d1b6f7925866342d # pin@3.7.11
12
+ id: release
12
13
  with:
13
14
  release-type: ruby
14
15
  package-name: phrase-ota-i18n
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ fix: true
2
+ parallel: true
3
+ format: progress
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
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
+
11
+ ## [1.0.1](https://github.com/phrase/phrase-ota-i18n/compare/v1.0.0...v1.0.1) (2023-09-04)
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * translations are kept on backend init ([1ac31cc](https://github.com/phrase/phrase-ota-i18n/commit/1ac31cc4cb7cfc6f6ce186a80dd26a19a8bdc844))
17
+
3
18
  ## 1.0.0 (2023-08-07)
4
19
 
5
20
 
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,8 @@ 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
+ @initialized = true # initializing immeditaly as we don't want to wait until all OTA translations have been fetched
10
11
  start_polling
11
12
  end
12
13
 
@@ -15,8 +16,6 @@ module Phrase
15
16
  end
16
17
 
17
18
  def init_translations
18
- @translations = {}
19
- @initialized = true
20
19
  end
21
20
 
22
21
  protected
@@ -24,44 +23,52 @@ module Phrase
24
23
  def start_polling
25
24
  Thread.new do
26
25
  loop do
27
- sleep(Phrase::Ota.config.poll_interval_seconds)
26
+ sleep(Phrase::Ota.config.poll_interval)
28
27
  update_translations
29
28
  end
30
29
  end
31
30
  end
32
31
 
33
32
  def update_translations
34
- log("Phrase: Updating translations...")
33
+ log("Updating translations for locales: #{available_locales}")
35
34
 
36
35
  available_locales.each do |locale|
37
- url = "#{Phrase::Ota.config.base_url}/#{Phrase::Ota.config.distribution_id}/#{Phrase::Ota.config.secret_token}/#{locale}/yml"
38
36
  params = {
39
37
  app_version: Phrase::Ota.config.app_version,
40
38
  client: "ruby",
41
39
  sdk_version: Phrase::Ota::VERSION
42
40
  }
43
- 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?
44
43
 
45
44
  connection = Faraday.new do |faraday|
46
45
  faraday.use FaradayMiddleware::FollowRedirects
47
46
  faraday.adapter Faraday.default_adapter
48
47
  end
49
48
 
50
- 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}")
51
53
 
52
- 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}"})
53
55
  next unless response.status == 200
54
56
 
55
- @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
56
58
  yaml = YAML.safe_load(response.body)
57
59
  yaml.each do |yaml_locale, tree|
58
- store_translations(yaml_locale, tree || {})
60
+ store_translations(locale, tree || {})
61
+ log("Updated locale: #{locale}")
59
62
  end
60
63
  end
61
64
  end
62
65
 
66
+ def locale_cache_key(locale)
67
+ "#{Phrase::Ota.config.distribution_id}/#{Phrase::Ota.config.secret_token}/#{locale}"
68
+ end
69
+
63
70
  def log(message)
64
- 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
65
72
  end
66
73
  end
67
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.0"
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.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phrase
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-08 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
@@ -86,7 +87,7 @@ licenses:
86
87
  - MIT
87
88
  metadata:
88
89
  homepage_uri: https://github.com/phrase/phrase-ota-i18n
89
- post_install_message:
90
+ post_install_message:
90
91
  rdoc_options: []
91
92
  require_paths:
92
93
  - lib
@@ -102,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
103
  version: '0'
103
104
  requirements: []
104
105
  rubygems_version: 3.4.10
105
- signing_key:
106
+ signing_key:
106
107
  specification_version: 4
107
108
  summary: Phrase OTA for Rails i18n
108
109
  test_files: []