mirror of
https://code.castopod.org/adaures/castopod
synced 2025-04-19 13:01:19 +00:00
fix(get_browser_language): return defaultLocale if browser doesn't send user preferred language
This commit is contained in:
parent
b5263107da
commit
9cc2996261
@ -11,12 +11,17 @@ declare(strict_types=1);
|
||||
|
||||
if (! function_exists('get_browser_language')) {
|
||||
/**
|
||||
* Gets the browser default language using the request header key `HTTP_ACCEPT_LANGUAGE`
|
||||
* Gets the browser default language using the request header key `HTTP_ACCEPT_LANGUAGE`. Returns Castopod's default
|
||||
* locale if `HTTP_ACCEPT_LANGUAGE` is null.
|
||||
*
|
||||
* @return string ISO 639-1 language code
|
||||
*/
|
||||
function get_browser_language(string $httpAcceptLanguage): string
|
||||
function get_browser_language(?string $httpAcceptLanguage = null): string
|
||||
{
|
||||
if ($httpAcceptLanguage === null) {
|
||||
return config('App')->defaultLocale;
|
||||
}
|
||||
|
||||
$langs = explode(',', $httpAcceptLanguage);
|
||||
|
||||
return substr($langs[0], 0, 2);
|
||||
|
Loading…
x
Reference in New Issue
Block a user