Translates provided textual string

@param $text
@param bool $autoDetect
@return null
@throws TranslateException
162167
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;
    }
263134
private function applyTransformRule(string $text, string $rule, string $locale, string $regex): string
	{
		$transliterator = $this->getTransliterator($rule, $locale);
		$newText = '';
		$offset = 0;

		foreach ($this->getRanges($text, $regex) as $range) {
			$newText .= substr($text, $offset, $range[0] - $offset);
			$newText .= $this->transformWithContext($transliterator, $text, $range[0], $range[1]);
			$offset = $range[0] + $range[1];
		}

		$newText .= substr($text, $offset);

		return $newText;
	}
1119021
public function setText($text) {
		if( !is_string($text) ) {
			throw new \Exception('RequireStringParameter');
		}
		$this->setTEXTBody(strip_tags($text));
		$this->setHTMLBody(nl2br($text));
	}
934593
protected function onSetText(string $text): void
    {
        parent::onSetText($text);

        $this->isInvalid = false;
        $this->value = null;

        if ($this->hasError()) {
            return;
        }

        if ($this->isEmpty()) {
            return;
        }

        if (!preg_match('/^[-+]?[0-9]+$/', $text)) {
            $this->setError('Invalid value');
            $this->isInvalid = true;

            return;
        }

        $value = intval($text);

        if ($this->minimumValue !== null && $value < $this->minimumValue || $this->maximumValue !== null && $value > $this->maximumValue) {
            $this->setError('Invalid value');
            $this->isInvalid = true;

            return;
        }

        $this->value = $value;
    }
669489
public function search(string $text)
    {
        $search = $this->find('css', '#adminbarsearch');

        if (! $search) {
            throw new ExpectationException(
                '[W404] Search field in the toolbar could not be found',
                $this->getDriver()
            );
        }

        try {
            $search->find('css', '#adminbar-search')->press();
            $search->find('css', '#adminbar-search')->focus();
            $search->fillField('adminbar-search', $text);
            $search->find('css', '#adminbar-search')->focus();
        } catch (UnsupportedDriverActionException $e) {
            $search->fillField('adminbar-search', $text);
        }

        $search->submit();
    }
210577
protected function onFormatText(string &$text): void
    {
        $lines = preg_split("/\r\n|\n|\r/", $text);
        $result = [];

        $lastEmptyLinesCount = 0;
        $hasFoundNonEmptyLines = false;

        foreach ($lines as $line) {
            if (($this->textFormatOptions & TextFormatOptions::TRIM) !== 0) {
                $line = trim($line);
            }
            if (($this->textFormatOptions & TextFormatOptions::COMPACT) !== 0) {
                $line = preg_replace('/\s+/', ' ', $line);
            }

            if ($line === '') {
                if (($this->textFormatOptions & TextFormatOptions::COMPACT_LINES) !== 0 && $lastEmptyLinesCount > 0) {
                    continue;
                }
                if (($this->textFormatOptions & TextFormatOptions::TRIM_LINES) !== 0 && !$hasFoundNonEmptyLines) {
                    continue;
                }

                $lastEmptyLinesCount++;
            } else {
                $lastEmptyLinesCount = 0;
                $hasFoundNonEmptyLines = true;
            }

            $result[] = $line;
        }

        if (($this->textFormatOptions & TextFormatOptions::TRIM_LINES) !== 0 && $lastEmptyLinesCount > 0) {
            // Trim the last empty lines (we did not know until now that those were at the end).
            array_splice($result, -$lastEmptyLinesCount);
        }

        $text = implode("\r\n", $result);
    }
604690
protected function createTranslateContext(
        string $text,
        Language $languageTo,
        Language $languageFrom
    ): RequestContext {
        $requestContext = (new RequestContext(sprintf("%s/%s", $this->apiEndpoint, self::TRANSLATE_API_PATH)))
            ->setRequestParameters(
                [
                    'lang' => $this->getLanguageString($languageTo, $languageFrom)
                ] + $this->getAuthData()
            )
            ->setData(['text' => $text])
            ->setMethod(RequestContext::METHOD_POST);

        return $this->fillGeneralRequestSettings($requestContext);
    }
