summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2023-09-20 15:59:53 +0200
committerGitHub <noreply@github.com>2023-09-20 15:59:53 +0200
commit481e1d4e0e59ddda8da781a16fcffe25aa4f3cda (patch)
tree2cf8d2460827a785eb285268e57c8629cbb80e87
parent3d8ae6ab739ab1222546923c8df703260285fbc3 (diff)
Fix post translation erroring out (v4.0.x) (#26991)
-rw-r--r--app/lib/translation_service/deepl.rb2
-rw-r--r--app/lib/translation_service/libre_translate.rb2
-rw-r--r--app/services/translate_status_service.rb4
3 files changed, 4 insertions, 4 deletions
diff --git a/app/lib/translation_service/deepl.rb b/app/lib/translation_service/deepl.rb
index 537fd24c089..2b4746a4d03 100644
--- a/app/lib/translation_service/deepl.rb
+++ b/app/lib/translation_service/deepl.rb
@@ -46,7 +46,7 @@ class TranslationService::DeepL < TranslationService
raise UnexpectedResponseError unless json.is_a?(Hash)
- Translation.new(text: json.dig('translations', 0, 'text'), detected_source_language: json.dig('translations', 0, 'detected_source_language')&.downcase, provider: 'DeepL.com')
+ Translation.new(text: Sanitize.fragment(json.dig('translations', 0, 'text'), Sanitize::Config::MASTODON_STRICT), detected_source_language: json.dig('translations', 0, 'detected_source_language')&.downcase, provider: 'DeepL.com')
rescue Oj::ParseError
raise UnexpectedResponseError
end
diff --git a/app/lib/translation_service/libre_translate.rb b/app/lib/translation_service/libre_translate.rb
index 43576e30627..ee668d298e0 100644
--- a/app/lib/translation_service/libre_translate.rb
+++ b/app/lib/translation_service/libre_translate.rb
@@ -37,7 +37,7 @@ class TranslationService::LibreTranslate < TranslationService
raise UnexpectedResponseError unless json.is_a?(Hash)
- Translation.new(text: json['translatedText'], detected_source_language: source_language, provider: 'LibreTranslate')
+ Translation.new(text: Sanitize.fragment(json['translatedText'], Sanitize::Config::MASTODON_STRICT), detected_source_language: source_language, provider: 'LibreTranslate')
rescue Oj::ParseError
raise UnexpectedResponseError
end
diff --git a/app/services/translate_status_service.rb b/app/services/translate_status_service.rb
index b905f8158ad..6e6ed87b0a3 100644
--- a/app/services/translate_status_service.rb
+++ b/app/services/translate_status_service.rb
@@ -12,8 +12,8 @@ class TranslateStatusService < BaseService
@content = status_content_format(@status)
@target_language = target_language
- Rails.cache.fetch("translations/#{@status.language}/#{@target_language}/#{content_hash}", expires_in: CACHE_TTL) do
- Sanitize.fragment(translation_backend.translate(@content, @status.language, @target_language), Sanitize::Config::MASTODON_STRICT)
+ Rails.cache.fetch("translations:v2/#{@status.language}/#{@target_language}/#{content_hash}", expires_in: CACHE_TTL) do
+ translation_backend.translate(@content, @status.language, @target_language)
end
end