Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit feb3303

Browse files
committed
pms
1 parent 0f8954b commit feb3303

File tree

4 files changed

+25
-22
lines changed

4 files changed

+25
-22
lines changed

app/jobs/regular/detect_translate_post.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ def execute(args)
1414

1515
if SiteSetting.ai_translation_backfill_limit_to_public_content
1616
topic = post.topic
17-
return if topic.blank? || topic.category&.read_restricted?
17+
if topic.blank? || topic.category&.read_restricted? ||
18+
topic.archetype == Archetype.private_message
19+
return
20+
end
1821
end
1922

2023
begin

app/jobs/regular/localize_posts.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@ def execute(args)
3131

3232
if SiteSetting.ai_translation_backfill_limit_to_public_content
3333
posts =
34-
posts.joins(:topic).where(
35-
topics: {
36-
category_id: Category.where(read_restricted: false).select(:id),
37-
archetype: "regular",
38-
},
39-
)
34+
posts
35+
.joins(:topic)
36+
.where(topics: { category_id: Category.where(read_restricted: false).select(:id) })
37+
.where.not(topics: { archetype: Archetype.private_message })
4038
end
4139

4240
if SiteSetting.ai_translation_backfill_max_age_days > 0

spec/jobs/regular/detect_translate_post_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,8 @@
8181
DiscourseAi::Translation::PostLocalizer.expects(:localize).never
8282

8383
job.execute({ post_id: post.id })
84+
85+
pm_post = Fabricate(:post, topic: Fabricate(:private_message_topic))
86+
job.execute({ post_id: pm_post.id })
8487
end
8588
end

spec/jobs/regular/localize_posts_spec.rb

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,33 +126,35 @@
126126
fab!(:private_category) { Fabricate(:private_category, group: Group[:staff]) }
127127
fab!(:private_topic) { Fabricate(:topic, category: private_category) }
128128
fab!(:private_post) { Fabricate(:post, topic: private_topic, locale: "es") }
129+
130+
fab!(:pm_post) { Fabricate(:post, topic: Fabricate(:private_message_topic), locale: "es") }
131+
129132
fab!(:public_post) { Fabricate(:post, locale: "es") }
130133

131-
before { SiteSetting.ai_translation_backfill_limit_to_public_content = true }
134+
before do
135+
SiteSetting.ai_translation_backfill_limit_to_public_content = true
136+
SiteSetting.experimental_content_localization_supported_locales = "ja"
137+
end
132138

133139
it "only processes posts from public categories" do
134-
DiscourseAi::Translation::PostLocalizer.expects(:localize).with(public_post, "en").once
135140
DiscourseAi::Translation::PostLocalizer.expects(:localize).with(public_post, "ja").once
136-
DiscourseAi::Translation::PostLocalizer.expects(:localize).with(public_post, "de").once
137141

138142
DiscourseAi::Translation::PostLocalizer
139143
.expects(:localize)
140144
.with(private_post, any_parameters)
141145
.never
142146

147+
DiscourseAi::Translation::PostLocalizer.expects(:localize).with(pm_post, any_parameters).never
148+
143149
job.execute({})
144150
end
145151

146152
it "processes all posts when setting is disabled" do
147153
SiteSetting.ai_translation_backfill_limit_to_public_content = false
148154

149-
DiscourseAi::Translation::PostLocalizer.expects(:localize).with(public_post, "en").once
150155
DiscourseAi::Translation::PostLocalizer.expects(:localize).with(public_post, "ja").once
151-
DiscourseAi::Translation::PostLocalizer.expects(:localize).with(public_post, "de").once
152-
153-
DiscourseAi::Translation::PostLocalizer.expects(:localize).with(private_post, "en").once
156+
DiscourseAi::Translation::PostLocalizer.expects(:localize).with(pm_post, "ja").once
154157
DiscourseAi::Translation::PostLocalizer.expects(:localize).with(private_post, "ja").once
155-
DiscourseAi::Translation::PostLocalizer.expects(:localize).with(private_post, "de").once
156158

157159
job.execute({})
158160
end
@@ -162,12 +164,13 @@
162164
fab!(:old_post) { Fabricate(:post, locale: "es", created_at: 10.days.ago) }
163165
fab!(:new_post) { Fabricate(:post, locale: "es", created_at: 2.days.ago) }
164166

165-
before { SiteSetting.ai_translation_backfill_max_age_days = 5 }
167+
before do
168+
SiteSetting.ai_translation_backfill_max_age_days = 5
169+
SiteSetting.experimental_content_localization_supported_locales = "ja"
170+
end
166171

167172
it "only processes posts within the age limit" do
168-
DiscourseAi::Translation::PostLocalizer.expects(:localize).with(new_post, "en").once
169173
DiscourseAi::Translation::PostLocalizer.expects(:localize).with(new_post, "ja").once
170-
DiscourseAi::Translation::PostLocalizer.expects(:localize).with(new_post, "de").once
171174

172175
DiscourseAi::Translation::PostLocalizer
173176
.expects(:localize)
@@ -180,13 +183,9 @@
180183
it "processes all posts when setting is disabled" do
181184
SiteSetting.ai_translation_backfill_max_age_days = 0
182185

183-
DiscourseAi::Translation::PostLocalizer.expects(:localize).with(new_post, "en").once
184186
DiscourseAi::Translation::PostLocalizer.expects(:localize).with(new_post, "ja").once
185-
DiscourseAi::Translation::PostLocalizer.expects(:localize).with(new_post, "de").once
186187

187-
DiscourseAi::Translation::PostLocalizer.expects(:localize).with(old_post, "en").once
188188
DiscourseAi::Translation::PostLocalizer.expects(:localize).with(old_post, "ja").once
189-
DiscourseAi::Translation::PostLocalizer.expects(:localize).with(old_post, "de").once
190189

191190
job.execute({})
192191
end

0 commit comments

Comments
 (0)