fix(settings): show the correct initial locale in Personal info #49988
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #23486 (+possibly other locale related matters)
Summary
The initial Locale shown in the Personal info page is not the actual locale in-use. Besides being a bug in itself, it likely has resulted in some confusing bug reports about other aspects of Nextcloud not following the apparently active locale within an individual account.
Details
Given the following sent by the browser:
Results in our templates returning:
Which is fine I guess, but it does not match what is displayed on the Personal info page for this user. The Locale, instead, is shown as "English (United States)" (it should be just "English" given
data-locale="en").Some environments likely work around this by setting the
default_localeand/orforce_localeconfig paremeters (which short circuit the fall back code detailed below).Cause
We call
findLocal()in two different ways, which produces different fallback return values. In our templates we call it with the currently determined language:server/lib/private/L10N/Factory.php
Lines 115 to 116 in d8d708e
...which means if a user doesn't have a locale saved yet we hit this fallback code:
server/lib/private/L10N/Factory.php
Lines 267 to 269 in d8d708e
This returns the language (
enin my test case) as the fallback locale under all circumstances. This is why data-locale is set to en.But when the user loads up their Personal settings we populate the active locale without providing the language clue to findLocale():
server/apps/settings/lib/Settings/Personal/PersonalInfo.php
Line 268 in d8d708e
...So we hit a different fallback:
server/lib/private/L10N/Factory.php
Lines 272 to 274 in d8d708e
The result is this field is only accurate if the user changes their locale since that triggers a save to the preferences table. At best this is confusing, at worst this leads to bug reports about things not being formatted per the locale that is indicated as being active.
This explains why the Personal settings page always shows me the right thing (for an English speaker in the US), but behavior elsewhere in Nextcloud doesn't match it until I toggle it to something else then back which triggers a save (such as in #23486).
This also [likely] means visitors with a base language other than English sent in their browser
Accept-Languageheader get their real fallback locale set to their language (reasonable), but their Personal info page will show "English (United States)" until they toggle it (triggering a save).This was discovered when looking into #23486 and revisiting my initial quick fix in #49986.
TODO
Checklist