Commit 410d2899 authored by Oliver Bartsch's avatar Oliver Bartsch Committed by Nikita Hovratov
Browse files

[BUGFIX] Align translation prefix handling in DataMapProcessor

For translating / synchronizing (inline) records, the DataHandler
dispatches the data map to the DataMapProcessor. This components'
implementation of the translation prefix however differed from the
one in DataHandler, leading to inconsistency, as some fields still
got the "Translate to:" prefix added, while others did not.

This is now fixed by aligning the functionality with the one
used in the DataHandler.

Resolves: #97721
Releases: main, 11.5
Change-Id: I425ca172f2c66cf43613fb62be0e35fa1dff76fe
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74815


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Tested-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: Nikita Hovratov's avatarNikita Hovratov <nikita.h@live.de>
parent 2dd3daa5
Pipeline #27716 passed with stages
in 19 minutes and 23 seconds
......@@ -27,6 +27,7 @@ use TYPO3\CMS\Core\DataHandling\ReferenceIndexUpdater;
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
......@@ -1316,7 +1317,6 @@ class DataMapProcessor
*/
protected function prefixLanguageTitle(string $tableName, $fromId, int $language, array $data): array
{
$prefix = '';
$prefixFieldNames = array_intersect(
array_keys($data),
$this->getPrefixLanguageTitleFieldNames($tableName)
......@@ -1325,8 +1325,23 @@ class DataMapProcessor
return $data;
}
$languageService = $this->getLanguageService();
[$pageId] = BackendUtility::getTSCpid($tableName, (int)$fromId, $data['pid'] ?? null);
$tsConfig = BackendUtility::getPagesTSconfig($pageId)['TCEMAIN.'] ?? [];
if (($translateToMessage = (string)($tsConfig['translateToMessage'] ?? '')) === '') {
// Return in case translateToMessage had been unset
return $data;
}
$tableRelatedConfig = $tsConfig['default.'] ?? [];
ArrayUtility::mergeRecursiveWithOverrule(
$tableRelatedConfig,
$tsConfig['table.'][$tableName . '.'] ?? []
);
if ($tableRelatedConfig['disablePrependAtCopy'] ?? false) {
// Return in case "disablePrependAtCopy" is set for this table
return $data;
}
try {
$site = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByPageId($pageId);
$siteLanguage = $site->getLanguageById($language);
......@@ -1335,25 +1350,21 @@ class DataMapProcessor
$languageTitle = '';
}
$tsConfigTranslateToMessage = BackendUtility::getPagesTSconfig($pageId)['TCEMAIN.']['translateToMessage'] ?? '';
if (!empty($tsConfigTranslateToMessage)) {
$prefix = $tsConfigTranslateToMessage;
if ($languageService !== null) {
$prefix = $languageService->sL($prefix);
}
$prefix = sprintf($prefix, $languageTitle);
$languageService = $this->getLanguageService();
if ($languageService !== null) {
$translateToMessage = $languageService->sL($translateToMessage);
}
if (empty($prefix)) {
if ($languageTitle) {
$prefix = 'Translate to ' . $languageTitle . ':';
} else {
$prefix = 'Translate:';
}
$translateToMessage = sprintf($translateToMessage, $languageTitle);
if ($translateToMessage === '') {
// Return for edge cases when the translateToMessage got empty, e.g. because the referenced LLL
// label is empty or only contained a placeholder which is replaced by an empty language title.
return $data;
}
foreach ($prefixFieldNames as $prefixFieldName) {
// @todo The hook in DataHandler is not applied here
$data[$prefixFieldName] = '[' . $prefix . '] ' . $data[$prefixFieldName];
$data[$prefixFieldName] = '[' . $translateToMessage . '] ' . $data[$prefixFieldName];
}
return $data;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment