mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-06 05:24:51 +08:00
Our `TopicListResponder` determined content locale using only the `?tl=` URL param, falling back to `SiteSetting.default_locale`. This ignored the locale cookie set by the language switcher or persisted from a previous `?tl=` visit. The fix is to simply use `I18n.locale` which is already resolved from all sources (?tl= param, cookie, Accept-Language header, site default). This only affects initial page loads and browser refreshes. Ember internal navigation (format.json) is unaffected since it doesn't call `localize_topic_list_content`. Scenarios affected and fixed (per related urls): 1. Anonymous user switches to German via language switcher → German-origin topics show English titles on page load 2. User arrives via ?tl=fi from Google → first page works, but subsequent navigations (without ?tl= in URL) fall back to English despite the locale cookie being set Related issue: - https://meta.discourse.org/t/localisation-bug-for-anonymous-users-with-tl-lang/400090 - https://meta.discourse.org/t/topic-list-is-shown-in-a-language-de-but-has-one-de-topic-not-translated/400209
34 lines
917 B
Ruby
34 lines
917 B
Ruby
# frozen_string_literal: true
|
|
|
|
module TopicListResponder
|
|
def respond_with_list(list)
|
|
discourse_expires_in 1.minute
|
|
|
|
respond_to do |format|
|
|
format.html do
|
|
@list = list
|
|
localize_topic_list_content(list)
|
|
|
|
store_preloaded(
|
|
list.preload_key,
|
|
MultiJson.dump(TopicListSerializer.new(list, scope: guardian)),
|
|
)
|
|
render "list/list"
|
|
end
|
|
format.json { render_serialized(list, TopicListSerializer) }
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def localize_topic_list_content(list)
|
|
return if list.topics.blank? || !SiteSetting.content_localization_enabled
|
|
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)
|
|
end
|
|
end
|
|
end
|