FEATURE: Allow setting locale from 'lang' param (#30952)

As we start to translate more pages, we'll need a way for other sites to
link back to our translated topics.

This commit gives us the ability to use the "lang" URL param to define what
language a site should be in.

Related: https://github.com/discourse/discourse-translator/pull/199
This commit is contained in:
Natalie Tay
2025-01-24 11:53:13 +08:00
committed by GitHub
parent 5d4bb4b54e
commit 8d45755a06
4 changed files with 47 additions and 6 deletions

View File

@ -1215,13 +1215,11 @@ module Discourse
end
def self.anonymous_locale(request)
locale =
HttpLanguageParser.parse(request.cookies["locale"]) if SiteSetting.set_locale_from_cookie
locale = request.params["lang"] if SiteSetting.set_locale_from_param
locale ||= request.cookies["locale"] if SiteSetting.set_locale_from_cookie
locale ||=
HttpLanguageParser.parse(
request.env["HTTP_ACCEPT_LANGUAGE"],
) if SiteSetting.set_locale_from_accept_language_header
locale
request.env["HTTP_ACCEPT_LANGUAGE"] if SiteSetting.set_locale_from_accept_language_header
HttpLanguageParser.parse(locale)
end
# For test environment only