Fix user preferences not being applied correctly after sign-in

This commit is contained in:
Bubka
2023-03-15 11:46:37 +01:00
parent 5ced8cbf0e
commit f359a1ade3
9 changed files with 70 additions and 22 deletions

View File

@ -17,11 +17,12 @@ class SetLanguage
*/
public function handle($request, Closure $next)
{
// 2 possible cases here:
// 3 possible cases here:
// - The http client send an accept-language header
// - No language is specified
// - There is an authenticated user with a possible language set
// - No language is specified at all
//
// We honor the language requested in the header or we use the fallback one.
// Priority to the user preference, then the header request, otherwise the fallback language.
// Note that if a user is authenticated later by the auth guard, the app locale
// will be overriden if the user has set a specific language in its preferences.
@ -57,6 +58,11 @@ class SetLanguage
}
}
$user = $request->user();
if (! is_null($user) && $request->user()->preferences['lang'] != 'browser') {
$lang = $request->user()->preferences['lang'];
}
// If the language is not available (or partial), strings will be translated using the fallback language.
App::setLocale($lang);