discourse/app/jobs/regular/process_localized_cooked.rb
Natalie Tay 38e6420016
FEATURE: Also process manually updated translations (#35276)
This is a follow up to
https://github.com/discourse/discourse/pull/34900.

When a user manually updates translation via the translation composer,
also send the new translated cooked for post processing. I moved the
Processor to core, given PostLocalizations are core feature.

<img width="551" height="385" alt="Screenshot 2025-10-08 at 6 12 26 PM"
src="https://github.com/user-attachments/assets/1cce7ce3-5487-4e75-90fd-440792b9a899"
/>
2025-10-09 00:33:36 +08:00

28 lines
912 B
Ruby
Vendored

# frozen_string_literal: true
module Jobs
class ProcessLocalizedCooked < ::Jobs::Base
def execute(args)
DistributedMutex.synchronize(
"process_localized_cook_#{args[:post_localization_id]}",
validity: 10.minutes,
) do
post_localization = PostLocalization.find_by(id: args[:post_localization_id])
return if post_localization.blank?
post = post_localization.post
return if post.blank? || post.topic.blank?
original_cooked = post_localization.cooked
processor = LocalizedCookedPostProcessor.new(post_localization, post, {})
processor.post_process
cooked = processor.html
if cooked != original_cooked && cooked.present?
post_localization.update_column(:cooked, cooked)
MessageBus.publish("/topic/#{post.topic_id}", type: :localized, id: post.id)
end
end
end
end
end