0
0
Fork 0

Fix translations not being formatted, other issues in web UI (#19245)

Fix #19237
This commit is contained in:
Eugen Rochko 2022-09-28 01:02:01 +02:00 committed by GitHub
parent d86dd067ce
commit 55a2e9b5be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View file

@ -3,13 +3,16 @@
class TranslateStatusService < BaseService
CACHE_TTL = 1.day.freeze
include FormattingHelper
def call(status, target_language)
raise Mastodon::NotPermittedError unless status.public_visibility? || status.unlisted_visibility?
@status = status
@content = status_content_format(@status)
@target_language = target_language
Rails.cache.fetch("translations/#{@status.language}/#{@target_language}/#{content_hash}", expires_in: CACHE_TTL) { translation_backend.translate(@status.text, @status.language, @target_language) }
Rails.cache.fetch("translations/#{@status.language}/#{@target_language}/#{content_hash}", expires_in: CACHE_TTL) { translation_backend.translate(@content, @status.language, @target_language) }
end
private
@ -19,6 +22,6 @@ class TranslateStatusService < BaseService
end
def content_hash
Digest::SHA256.base64digest(@status.text)
Digest::SHA256.base64digest(@content)
end
end