From 1347f0506064a29c8bfd0511fde6dca5b975325b Mon Sep 17 00:00:00 2001 From: Dmitry Dulepov Date: Thu, 9 Jun 2022 13:08:49 +0300 Subject: [PATCH] [BUGFIX] Fix #55: container children should be localized as well --- Classes/Hooks/TranslateHook.php | 38 +++++---------------- Classes/Override/LocalizationController.php | 19 +++++------ 2 files changed, 18 insertions(+), 39 deletions(-) diff --git a/Classes/Hooks/TranslateHook.php b/Classes/Hooks/TranslateHook.php index d988d7f0..49fd20d4 100644 --- a/Classes/Hooks/TranslateHook.php +++ b/Classes/Hooks/TranslateHook.php @@ -87,31 +87,18 @@ public function processTranslateTo_copyAction(&$content, $languageRecord, $dataH } break; } - - if (!isset($cmdmap['localization']['custom']['srcLanguageId'])){ - $cmdmap['localization']['custom']['srcLanguageId'] = ''; - } - - $customMode = $cmdmap['localization']['custom']['mode']; - - //translation mode set to deepl or google translate - if (!is_null($customMode)) { - $langParam = explode('-', $cmdmap['localization']['custom']['srcLanguageId']); - $sourceLanguageCode = $langParam[0]; + $customMode = preg_replace('/^localize(deepl|google)(?:auto)?$/', '\1', $_GET['action']); + if ($customMode === 'deepl' || $customMode === 'google') { $targetLanguage = BackendUtility::getRecord('sys_language', $languageRecord['uid']); - $sourceLanguage = BackendUtility::getRecord('sys_language', (int)$sourceLanguageCode); //get target language mapping if any $targetLanguageMapping = $this->deeplSettingsRepository->getMappings($targetLanguage['uid']); if ($targetLanguageMapping != null) { $targetLanguage['language_isocode'] = $targetLanguageMapping; } - if ($sourceLanguage == null) { - // Make good defaults - $sourceLanguageIso = 'en'; - //choose between default and autodetect - $deeplSourceIso = ($sourceLanguageCode == 'auto' ? null : 'EN'); - + [$sourceLanguageCode] = explode('-', $_GET['srcLanguageId']); + if ($sourceLanguageCode === 'auto') { + $deeplSourceIso = 'EN'; // Try to find the default language from the site configuration if (isset($tablename) && isset($currectRecordId)) { $currentRecord = BackendUtility::getRecord($tablename, (int)$currectRecordId); @@ -119,34 +106,29 @@ public function processTranslateTo_copyAction(&$content, $languageRecord, $dataH try { $site = $siteFinder->getSiteByPageId($currentRecord['pid']); $language = $site->getDefaultLanguage(); - $sourceLanguageIso = strtolower($language->getTwoLetterIsoCode()); - if ($sourceLanguageCode !== 'auto') { - $deeplSourceIso = strtoupper($sourceLanguageIso); - } + $deeplSourceIso = strtoupper($language->getTwoLetterIsoCode()); } catch (SiteNotFoundException $exception) { // Ignore, use defaults } } } else { + $sourceLanguage = BackendUtility::getRecord('sys_language', (int)$sourceLanguageCode); $sourceLanguageMapping = $this->deeplSettingsRepository->getMappings($sourceLanguage['uid']); if ($sourceLanguageMapping != null) { $sourceLanguage['language_isocode'] = $sourceLanguageMapping; } - $sourceLanguageIso = $sourceLanguage['language_isocode']; - $deeplSourceIso = $sourceLanguageIso; + $deeplSourceIso = $sourceLanguage['language_isocode']; } if ($this->isHtml($content)) { $content = $this->stripSpecificTags(['br'], $content); } - //mode deepl if ($customMode == 'deepl') { //if target language and source language among supported languages if (in_array(strtoupper($targetLanguage['language_isocode']), $this->deeplService->apiSupportedLanguages)) { if ($tablename == 'tt_content') { $response = $this->deeplService->translateRequest($content, $targetLanguage['language_isocode'], $deeplSourceIso); } else { - $currentRecord = BackendUtility::getRecord($tablename, (int)$currectRecordId); $response = $this->deeplService->translateRequest($content, $targetLanguage['language_isocode'], $sourceLanguage['language_isocode']); } if (!empty($response) && isset($response->translations)) { @@ -158,12 +140,10 @@ public function processTranslateTo_copyAction(&$content, $languageRecord, $dataH } } } - } //mode google - elseif ($customMode == 'google') { + } elseif ($customMode == 'google') { if ($tablename == 'tt_content') { $response = $this->googleService->translate($deeplSourceIso, $targetLanguage['language_isocode'], $content); } else { - $currentRecord = BackendUtility::getRecord($tablename, (int)$currectRecordId); $response = $this->googleService->translate($content, $targetLanguage['language_isocode'], $content); } if (!empty($response)) { diff --git a/Classes/Override/LocalizationController.php b/Classes/Override/LocalizationController.php index e376adb6..5028278a 100644 --- a/Classes/Override/LocalizationController.php +++ b/Classes/Override/LocalizationController.php @@ -183,10 +183,17 @@ public function getRecordLocalizeSummary(ServerRequestInterface $request): Respo ]; } - return (new JsonResponse())->setPayload([ + $payload = [ 'records' => $records, 'columns' => $this->getPageColumns($pageId, $records, $params), - ]); + ]; + if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('container')) { + // s. EXT:containers Xclass B13\Container\Xclasses\LocalizationController + $recordLocalizeSummaryModifier = GeneralUtility::makeInstance(\B13\Container\Xclasses\RecordLocalizeSummaryModifier::class); + $payload = $recordLocalizeSummaryModifier->rebuildPayload($payload); + } + + return (new JsonResponse())->setPayload($payload); } /** @@ -242,14 +249,6 @@ protected function process($params): void $cmd['tt_content'][$currentUid] = [ 'localize' => $destLanguageId, ]; - //setting mode and source language for deepl translate. - if ($params['action'] === static::ACTION_LOCALIZEDEEPL || $params['action'] === static::ACTION_LOCALIZEDEEPL_AUTO) { - $cmd['localization']['custom']['mode'] = 'deepl'; - $cmd['localization']['custom']['srcLanguageId'] = $params['srcLanguageId']; - } else if ($params['action'] === static::ACTION_LOCALIZEGOOGLE || $params['action'] === static::ACTION_LOCALIZEGOOGLE_AUTO) { - $cmd['localization']['custom']['mode'] = 'google'; - $cmd['localization']['custom']['srcLanguageId'] = $params['srcLanguageId']; - } } else { $cmd['tt_content'][$currentUid] = [ 'copyToLanguage' => $destLanguageId,