Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions lib/discourse_translator/automatic_translations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,37 @@ module DiscourseTranslator
class AutomaticTranslations
def inject(plugin)
plugin.on(:post_process_cooked) do |_, post|
if SiteSetting.automatic_translation_target_languages.present? && post.user_id > 0
if translatable?(post)
Jobs.enqueue(:translate_translatable, type: "Post", translatable_id: post.id)
end
end

plugin.on(:topic_created) do |topic|
if SiteSetting.automatic_translation_target_languages.present? && topic.user_id > 0
if translatable?(topic)
Jobs.enqueue(:translate_translatable, type: "Topic", translatable_id: topic.id)
end
end

plugin.on(:topic_edited) do |topic|
if SiteSetting.automatic_translation_target_languages.present? && topic.user_id > 0
if translatable?(topic)
Jobs.enqueue(:translate_translatable, type: "Topic", translatable_id: topic.id)
end
end
end

def translatable?(content)
return false if SiteSetting.automatic_translation_target_languages.blank?
return false if content.user_id <= 0
return false if SiteSetting.automatic_translation_backfill_rate <= 0
return true unless SiteSetting.automatic_translation_backfill_limit_to_public_content

public_categories = Category.where(read_restricted: false).pluck(:id)

if content.class == Post
public_categories.include?(content.topic.category_id)
elsif content.class == Topic
public_categories.include?(content.category_id)
end
end
end
end
Loading