public function translate($text, $autoDetect = true)
    {
        if (! $this->getTargetLang()) {
            throw new TranslateException('No target language was set.');
        }

        if (! $this->getSourceLang() && $autoDetect) {
            // Detect language if source language was not provided and auto detect is turned on
            $this->setSourceLang($this->detect($text));
        } else {
            if (! $this->getSourceLang()) {
                throw new TranslateException('No source language was set with autodetect turned off.');
            }
        }

        $requestUrl = $this->buildRequestUrl($this->getTranslateUrl(), [
            'q' => $text,
            'source' => $this->getSourceLang(),
            'target' => $this->getTargetLang()
        ]);

        $response = $this->getResponse($requestUrl);

        if (isset($response['data']['translations']) && count($response['data']['translations']) > 0) {
            return $response['data']['translations'][0]['translatedText'];
        }
        return null;
    }