public static function detect($test = false)
    {
        if ($test) {
            return 'en';
        }

        $key = self::$sessionName;

        $cookieName = self::cookieName($key);

        // check if the session lang exists
        if (Session::exists($key)) {
            //check if supported languages contains the session lang value
            if (!in_array(Session::get($key), self::$supported)) {
                Session::put($key, config('lang.default', 'en'));
            }

            if (Cookie::existe($cookieName)) {
                if (Cookie::get($cookieName) != Session::get($key)) {
                    Cookie::create($cookieName, Session::get($key), config('lang.lifetime'));
                }
            } else {
                Cookie::create($cookieName, Session::get($key), config('lang.lifetime'));
            }
        } // check if the cookie lang exists
        elseif (Cookie::existe($cookieName)) {
            //check if supported languages contains the cookie lang value
            if (in_array(Cookie::get($cookieName), self::$supported)) {
                Session::put($key, Cookie::get($cookieName));
            } else {
                Session::put($key, config('lang.default', 'en'));
                Cookie::create($cookieName, config('lang.default', 'en'), config('lang.lifetime'));
            }
        } // if cokkie and session not found
        else {
            Session::put($key, config('lang.default', 'en'));
            Cookie::create($cookieName, config('lang.default', 'en'), config('lang.lifetime'));
        }

        return Session::get($key);
    }