diff --git a/src/Drivers/AmazonTranslate.php b/src/Drivers/AmazonTranslate.php index e8f83e4..cd60070 100644 --- a/src/Drivers/AmazonTranslate.php +++ b/src/Drivers/AmazonTranslate.php @@ -24,6 +24,12 @@ public function __construct(array $credentials, string $region, string $version public function translate(string $text): string { + if (strlen($text) > 10000) { + $strings = str_split($text, 10000); + + return implode('', $this->translateBatch($strings)); + } + $response = $this->sendTranslateRequest($text, [ 'TargetLanguageCode' => $this->target, 'SourceLanguageCode' => $this->source, diff --git a/src/Drivers/GoogleV2Translate.php b/src/Drivers/GoogleV2Translate.php index 347caf4..623844d 100644 --- a/src/Drivers/GoogleV2Translate.php +++ b/src/Drivers/GoogleV2Translate.php @@ -26,6 +26,12 @@ public function __construct(string $key, string $format = 'html', string $model public function translate(string $text): string { + if (strlen($text) > 102400) { + $strings = str_split($text, 102400); + + return implode('', $this->translateBatch($strings)); + } + $response = $this->sendTranslateRequest($text, [ 'target' => $this->target, 'source' => $this->source, diff --git a/src/Drivers/StichozaTranslate.php b/src/Drivers/StichozaTranslate.php index 1f33d29..bce9d76 100644 --- a/src/Drivers/StichozaTranslate.php +++ b/src/Drivers/StichozaTranslate.php @@ -14,8 +14,14 @@ public function __construct() $this->client = new GoogleTranslate(); } - public function translate(string $string): string + public function translate(string $text): string { - return $this->client->setSource($this->source)->setTarget($this->target)->translate($string); + if (strlen($text) > 15000) { + $strings = str_split($text, 15000); + + return implode('', $this->translateBatch($strings)); + } + + return $this->client->setSource($this->source)->setTarget($this->target)->translate($text); } }