312515
public function text(string $text, $strict = false): ResponseInterface
    {
        return $this->print($text, $strict ? 'text/plain; charset=utf-8' : null);
    }
417896
public function translate($text, $parameters = array())
    {
        if (!is_null($this->lang)) {
            return $this->lang->get($text, $parameters);
        }

        return $text;
    }
676534
private function importSingleTranslation($keyword, $text, $locale, $filename, $domain, $force = false)
    {
        if (strlen($keyword) > 255) {
            return false;
        }

        $translationGroup = $this->translationGroupManager->getTranslationGroupByKeywordAndDomain($keyword, $domain);

        if (!$translationGroup->hasTranslation($locale)) {
            $this->translationGroupManager->addTranslation($translationGroup, $locale, $text, $filename);

            return true;
        }

        if (true === $force) {
            $this->translationGroupManager->updateTranslation($translationGroup, $locale, $text, $filename);

            return true;
        }

        return false;
    }
1348162
private function MatchText( $text )
	{
		for ( $k = 0; $k < strlen( $text ); $k++ )
		{
			$ch = $this->Peek( $k );
			if ( $ch == 0 || $ch != $text[ $k ] )
				return false;
		}
		for ( $k = 0; $k < strlen( $text ); $k++ )
			$this->Read();
		return true;
	}
1105020
private function translateText($text)
    {
        if (empty($text) || preg_match('/^\s+$/', $text)) {
            return $text;
        }
        if (false !== strpos($text, '|')) {
            $parts = preg_split('/\s*\|\s*/', $text);

            foreach ($parts as $key => $part) {
                $parts[$key] = $this->translateText($part);
            }

            return implode(' | ', $parts);
        }

        preg_match_all('/%.*?%/', $text, $matches);

        if (!empty($matches[0])) {
            $placeholders = $matches[0];
            $words = preg_split('/%.*?%/', $text);
            $parts = [];

            foreach ($words as $i => $word) {
                $parts[] = !empty($word) && !preg_match('/^\s+$/', $word) ? $this->translateText($word) : $word;

                if (isset($placeholders[$i])) {
                    $parts[] = $placeholders[$i];
                }
            }

            return implode('', $parts);
        }

        $params = [
            'key'    => $this->apiKey,
            'text'   => $text,
            'lang'   => $this->direction,
            'format' => 'html',
        ];
        $json = file_get_contents('https://translate.yandex.net/api/v1.5/tr.json/translate?'.http_build_query($params));

        return json_decode($json, true)['text'][0];
    }
647483
protected function getDataFromText($text)
    {
        $data = json_decode($text, true);
        if (!is_array($data)) {
            return null;
        }
        return $data;
    }
896482
def translate(self, text):
        

        # Reset substitution counter
        self.count = 0

        # Process text
        return self._make_regex().sub(self, text)
1136158
public function translate(string $text, array $params = null)
    {
        $index = null;
        $namespace = 'Apps\Controller\\' . env_name . '\\';
        foreach (@debug_backtrace() as $caller) {
            if (isset($caller['class']) && Str::startsWith($namespace, $caller['class'])) {
                $index = Str::sub((string)$caller['class'], Str::length($namespace));
            }
        }
        return $this->get($index, $text, $params);
    }
1334514
public void append(final Object text) {
		if (text instanceof Message) {
			append(translate(text), true);
		} else if (text != null) {
			append(text.toString(), true);
		}
	}
273363
public static function fromString($string, Translations $translations, array $options = [])
    {
        $options += static::$options;

        $functions = new JsFunctionsScanner($string);
        $functions->saveGettextFunctions($translations, $options);
    }