public function detectLanguage($context = "default")
    {
        self::$context = $context;
        
        // Priority:
        
        // 1) explicitly set by the request parameter language
        // 2) last language in the session
        // 3) last language in the cookie
        // 4) browser default language
        // 5) the first one from the supported list
        // 6) English
        
        // Let's go
        
        $language = "en";
        
        // 5) the first one from the supported list
        foreach (self::$supported_languages as $lng) {
            $language = $lng;
            break;
        }
        
        // 4) browser default
        if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]) && trim($_SERVER["HTTP_ACCEPT_LANGUAGE"]) != "") {
            $accepted = explode(',', $_SERVER["HTTP_ACCEPT_LANGUAGE"]);
            
            foreach ($accepted as $key => $name) {
                $code = explode(';', $name);
                // handle the cases like en-ca => en
                $code = explode("-", $code[0]);
                
                if (!empty(self::$supported_languages[$code[0]])) {
                    $language = $code[0];
                    break;
                }
            }
        }
        
        // 3) last language in the cookie
        if (!empty($_COOKIE[self::$context . "_language"]) && !empty(self::$supported_languages[$_COOKIE[self::$context . "_language"]])) {
            $language = $_COOKIE[self::$context . "_language"];
        }
        
        // 2) last language in the session
        if (!empty(session()->vars()[self::$context . "_language"]) && !empty(self::$supported_languages[session()->vars()[self::$context . "_language"]])) {
            $language = $_COOKIE[self::$context . "_language"];
        }
        
        // 1) explicitly set by request parameter language
        if (!empty($_REQUEST["language"]) && !empty(self::$supported_languages[$_REQUEST["language"]])) {
            $language = $_REQUEST["language"];
        }
        
        $this->setCurrentLanguage($language);
    }