src/ChrisKonnertz/DeepLy/ResponseBag/TranslationBag.php
public function getTranslation()
    {
        if (sizeof($this->responseContent->translations) === 0) {
            return null;
        }

        $translatedText = '';
        $lineBreaks = $this->lineBreaks; // Copy the array so we can modify it
        foreach ($this->responseContent->translations as $index => $translation) {
            // The beams array contains 1-n translation alternatives.
            // The first one (index 0) is the "best" one (best score)
            $beam = $translation->beams[0];

            // Add a line break. Add multiple line breaks if there is a cluster of empty lines.
            while (sizeof($lineBreaks) > 0 and current($lineBreaks) == $index) {
                array_shift($lineBreaks);
                $translatedText .= PHP_EOL;
            }

            // Since we want to return one string we have to glue the sentences.
            // We add a space between them if there is not space or line break at the end of the last sentence.
            // Note that we can use \n here, because PHP_EOL always ends with a \n.
            $lastChar = mb_substr($translatedText, -1);
            if ($lastChar !== '' and $lastChar !== ' ' and mb_substr($translatedText, -1) !== "\n") {
                $translatedText .= ' ';
            }

            $translatedText .= $beam->postprocessed_sentence;
        }

        return $translatedText;
    }
public function getTranslation()
    {
        if (sizeof($this->responseContent->translations) === 0) {
            return null;
        }

        $translatedText = '';
        $lineBreaks = $this->lineBreaks; // Copy the array so we can modify it
        foreach ($this->responseContent->translations as $index => $translation) {
            // The beams array contains 1-n translation alternatives.
            // The first one (index 0) is the "best" one (best score)
            $beam = $translation->beams[0];

            // Add a line break. Add multiple line breaks if there is a cluster of empty lines.
            while (sizeof($lineBreaks) > 0 and current($lineBreaks) == $index) {
                array_shift($lineBreaks);
                $translatedText .= PHP_EOL;
            }

            // Since we want to return one string we have to glue the sentences.
            // We add a space between them if there is not space or line break at the end of the last sentence.
            // Note that we can use \n here, because PHP_EOL always ends with a \n.
            $lastChar = mb_substr($translatedText, -1);
            if ($lastChar !== '' and $lastChar !== ' ' and mb_substr($translatedText, -1) !== "\n") {
                $translatedText .= ' ';
            }

            $translatedText .= $beam->postprocessed_sentence;
        }

        return $translatedText;
    }
Returns a translation from the response content of the API call.
Tries to return the "best" translation (which is the first).
Returns null if there is no translation.

@return string|null