There are two branches of logic in ApplicationController#with_resolved_locale: logged-in users and logged-out users.
Logged-out users (1) Set locale from the request, then (2) use the ‘default locale’ site setting if none was detected.
Priority is ?lang= in the URL, then the locale cookie, then Accept-Language if each respective site setting is enabled.
The logged-in logic is simpler: User preference, then ‘default locale’ if user preference is forbidden.
In all cases, if the resolved locale has been unloaded from the Discourse server, en is used. (This mostly triggers during unit and integration tests, IIRC.)
locale = SiteSettings::DefaultsProvider::DEFAULT_LOCALE if !I18n.locale_available?(locale)
So, in summary, what it does:
- It’s the language for anonymous requests with no
Accept-Languageheader.- Including, in particular, the account registration process.
- It’s the language that will always be used if you have not allowed users to choose their own language, or the user has not set a preferred locale.