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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c5060f0fe015b2284bcb3099e6a9287a5dac0bbc8f0cb8f8172c0d068dcfb714
|
|
4
|
+
data.tar.gz: 25abebd6fff9da4101bf2aca097085b9314c0b217b3de1547b597f2f641e95c9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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 =
|
|
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
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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:,
|