@@ -4,53 +4,22 @@ module DiscourseTranslator
44 class AutomaticTranslations
55 def inject ( plugin )
66 plugin . on ( :post_process_cooked ) do |_ , post |
7- if translatable? ( post )
8- Jobs . enqueue ( :translate_translatable , type : "Post" , translatable_id : post . id )
9- end
10-
117 if SiteSetting . experimental_content_localization
128 Jobs . enqueue ( :detect_translate_post , post_id : post . id )
139 end
1410 end
1511
1612 plugin . on ( :topic_created ) do |topic |
17- if translatable? ( topic )
18- Jobs . enqueue ( :translate_translatable , type : "Topic" , translatable_id : topic . id )
19- end
20-
2113 if SiteSetting . experimental_content_localization
2214 Jobs . enqueue ( :detect_translate_topic , topic_id : topic . id )
2315 end
2416 end
2517
26- plugin . on ( :topic_edited ) do |topic |
27- if translatable? ( topic )
28- Jobs . enqueue ( :translate_translatable , type : "Topic" , translatable_id : topic . id )
29- end
30- end
31-
3218 plugin . on ( :post_edited ) do |post , topic_changed |
3319 if SiteSetting . experimental_content_localization && topic_changed
3420 Jobs . enqueue ( :detect_translate_topic , topic_id : post . topic_id )
3521 end
3622 end
3723 end
38-
39- def translatable? ( content )
40- return false if SiteSetting . automatic_translation_target_languages . blank?
41- return false if content . user_id <= 0
42- return false if SiteSetting . automatic_translation_backfill_rate <= 0
43- return true unless SiteSetting . automatic_translation_backfill_limit_to_public_content
44-
45- public_categories = Category . where ( read_restricted : false ) . pluck ( :id )
46-
47- if content . is_a? ( Post )
48- public_categories . include? ( content . topic . category_id )
49- elsif content . is_a? ( Topic )
50- public_categories . include? ( content . category_id )
51- else
52- false
53- end
54- end
5524 end
5625end
0 commit comments