discourse/plugins/discourse-ai/lib/translation/entry_point.rb
Natalie Tay b7d7f99c04
FEATURE: Allow re-localization twice a day if post version has changed (#34023)
This commit is a continuation of
https://github.com/discourse/discourse-ai/pull/1422.

Previously, we entirely skipped / disallowed localization. With this PR,
- For topics, we will only enqueue the translate title job if the post
revisor indicates there is a title change
- For posts, we will only enqueue the translate post job if there is a
post version change

Both jobs will be enqueued with a delay of
`SiteSetting.editing_grace_period` or `5 minutes`, whichever is larger.
Each topic or post may be retranslated to a locale at a maximum of twice
a day.
2025-08-04 10:58:30 +08:00

37 lines
1.1 KiB
Ruby
Vendored

# frozen_string_literal: true
module DiscourseAi
module Translation
class EntryPoint
def inject_into(plugin)
plugin.on(:post_created) do |post|
if DiscourseAi::Translation.enabled?
Jobs.enqueue(:detect_translate_post, post_id: post.id)
end
end
plugin.on(:topic_created) do |topic|
if DiscourseAi::Translation.enabled?
Jobs.enqueue(:detect_translate_topic, topic_id: topic.id)
end
end
plugin.on(:post_edited) do |post, topic_changed, revisor|
if DiscourseAi::Translation.enabled?
grace = [SiteSetting.editing_grace_period.seconds, 5.minutes].max
if topic_changed
if revisor.topic_title_changed?
Jobs.enqueue_in(grace, :detect_translate_topic, topic_id: post.topic_id)
end
else
if revisor.should_create_new_version?
Jobs.enqueue_in(grace, :detect_translate_post, post_id: post.id)
end
end
end
end
end
end
end
end