public function detectLanguage($text)
    {
        // Note: We always use English as the target language. If the source language is English as well,
        // DeepL automatically seems to set the target language to French so this is not a problem.
        $translationBag = $this->requestTranslation($text, self::LANG_EN, self::LANG_AUTO);

        return $translationBag->getSourceLanguage();
    }
public function detectLanguage($text)
    {
        // Note: We always use English as the target language. If the source language is English as well,
        // DeepL automatically seems to set the target language to French so this is not a problem.
        $translationBag = $this->requestTranslation($text, self::LANG_EN, self::LANG_AUTO);

        return $translationBag->getSourceLanguage();
    }
public function detectLanguage ( $ text ) { // Note: We always use English as the target language. If the source language is English as well, // DeepL automatically seems to set the target language to French so this is not a problem. $ translationBag = $ this -> requestTranslation ( $ text , self :: LANG_EN , self :: LANG_AUTO ) ; return $ translationBag -> getSourceLanguage ( ) ; }
Tries to detect the language of a text and returns its language code.
The language of the text has to be one of the supported languages or the result will be incorrect.
This method might throw an exception so you should wrap it in a try-catch-block.
Especially it will throw an exception if the API was not able to auto-detected the language.

@param string      $text The text you want to analyze
@return string|null      Returns a language code from the self::LANG_CODES array or null
@throws \Exception
Tries to detect the language of a text and returns its language code . The language of the text has to be one of the supported languages or the result will be incorrect . This method might throw an exception so you should wrap it in a try - catch - block . Especially it will throw an exception if the API was not able to auto - detected the language .