Skip to content

Commit

Permalink
Add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kitzberger committed Dec 12, 2024
1 parent b38db78 commit 0baaba3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Classes/Service/DeeplService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace WebVision\WvDeepltranslate\Service;

use GuzzleHttp\Exception\ClientException;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Http\Request;
Expand All @@ -17,8 +19,10 @@
use WebVision\WvDeepltranslate\Domain\Repository\SettingsRepository;
use WebVision\WvDeepltranslate\Utility\DeeplBackendUtility;

class DeeplService
class DeeplService implements LoggerAwareInterface
{
use LoggerAwareTrait;

/**
* Default supported languages
*
Expand Down Expand Up @@ -84,8 +88,12 @@ public function translateRequest(string $content, string $targetLanguage, string
if(!isset($glossary['glossary_id'])) {
$glossary['glossary_id'] = '';
}
$this->logger->debug('Request: ' . print_r([$content, $sourceLanguage, $targetLanguage, $glossary['glossary_id']], true));
$response = $this->client->translate($content, $sourceLanguage, $targetLanguage, $glossary['glossary_id']);
$response = json_decode($response->getBody()->getContents(), true);
$this->logger->debug('Response: ' . print_r($response, true));
} catch (ClientException $e) {
$this->logger->error($e->getMessage());
$flashMessage = GeneralUtility::makeInstance(
FlashMessage::class,
$e->getMessage(),
Expand All @@ -99,7 +107,7 @@ public function translateRequest(string $content, string $targetLanguage, string
return [];
}

return json_decode($response->getBody()->getContents(), true);
return $response;
}

private function loadSupportedLanguages(): void
Expand Down

0 comments on commit 0baaba3

Please sign in to comment.