From 587daf63561098048e3094704957afbe056c7ec0 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 22 May 2024 17:34:05 +0200 Subject: [PATCH] [BUGFIX] Use TYPO3 configured proxy for deepl client When converting the client, the proxy configuration via TYPO3 was no longer taken into account. This will be made up for with this change. --- Classes/AbstractClient.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Classes/AbstractClient.php b/Classes/AbstractClient.php index de5a7b63..4f69d654 100644 --- a/Classes/AbstractClient.php +++ b/Classes/AbstractClient.php @@ -5,6 +5,7 @@ namespace WebVision\WvDeepltranslate; use DeepL\Translator; +use DeepL\TranslatorOptions; use Psr\Log\LoggerInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; use WebVision\WvDeepltranslate\Exception\ApiKeyNotSetException; @@ -43,7 +44,16 @@ protected function getTranslator(): Translator throw new ApiKeyNotSetException('The api key ist not set', 1708081233823); } - $this->translator = GeneralUtility::makeInstance(Translator::class, $this->configuration->getApiKey()); + $options = []; + if ( + isset($GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy']) + && $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy'] !== '' + && GeneralUtility::isValidUrl($GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy']) + ) { + $options[TranslatorOptions::PROXY] = $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy']; + } + + $this->translator = new Translator($this->configuration->getApiKey(), $options); return $this->translator; }