discourse/lib/post_localization_creator.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

24 lines
623 B
Ruby

# frozen_string_literal: true
class PostLocalizationCreator
def self.create(post_id:, locale:, raw:, user:)
Guardian.new(user).ensure_can_localize_content!
post = Post.find_by(id: post_id)
raise Discourse::NotFound unless post
localization =
PostLocalization.create!(
post: post,
locale: locale,
raw: raw,
cooked: post.post_analyzer.cook(raw, post.cooking_options || {}),
post_version: post.version,
localizer_user_id: user.id,
)
Jobs.enqueue(:process_localized_cooked, post_localization_id: localization.id)
localization
end
end