mirror of
https://ghfast.top/https://github.com/discourse/discourse-translator.git
synced 2026-07-17 11:56:50 +08:00
Doing some cleanup - `experimental_topic_translation` becomes `experimental_inline_translation` - `translator` becomes `translator_provider` - DualText translation is now Parallel Translation (the feature where translation is appended to the post, rather than shown inline) - Unused `translate_posts_to_languages` removed
25 lines
1,000 B
Ruby
25 lines
1,000 B
Ruby
# frozen_string_literal: true
|
|
|
|
module DiscourseTranslator
|
|
class ParallelTextTranslation
|
|
def inject(plugin)
|
|
# in parallel text translations,
|
|
# we don't want to send the post for detection if automatic translation already happens,
|
|
# as automatic translations send content for language detection as a side effect of translating
|
|
|
|
plugin.on(:post_process_cooked) do |_, post|
|
|
if SiteSetting.automatic_translation_target_languages.blank? &&
|
|
Guardian.new.can_detect_language?(post) && post.user_id > 0
|
|
Jobs.enqueue(:detect_translatable_language, type: "Post", translatable_id: post.id)
|
|
end
|
|
end
|
|
|
|
plugin.on(:topic_created) do |topic|
|
|
if SiteSetting.automatic_translation_target_languages.blank? &&
|
|
Guardian.new.can_detect_language?(topic.first_post) && topic.user_id > 0
|
|
Jobs.enqueue(:detect_translatable_language, type: "Topic", translatable_id: topic.id)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|