mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-21 14:20:13 +08:00
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
24 lines
626 B
Ruby
Vendored
24 lines
626 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
class PostLocalizationCreator
|
|
def self.create(post_id:, locale:, raw:, user:)
|
|
post = Post.find_by(id: post_id)
|
|
|
|
Guardian.new(user).ensure_can_localize_post!(post)
|
|
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
|