Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion app/jobs/regular/detect_translate_post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def execute(args)
return unless SiteSetting.experimental_content_translation
return if args[:post_id].blank?

post = Post.find(args[:post_id])
post = Post.find_by(id: args[:post_id])
return if post.blank? || post.raw.blank? || post.deleted_at.present? || post.user_id <= 0

detected_locale = DiscourseTranslator::PostLocaleDetector.detect_locale(post)
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/regular/detect_translate_topic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def execute(args)
return unless SiteSetting.experimental_content_translation
return if args[:topic_id].blank?

topic = Topic.find(args[:topic_id])
topic = Topic.find_by(id: args[:topic_id])
if topic.blank? || topic.title.blank? || topic.deleted_at.present? || topic.user_id <= 0
return
end
Expand Down
25 changes: 0 additions & 25 deletions app/jobs/regular/translate_translatable.rb

This file was deleted.

123 changes: 0 additions & 123 deletions app/jobs/scheduled/automatic_translation_backfill.rb

This file was deleted.

31 changes: 0 additions & 31 deletions lib/discourse_translator/automatic_translations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,22 @@ module DiscourseTranslator
class AutomaticTranslations
def inject(plugin)
plugin.on(:post_process_cooked) do |_, post|
if translatable?(post)
Jobs.enqueue(:translate_translatable, type: "Post", translatable_id: post.id)
end

if SiteSetting.experimental_content_localization
Jobs.enqueue(:detect_translate_post, post_id: post.id)
end
end

plugin.on(:topic_created) do |topic|
if translatable?(topic)
Jobs.enqueue(:translate_translatable, type: "Topic", translatable_id: topic.id)
end

if SiteSetting.experimental_content_localization
Jobs.enqueue(:detect_translate_topic, topic_id: topic.id)
end
end

plugin.on(:topic_edited) do |topic|
if translatable?(topic)
Jobs.enqueue(:translate_translatable, type: "Topic", translatable_id: topic.id)
end
end

plugin.on(:post_edited) do |post, topic_changed|
if SiteSetting.experimental_content_localization && topic_changed
Jobs.enqueue(:detect_translate_topic, topic_id: post.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.is_a?(Post)
public_categories.include?(content.topic.category_id)
elsif content.is_a?(Topic)
public_categories.include?(content.category_id)
else
false
end
end
end
end
Loading
Loading