Fix post translation erroring out (v4.1.x) (#26990)
This commit is contained in:
parent
af0ee12908
commit
5d93c5f019
|
@ -46,7 +46,7 @@ class TranslationService::DeepL < TranslationService
|
||||||
|
|
||||||
raise UnexpectedResponseError unless json.is_a?(Hash)
|
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
|
rescue Oj::ParseError
|
||||||
raise UnexpectedResponseError
|
raise UnexpectedResponseError
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,7 +37,7 @@ class TranslationService::LibreTranslate < TranslationService
|
||||||
|
|
||||||
raise UnexpectedResponseError unless json.is_a?(Hash)
|
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
|
rescue Oj::ParseError
|
||||||
raise UnexpectedResponseError
|
raise UnexpectedResponseError
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,8 +12,8 @@ class TranslateStatusService < BaseService
|
||||||
@content = status_content_format(@status)
|
@content = status_content_format(@status)
|
||||||
@target_language = target_language
|
@target_language = target_language
|
||||||
|
|
||||||
Rails.cache.fetch("translations/#{@status.language}/#{@target_language}/#{content_hash}", expires_in: CACHE_TTL) do
|
Rails.cache.fetch("translations:v2/#{@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)
|
translation_backend.translate(@content, @status.language, @target_language)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue