Skip to content

Commit

Permalink
[TASK] Avoid undefined array key access in DeeplService
Browse files Browse the repository at this point in the history
This change modifies `DeeplService::translateRequest()`
to mitigate undefined array key access errors.
  • Loading branch information
NarkNiro committed Apr 15, 2024
1 parent 202765e commit 982311d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Classes/Service/DeeplService.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,23 @@ public function translateRequest(
string $targetLanguage,
string $sourceLanguage
) {
$glossaryId = '';
// If the source language is set to Autodetect, no glossary can be detected.
if ($sourceLanguage === 'auto') {
$sourceLanguage = null;
$glossary['glossary_id'] = '';
} else {
// @todo Make glossary findable by current site.
$glossary = $this->glossaryRepository->getGlossaryBySourceAndTarget(
$sourceLanguage,
$targetLanguage,
DeeplBackendUtility::detectCurrentPage()
);
if ($glossary['glossary_id'] !== '') {
$glossaryId = $glossary['glossary_id'];
}
}

$response = $this->client->translate($content, $sourceLanguage, $targetLanguage, $glossary['glossary_id']);
$response = $this->client->translate($content, $sourceLanguage, $targetLanguage, $glossaryId);

if ($response === null) {
if (!Environment::isCli() || !Environment::getContext()->isTesting()) {
Expand Down

0 comments on commit 982311d

Please sign in to comment.