diff --git a/Classes/Hooks/AbstractTranslateHook.php b/Classes/Hooks/AbstractTranslateHook.php index d8e73e8f..dbc3ea3d 100644 --- a/Classes/Hooks/AbstractTranslateHook.php +++ b/Classes/Hooks/AbstractTranslateHook.php @@ -4,7 +4,11 @@ namespace WebVision\WvDeepltranslate\Hooks; +use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\DataHandling\DataHandler; +use TYPO3\CMS\Core\Messaging\FlashMessage; +use TYPO3\CMS\Core\Messaging\FlashMessageService; +use TYPO3\CMS\Core\Utility\GeneralUtility; use WebVision\WvDeepltranslate\Domain\Repository\PageRepository; use WebVision\WvDeepltranslate\Exception\ApiKeyNotSetException; use WebVision\WvDeepltranslate\Service\DeeplService; @@ -58,6 +62,18 @@ public function translateContent( } if ($response === null) { + if (!Environment::isCli() || !Environment::getContext()->isTesting()) { + $flashMessage = GeneralUtility::makeInstance( + FlashMessage::class, + 'Translation not successful', // ToDo use locallang label + '', + -1 + ); + GeneralUtility::makeInstance(FlashMessageService::class) + ->getMessageQueueByIdentifier() + ->addMessage($flashMessage); + } + return $content; } diff --git a/Classes/Service/DeeplService.php b/Classes/Service/DeeplService.php index d61121c7..71b53148 100644 --- a/Classes/Service/DeeplService.php +++ b/Classes/Service/DeeplService.php @@ -10,11 +10,7 @@ use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; -use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\Exception\SiteNotFoundException; -use TYPO3\CMS\Core\Messaging\FlashMessage; -use TYPO3\CMS\Core\Messaging\FlashMessageService; -use TYPO3\CMS\Core\Utility\GeneralUtility; use WebVision\WvDeepltranslate\ClientInterface; use WebVision\WvDeepltranslate\Domain\Repository\GlossaryRepository; use WebVision\WvDeepltranslate\Exception\ApiKeyNotSetException; @@ -72,16 +68,9 @@ public function translateRequest( $response = $this->client->translate($content, $sourceLanguage, $targetLanguage, $glossaryId); if ($response === null) { - if (!Environment::isCli() || !Environment::getContext()->isTesting()) { - $flashMessage = GeneralUtility::makeInstance( - FlashMessage::class, - 'Translation not successful', - '', - -1 - ); - GeneralUtility::makeInstance(FlashMessageService::class) - ->getMessageQueueByIdentifier() - ->addMessage($flashMessage); + // @todo Can be replaced with `$this->logger?->` when TYPO3 v11 and therefore PHP 7.4/8.0 support is dropped. + if ($this->logger !== null) { + $this->logger->warning('Translation not successful'); } }