diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php
index 3875a60d2dfffd831a88f696e08bb99d299375b1..1b75134f3a9413c4a7760640de01700d007942d2 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;
 	}
 
 	/**