discourse-translator/lib/discourse_translator/parallel_text_translation.rb
Natalie Tay 95a5cfe304
DEV: Cleanup terms (#232)
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
2025-02-27 17:40:56 +08:00

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