discourse/lib/post_localization_updater.rb
Natalie Tay 3f8ccda7aa
FEATURE: Allow post authors to localize their own posts (#36178)
We should allow authors to localize their own content.

This is gated behind the
`content_localization_allow_author_localization` setting, which is
enabled by default.

Meta:
https://meta.discourse.org/t/feature-request-allow-users-to-localize-only-their-own-topics/389147
2025-11-25 11:02:22 +08:00

24 lines
721 B
Ruby
Vendored

# frozen_string_literal: true
class PostLocalizationUpdater
def self.update(post_id:, locale:, raw:, user:)
Guardian.new(user).ensure_can_localize_post!(post_id)
localization = PostLocalization.find_by(post_id: post_id, locale: locale)
raise Discourse::NotFound unless localization
post = localization.post
raise Discourse::NotFound unless post
return localization if localization.raw == raw
localization.raw = raw
localization.cooked = PrettyText.cook(raw)
localization.localizer_user_id = user.id
localization.post_version = post.version
localization.save!
Jobs.enqueue(:process_localized_cooked, post_localization_id: localization.id)
localization
end
end