diff --git a/composer.json b/composer.json index 558fcf2..dd7d306 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "php": ">=7.1.0", "illuminate/support": "^5.5|^6|^7|^8|^9|^10|^11", "illuminate/translation": "^5.5|^6|^7|^8|^9|^10|^11", - "stichoza/google-translate-php": "^5.0.1", + "stichoza/google-translate-php": "^5.2.0", "google/cloud-translate": "^1.7.4", "yandex/translate-api": "^1.5.2", "ext-json": "*" diff --git a/src/Api/StichozaApiTranslate.php b/src/Api/StichozaApiTranslate.php index cf933c6..ba4d8fb 100644 --- a/src/Api/StichozaApiTranslate.php +++ b/src/Api/StichozaApiTranslate.php @@ -21,14 +21,13 @@ public function __construct($api_key = null) public function translate(string $text, string $locale, string $base_locale = null): string { - if ($base_locale === null) - $this->handle->setSource(); - else - $this->handle->setSource($base_locale); - $this->handle->setTarget($locale); + $this->handle + ->setSource($base_locale) + ->setTarget($locale); + try { - return $this->handle->translate($text); - } catch (\ErrorException $e) { + return $this->handle->translate($text) ?? ''; + } catch (\Exception $e) { return false; } }