Skip to content

Commit

Permalink
[BUGFIX] Fix web-vision#55: container children should be localized as…
Browse files Browse the repository at this point in the history
… well
  • Loading branch information
dmitryd committed Jun 9, 2022
1 parent d8f0e63 commit 1347f05
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 39 deletions.
38 changes: 9 additions & 29 deletions Classes/Hooks/TranslateHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,66 +87,48 @@ 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);
$siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
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)) {
Expand All @@ -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)) {
Expand Down
19 changes: 9 additions & 10 deletions Classes/Override/LocalizationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1347f05

Please sign in to comment.