header("Accept-Language")); if ($accepted && $accepted !== '*') { $prefLocales = array_reduce( array_diff(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. $lang = array_key_first($prefLocales); } } // If the language is not available (or partial), strings will be translated using the fallback language. App::setLocale($lang); return $next($request); } }