From 7fdfdff85cfab2b5174a1117530bcc3ae7be7301 Mon Sep 17 00:00:00 2001 From: Markus Klein <klein.t3@reelworx.at> Date: Wed, 25 Feb 2015 14:26:51 +0100 Subject: [PATCH] [BUGFIX] Properly handle XLF translation file detection The GeneralUtility::llXmlAutoFileName() method will now also correctly handle paths to files that are not placed within a known directory (ext, sysext, etc.) if the call is made with $sameFile = TRUE. This allows placing language files in arbitrary storage. This change finally re-enables the usage of locallang files in TypoScript or f:translate-ViewHelpers which use the XLIFF format and are not placed within an extension. This has always been working with files in the XML format. Resolves: #65273 Releases: master, 6.2 Change-Id: Ibb647cea32a9fc04e9dfdf707a5e8690ad399d5c Reviewed-on: http://review.typo3.org/37167 Reviewed-by: Oliver Hader <oliver.hader@typo3.org> Tested-by: Oliver Hader <oliver.hader@typo3.org> Reviewed-by: Helmut Hummel <helmut.hummel@typo3.org> Tested-by: Helmut Hummel <helmut.hummel@typo3.org> --- .../core/Classes/Utility/GeneralUtility.php | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php index 3875a60d2dff..1b75134f3a94 100755 --- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php +++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php @@ -3976,20 +3976,24 @@ Connection: close } /** - * Returns auto-filename for locallang-XML localizations. + * Returns auto-filename for locallang localizations * - * @param string $fileRef Absolute file reference to locallang-XML file. Must be inside system/global/local extension + * @param string $fileRef Absolute file reference to locallang file * @param string $language Language key - * @param bool $sameLocation if TRUE, then locallang-XML localization file name will be returned with same directory as $fileRef - * @return string Returns the filename reference for the language unless error occurred (or local mode is used) in which case it will be NULL + * @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 */ static public function llXmlAutoFileName($fileRef, $language, $sameLocation = FALSE) { + // If $fileRef is already prefixed with "[language key]" then we should return it as is + $fileName = basename($fileRef); + if (self::isFirstPartOfStr($fileName, $language . '.')) { + return $fileRef; + } + if ($sameLocation) { - $location = 'EXT:'; - } else { - // Default location of translations - $location = 'typo3conf/l10n/' . $language . '/'; + return str_replace($fileName, $language . '.' . $fileName, $fileRef); } + // Analyse file reference: // Is system: if (self::isFirstPartOfStr($fileRef, PATH_typo3 . 'sysext/')) { @@ -4000,10 +4004,6 @@ Connection: close } elseif (self::isFirstPartOfStr($fileRef, PATH_typo3conf . 'ext/')) { // Is local: $validatedPrefix = PATH_typo3conf . 'ext/'; - } elseif (self::isFirstPartOfStr($fileRef, PATH_site . 'tests/')) { - // Is test: - $validatedPrefix = PATH_site . 'tests/'; - $location = $validatedPrefix; } else { $validatedPrefix = ''; } @@ -4011,20 +4011,16 @@ Connection: close // Divide file reference into extension key, directory (if any) and base name: list($file_extKey, $file_extPath) = explode('/', substr($fileRef, strlen($validatedPrefix)), 2); $temp = self::revExplode('/', $file_extPath, 2); - if (count($temp) == 1) { + if (count($temp) === 1) { array_unshift($temp, ''); } // Add empty first-entry if not there. list($file_extPath, $file_fileName) = $temp; - // If $fileRef is already prefix with "[language key]" then we should return it as this - if (substr($file_fileName, 0, strlen($language) + 1) === $language . '.') { - return $fileRef; - } // The filename is prefixed with "[language key]." because it prevents the llxmltranslate tool from detecting it. - return $location . $file_extKey . '/' . ($file_extPath ? $file_extPath . '/' : '') . $language . '.' . $file_fileName; - } else { - return NULL; + $location = 'typo3conf/l10n/' . $language . '/' . $file_extKey . '/' . ($file_extPath ? $file_extPath . '/' : ''); + return $location . $language . '.' . $file_fileName; } + return NULL; } /** -- GitLab