translated 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d8e76f6a921836b0f1eaab3a9c216876050d70b2376b936c641863c88aa8979c
4
- data.tar.gz: 6e2cb9f18f06f3d0408812eb42bd57053ccc9b2acc766a2d5f78dd249e503c7f
3
+ metadata.gz: acb8d7e06251f8aae75abe2377bd1f584babc1629c7e94b33b5b7908897e8bbf
4
+ data.tar.gz: c5945645366f4f0877c13170b9c8b3c14cc26c5cc65faaf79fc22d3f3103c06b
5
5
  SHA512:
6
- metadata.gz: f6bc895fb490fac8fe2c23a9bf7e000dde58330909c36a956d288a0b325583d21cf45dc6c7a897f0752a38e904f33486033e22b4f80efc4c7a7d548d4a79479b
7
- data.tar.gz: c4912b58c78943cdf884be2d3bc5a993fdd7b04984adfba97eca41e00a999cf27e40e81e799f793966fe7f5ff8000a0780b1ce40a2c67565e3eeed1f8a9f886e
6
+ metadata.gz: 11da8257b48f70e16e05502677bed0ea41944c660c207c380124bd476c7f863522a5cbb028c9833ea3d71303ddce9f738671b677c7b831d0451073183b2be1a4
7
+ data.tar.gz: 8c13fd3009074808969064a9b130659506cc424629096dac17c7b2c30a018de5c09de7cc1845541fde31206baff2d7531b640e864a51bfb31768ea7918ca8211
@@ -23,6 +23,10 @@ module Translated
23
23
  content
24
24
  end
25
25
 
26
+ def #{name}_changed?
27
+ #{name}_translation_changed? || super
28
+ end
29
+
26
30
  private
27
31
 
28
32
  def #{name}_translation_changed?
@@ -40,7 +44,15 @@ module Translated
40
44
 
41
45
  validates name, validates if validates.present?
42
46
 
43
- scope :with_translations, -> { includes(:translated_text_fields) }
47
+ scope :"with_#{name}_translation", -> { includes(:"#{name}_translation") }
48
+ end
49
+
50
+ def with_translations
51
+ includes(translation_association_names)
52
+ end
53
+
54
+ def translation_association_names
55
+ reflect_on_all_associations(:has_one).map(&:name).select { |n| n.ends_with?('_translation') }
44
56
  end
45
57
 
46
58
  def has_translated_rich_text(name) # rubocop:disable Naming/PredicateName
@@ -5,16 +5,29 @@ require 'rest-client'
5
5
  module Translated
6
6
  class Translator
7
7
  API_HOST = ENV.fetch('TRANSLATED_API_HOST', 'https://translatedrb.com')
8
+ MAX_RETRIES = 3
9
+ RETRY_DELAY = 1 # seconds
8
10
 
9
11
  def translate(text, from:, to:)
10
- response = RestClient.post(
11
- "#{API_HOST}/translate",
12
- { text: text, from: from, to: to }.to_json,
13
- accept: :json,
14
- authorization: "Token token=\"#{api_key}\"",
15
- content_type: :json
16
- )
17
- JSON.parse(response.body)['translated_text']
12
+ retries = 0
13
+ begin
14
+ response = RestClient.post(
15
+ "#{API_HOST}/translate",
16
+ { text: text, from: from, to: to }.to_json,
17
+ accept: :json,
18
+ authorization: "Token token=\"#{api_key}\"",
19
+ content_type: :json
20
+ )
21
+ JSON.parse(response.body)['translated_text']
22
+ rescue RestClient::GatewayTimeout => e
23
+ retries += 1
24
+ if retries <= MAX_RETRIES
25
+ sleep(RETRY_DELAY * retries) # exponential backoff
26
+ retry
27
+ else
28
+ raise e
29
+ end
30
+ end
18
31
  end
19
32
 
20
33
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Translated
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: translated
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trae Robrock
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-10-15 00:00:00.000000000 Z
12
+ date: 2026-01-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activejob