Skip to content

A platform for community discussion. Free, open, simple.

FIX: Use resolved locale for localizations, instead of param+site default fallback (#39395)

Natalie Taya44f0d15a2a6
diff --git a/lib/topic_list_responder.rb b/lib/topic_list_responder.rb
index f09024555f9..4331bb72086 100644
--- a/lib/topic_list_responder.rb
+++ b/lib/topic_list_responder.rb
@@ -23,7 +23,9 @@ module TopicListResponder
def localize_topic_list_content(list)
return if list.topics.blank? || !SiteSetting.content_localization_enabled
- crawl_locale = params[Discourse::LOCALE_PARAM].presence || SiteSetting.default_locale
+ return if cookies.key?(ContentLocalization::SHOW_ORIGINAL_COOKIE)
+ return if current_user&.user_option&.show_original_content
+ crawl_locale = I18n.locale
list.topics.each do |topic|
LocalizationAttributesReplacer.replace_topic_attributes(topic, crawl_locale)
diff --git a/spec/requests/list_controller_spec.rb b/spec/requests/list_controller_spec.rb
index d7a9f02bcaa..a9e0c8d388c 100644
--- a/spec/requests/list_controller_spec.rb
+++ b/spec/requests/list_controller_spec.rb
@@ -2001,6 +2001,7 @@ RSpec.describe ListController do
end
before do
+ SiteSetting.set_locale_from_param = true
topic.update!(locale: "en")
topic.category.update!(locale: "en")
end
diff --git a/spec/system/content_localization_spec.rb b/spec/system/content_localization_spec.rb
index 3978ef3e658..2a10516693c 100644
--- a/spec/system/content_localization_spec.rb
+++ b/spec/system/content_localization_spec.rb
@@ -201,6 +201,37 @@ describe "Content Localization" do
expect(topic_page.topic_title).to have_content("織田信長の生涯")
end
+ fab!(:ja_topic) do
+ topic = Fabricate(:topic, title: "日本語で書かれたトピック", locale: "ja", user: admin)
+ Fabricate(:post, topic:, locale: "ja", raw: "日本語の投稿です")
+ topic
+ end
+ fab!(:ja_topic_en_localization) do
+ Fabricate(
+ :topic_localization,
+ topic: ja_topic,
+ locale: "en",
+ fancy_title: "A topic written in Japanese",
+ )
+ end
+
+ it "shows original title on topic list for anonymous users when topic locale matches browsing locale" do
+ visit("/?tl=ja")
+ expect(page).to have_css(".topic-list-body .raw-topic-link", text: "日本語で書かれたトピック")
+ expect(page).to have_no_css(
+ ".topic-list-body .raw-topic-link",
+ text: "A topic written in Japanese",
+ )
+
+ # navigate away and come back — locale should persist via cookie
+ visit("/")
+ expect(page).to have_css(".topic-list-body .raw-topic-link", text: "日本語で書かれたトピック")
+ expect(page).to have_no_css(
+ ".topic-list-body .raw-topic-link",
+ text: "A topic written in Japanese",
+ )
+ end
+
it "ignores tl parameter for logged-in users" do
sign_in(site_local_user)
visit("/t/#{topic.id}?tl=ja")