mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-05-30 14:58:57 +02:00
Make language detection more robust
This commit is contained in:
parent
2123250a5e
commit
3e391167c6
@ -28,10 +28,23 @@ class SetLanguage
|
|||||||
|
|
||||||
if($lang === 'browser') {
|
if($lang === 'browser') {
|
||||||
$lang = config('app.fallback_locale');
|
$lang = config('app.fallback_locale');
|
||||||
|
$accepted = $request->header("Accept-Language");
|
||||||
if ($request->hasHeader("Accept-Language")) {
|
|
||||||
|
if ($accepted) {
|
||||||
|
$accepted = is_array($accepted) ? implode(',', $accepted) : $accepted;
|
||||||
|
$prefLocales = array_reduce(
|
||||||
|
explode(',', $accepted),
|
||||||
|
function ($res, $el) {
|
||||||
|
list($l, $q) = array_merge(explode(';q=', $el), [1]);
|
||||||
|
$res[$l] = (float) $q;
|
||||||
|
return $res;
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
arsort($prefLocales);
|
||||||
|
|
||||||
// We only keep the primary language passed via the header.
|
// We only keep the primary language passed via the header.
|
||||||
$lang = head(explode(',', $request->header("Accept-Language")));
|
$lang = array_key_first($prefLocales);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user