FIX: Ensure auto close notice is posted with system locale

FIX: Ensure auto close notice is posted with system locale

Previously it was created with the locale of the user who created the final post in the topic

diff --git a/lib/post_creator.rb b/lib/post_creator.rb
index 5bac660..7c19f66 100644
--- a/lib/post_creator.rb
+++ b/lib/post_creator.rb
@@ -351,7 +351,8 @@ class PostCreator
         :closed, true, Discourse.system_user,
         message: I18n.t(
           'topic_statuses.autoclosed_message_max_posts',
-          count: SiteSetting.auto_close_messages_post_count
+          count: SiteSetting.auto_close_messages_post_count,
+          locale: SiteSetting.default_locale
         )
       )
     elsif !is_private_message &&
@@ -363,7 +364,8 @@ class PostCreator
         :closed, true, Discourse.system_user,
         message: I18n.t(
           'topic_statuses.autoclosed_topic_max_posts',
-          count: SiteSetting.auto_close_topics_post_count
+          count: SiteSetting.auto_close_topics_post_count,
+          locale: SiteSetting.default_locale
         )
       )
     end
diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rb
index 2838e86..b5616e8 100644
--- a/spec/components/post_creator_spec.rb
+++ b/spec/components/post_creator_spec.rb
@@ -391,6 +391,26 @@ describe PostCreator do
               expect(topic.closed).to eq(true)
               expect(topic_timer.reload.deleted_at).to eq_time(Time.zone.now)
             end
+
+            it "uses the system locale for the message" do
+              post
+
+              I18n.with_locale(:fr) do
+                PostCreator.new(
+                  topic.user,
+                  topic_id: topic.id,
+                  raw: "this is a second post"
+                ).create
+              end
+
+              topic.reload
+
+              expect(topic.posts.last.raw).to eq(I18n.t(
+                'topic_statuses.autoclosed_topic_max_posts',
+                count: SiteSetting.auto_close_topics_post_count,
+                locale: :en
+              ))
+            end
           end
         end
       end

GitHub sha: 0a537608

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/strange-russian-auto-close-message/161148/6