@@ -4,22 +4,39 @@ module DiscourseTranslator
44 class AutomaticTranslations
55 def inject ( plugin )
66 plugin . on ( :post_process_cooked ) do |_ , post |
7- if SiteSetting . automatic_translation_target_languages . present? && post . user_id > 0
7+ if translatable? ( post )
88 Jobs . enqueue ( :translate_translatable , type : "Post" , translatable_id : post . id )
99 end
1010 end
1111
1212 plugin . on ( :topic_created ) do |topic |
13- if SiteSetting . automatic_translation_target_languages . present? && topic . user_id > 0
13+ if translatable? ( topic )
1414 Jobs . enqueue ( :translate_translatable , type : "Topic" , translatable_id : topic . id )
1515 end
1616 end
1717
1818 plugin . on ( :topic_edited ) do |topic |
19- if SiteSetting . automatic_translation_target_languages . present? && topic . user_id > 0
19+ if translatable? ( topic )
2020 Jobs . enqueue ( :translate_translatable , type : "Topic" , translatable_id : topic . id )
2121 end
2222 end
2323 end
24+
25+ def translatable? ( content )
26+ return false if SiteSetting . automatic_translation_target_languages . blank?
27+ return false if content . user_id <= 0
28+ return false if SiteSetting . automatic_translation_backfill_rate <= 0
29+ return true unless SiteSetting . automatic_translation_backfill_limit_to_public_content
30+
31+ public_categories = Category . where ( read_restricted : false ) . pluck ( :id )
32+
33+ if content . is_a ( Post )
34+ public_categories . include? ( content . topic . category_id )
35+ elsif content . is_a ( Topic )
36+ public_categories . include? ( content . category_id )
37+ else
38+ false
39+ end
40+ end
2441 end
2542end
0 commit comments