diff --git a/typo3/sysext/core/Classes/Localization/Parser/AbstractXmlParser.php b/typo3/sysext/core/Classes/Localization/Parser/AbstractXmlParser.php index 88cdd453fc87611a89ac6a30d8d49eddb0f43ca9..406f7763657910dd52832951b4fa8ea44156f2b6 100644 --- a/typo3/sysext/core/Classes/Localization/Parser/AbstractXmlParser.php +++ b/typo3/sysext/core/Classes/Localization/Parser/AbstractXmlParser.php @@ -46,10 +46,10 @@ abstract class AbstractXmlParser implements LocalizationParserInterface $this->sourcePath = $sourcePath; $this->languageKey = $languageKey; if ($this->languageKey !== 'default') { - $this->sourcePath = GeneralUtility::getFileAbsFileName(GeneralUtility::llXmlAutoFileName($this->sourcePath, $this->languageKey)); + $this->sourcePath = $this->getLocalizedFileName($this->sourcePath, $this->languageKey); if (!@is_file($this->sourcePath)) { // Global localization is not available, try split localization file - $this->sourcePath = GeneralUtility::getFileAbsFileName(GeneralUtility::llXmlAutoFileName($sourcePath, $languageKey, true)); + $this->sourcePath = $this->getLocalizedFileName($sourcePath, $languageKey, true); } if (!@is_file($this->sourcePath)) { throw new FileNotFoundException('Localization file does not exist', 1306332397); @@ -83,6 +83,55 @@ abstract class AbstractXmlParser implements LocalizationParserInterface return $this->doParsingFromRoot($rootXmlNode); } + /** + * Checks if a localized file is found in typo3conf/l10n/ (e.g. a language pack was downloaded in the backend) + * or if $sameLocation is set, then checks for a file located in "{language}.locallang.xlf" at the same directory + * + * @param string $fileRef Absolute file reference to locallang file + * @param string $language Language key + * @param bool $sameLocation If TRUE, then locallang localization file name will be returned with same directory as $fileRef + * @return string|null Absolute path to the language file, or null if error occurred + */ + protected function getLocalizedFileName($fileRef, $language, $sameLocation = false) + { + // If $fileRef is already prefixed with "[language key]" then we should return it as is + $fileName = basename($fileRef); + if (GeneralUtility::isFirstPartOfStr($fileName, $language . '.')) { + return GeneralUtility::getFileAbsFileName($fileRef); + } + + if ($sameLocation) { + return GeneralUtility::getFileAbsFileName(str_replace($fileName, $language . '.' . $fileName, $fileRef)); + } + + // Analyse file reference: + // Is system: + if (GeneralUtility::isFirstPartOfStr($fileRef, PATH_typo3 . 'sysext/')) { + $validatedPrefix = PATH_typo3 . 'sysext/'; + } elseif (GeneralUtility::isFirstPartOfStr($fileRef, PATH_typo3 . 'ext/')) { + // Is global: + $validatedPrefix = PATH_typo3 . 'ext/'; + } elseif (GeneralUtility::isFirstPartOfStr($fileRef, PATH_typo3conf . 'ext/')) { + // Is local: + $validatedPrefix = PATH_typo3conf . 'ext/'; + } else { + $validatedPrefix = ''; + } + if ($validatedPrefix) { + // Divide file reference into extension key, directory (if any) and base name: + list($extensionKey, $file_extPath) = explode('/', substr($fileRef, strlen($validatedPrefix)), 2); + $temp = GeneralUtility::revExplode('/', $file_extPath, 2); + if (count($temp) === 1) { + array_unshift($temp, ''); + } + // Add empty first-entry if not there. + list($file_extPath, $file_fileName) = $temp; + // The filename is prefixed with "[language key]." because it prevents the llxmltranslate tool from detecting it. + return PATH_site . 'typo3conf/l10n/' . $language . '/' . $extensionKey . '/' . ($file_extPath ? $file_extPath . '/' : '') . $language . '.' . $file_fileName; + } + return null; + } + /** * Returns array representation of XML data, starting from a root node. * diff --git a/typo3/sysext/core/Classes/Localization/Parser/LocallangXmlParser.php b/typo3/sysext/core/Classes/Localization/Parser/LocallangXmlParser.php index 1d8dd52884f1fc86db6aae02e38e96b78c9f69d6..fbf1ebfe92c8124615727d6918ea426272ade492 100644 --- a/typo3/sysext/core/Classes/Localization/Parser/LocallangXmlParser.php +++ b/typo3/sysext/core/Classes/Localization/Parser/LocallangXmlParser.php @@ -45,7 +45,7 @@ class LocallangXmlParser extends AbstractXmlParser // Parse source $parsedSource = $this->parseXmlFile(); // Parse target - $localizedTargetPath = GeneralUtility::getFileAbsFileName(GeneralUtility::llXmlAutoFileName($this->sourcePath, $this->languageKey)); + $localizedTargetPath = $this->getLocalizedFileName($this->sourcePath, $this->languageKey); $targetPath = $this->languageKey !== 'default' && @is_file($localizedTargetPath) ? $localizedTargetPath : $this->sourcePath; try { $parsedTarget = $this->getParsedTargetData($targetPath); diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php index ca61e94006815d1f6bc9e25cdfd92d46c1d1971b..d6ee404eda8f8852939ccd7d4e58ae22616342f3 100644 --- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php +++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php @@ -3336,9 +3336,11 @@ class GeneralUtility * @param string $language Language key * @param bool $sameLocation If TRUE, then locallang localization file name will be returned with same directory as $fileRef * @return string Returns the filename reference for the language unless error occurred in which case it will be NULL + * @deprecated in TYPO3 v9.0, will be removed in TYPO3 v10.0, as the functionality has been moved into AbstractXmlParser. */ public static function llXmlAutoFileName($fileRef, $language, $sameLocation = false) { + trigger_error('This method will be removed in TYPO3 v10.0, the functionality has been moved into AbstractXmlParser', E_USER_DEPRECATED); // If $fileRef is already prefixed with "[language key]" then we should return it as is $fileName = basename($fileRef); if (self::isFirstPartOfStr($fileName, $language . '.')) { diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-83083-GeneralUtilityllXmlAutoFileName.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-83083-GeneralUtilityllXmlAutoFileName.rst new file mode 100644 index 0000000000000000000000000000000000000000..7b95a78f8636b089b6c43c8b78b6ca9b5af5c022 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-83083-GeneralUtilityllXmlAutoFileName.rst @@ -0,0 +1,33 @@ +.. include:: ../../Includes.txt + +========================================================= +Deprecation: #83083 - GeneralUtility::llXmlAutoFileName() +========================================================= + +See :issue:`83083` + +Description +=========== + +The method ``GeneralUtility::llXmlAutoFileName()``, which detects a XLF/XML translation file, has been moved into +AbstractXmlParser, as the functionality is solely used in there, and the code belongs in this area. + + +Impact +====== + +Calling the method will trigger a deprecation warning. + + +Affected Installations +====================== + +Any TYPO3 instance with an extension using the method directly. + + +Migration +========= + +If necessary, use the XmlParser functionality, or implement the code directly in your own extension. + +.. index:: PHP-API, FullyScanned \ No newline at end of file diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php index 3edd1528ac48d72e1a3973a5eca6cee27ee5c43d..5324b3bd0fcd8ef06813337257b398ca3bf8114b 100644 --- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php +++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php @@ -505,4 +505,11 @@ return [ 'Deprecation-82445-PageTranslationRelatedFunctionality.rst', ], ], + 'TYPO3\CMS\Core\Utility\GeneralUtility::llXmlAutoFileName' => [ + 'numberOfMandatoryArguments' => 2, + 'maximumNumberOfArguments' => 3, + 'restFiles' => [ + 'Deprecation-83083-GeneralUtilityllXmlAutoFileName.rst', + ], + ], ];