Skip to content
Snippets Groups Projects
Commit 9cc29962 authored by Yassine Doghri's avatar Yassine Doghri
Browse files

fix(get_browser_language): return defaultLocale if browser doesn't send user preferred language

parent b5263107
No related branches found
No related tags found
No related merge requests found
Pipeline #7160 passed
Pipeline: Castopod

#7161

    ......@@ -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);
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment