active_translation 0.7.5 → 0.7.7

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: 41efab1065efc26a1d0e04a05ec1be8f0f4b5a9143b0d486c958540f8cb970bc
4
- data.tar.gz: 02b939cc57e481288dd6d691f65c86cb6bacac2eface6866fa3f8f2f91765dda
3
+ metadata.gz: c5060f0fe015b2284bcb3099e6a9287a5dac0bbc8f0cb8f8172c0d068dcfb714
4
+ data.tar.gz: 25abebd6fff9da4101bf2aca097085b9314c0b217b3de1547b597f2f641e95c9
5
5
  SHA512:
6
- metadata.gz: 5b816b22734257d8818fe47035c50793afaf5801de186da7922479803051181d5e58c3859ac2123d916593431c412b0fae9acd24d049aee4534e6cc9b164c576
7
- data.tar.gz: a440a16da19267c58e99ae3f017139465aa2ddec3b6418ce9b61ef023778221c71460932e28631638f30ee2fa3b2519603806f06beabcb58ed4099f354506951
6
+ metadata.gz: be37b5420e08aa497dc213784b4101eb09de9fd645fe14c974dbd0659453251242a55e90ffba89afd6194067edfdf3c3a344294b20a63be7fda7a0deb1ad18b4
7
+ data.tar.gz: e9afd718cec5a0a67035c8e6656579e57993caf67ff6e8b39254e6f9b3301c31c894ffeb41e16375b8dd30554cd30063f8d74f37ad200747feecdb3308ba8618
@@ -6,6 +6,8 @@ module ActiveTranslation
6
6
  class GoogleTranslate
7
7
  class << self
8
8
  def translate(target_language_code:, text:, source: "en-US", obj: nil)
9
+ return "[#{target_language_code}] #{text}" if Rails.env.test?
10
+
9
11
  conn = Faraday.new(url: "https://translation.googleapis.com/") do |faraday|
10
12
  faraday.request :json
11
13
  faraday.response :json
@@ -166,28 +166,16 @@ module ActiveTranslation
166
166
  locale: locale,
167
167
  )
168
168
 
169
- translated_text = if Rails.env.test?
170
- cached_translation&.translated_text || "[#{locale}] #{send(attribute)}"
171
- else
172
- cached_translation&.translated_text || ActiveTranslation::GoogleTranslate.translate(target_language_code: locale, text: text)
173
- end
174
-
175
- case translation_config[:cache]
176
- when TrueClass
177
- ActiveTranslation::Cache.find_or_create_by(
178
- checksum: text_checksum(send(attribute)),
179
- locale:,
180
- ).update(translated_text:,)
181
- when String, Symbol
182
- return unless attribute.to_s == translation_config[:cache].to_s
169
+ translated_text = cached_translation&.translated_text || ActiveTranslation::GoogleTranslate.translate(target_language_code: locale, text: send(attribute))
183
170
 
184
- ActiveTranslation::Cache.find_or_create_by(
185
- checksum: text_checksum(send(attribute)),
186
- locale:,
187
- ).update(translated_text:,)
188
- when Array
189
- return unless translation_config[:cache].map(&:to_s).include? attribute.to_s
171
+ should_cache = case translation_config[:cache]
172
+ when TrueClass then true
173
+ when String, Symbol then attribute.to_s == translation_config[:cache].to_s
174
+ when Array then translation_config[:cache].map(&:to_s).include?(attribute.to_s)
175
+ else false
176
+ end
190
177
 
178
+ if should_cache
191
179
  ActiveTranslation::Cache.find_or_create_by(
192
180
  checksum: text_checksum(send(attribute)),
193
181
  locale:,
@@ -1,3 +1,3 @@
1
1
  module ActiveTranslation
2
- VERSION = "0.7.5"
2
+ VERSION = "0.7.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_translation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.5
4
+ version: 0.7.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Talentronic