Skip to content

Commit

Permalink
Merge pull request #331 from web-vision/deepl-proxy-config
Browse files Browse the repository at this point in the history
[BUGFIX] Use TYPO3 configured proxy for deepl client
  • Loading branch information
NarkNiro authored May 23, 2024
2 parents 61bdf78 + 587daf6 commit 28e04b4
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Classes/AbstractClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

3 comments on commit 28e04b4

@staempfli-webteam
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy']['http'] ?
In my opinion GeneralUtility::isValidUrl($GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy'] always returns false, because this key points to an array, not a url.

Bildschirmfoto 2024-06-04 um 11 11 11

@staempfli-webteam
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        $options = [];
        if ( isset($GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy']) && $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy'] !== '' ) {
            if ( isset($GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy']['http']) && $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy']['http'] !== '' && GeneralUtility::isValidUrl($GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy']['http']) ) {
                $options[TranslatorOptions::PROXY] = $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy']['http'];
            }
        }

Worked for me.

@staempfli-webteam
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.