getLocales()); // localization files should not be edited if ($this->checkLocalizedFile(basename($file), $availableLanguages)) { throw new LFException('failure.langfile.notSupported'); } $this->setWorkspace('base'); parent::init($file, $path, $metaFile); } /** * reads the absolute language file with all localized sub files * * @throws \Exception * @throws LFException * @return void */ public function readFile() { // read absolute file $localLang = $this->readLLFile($this->absFile, 'default'); // loop all languages $languages = SgLib::getSystemLanguages(); $originLang = []; foreach ($languages as $lang) { $originLang[$lang] = $this->absFile; if (!\array_key_exists($lang, $localLang)) { continue; } if ($lang === 'default' || (\is_array($localLang[$lang]) && \count($localLang[$lang]))) { if (\is_array($localLang[$lang]) && \count($localLang[$lang])) { \ksort($localLang[$lang]); } continue; } // get localized file $lFile = $this->getLocalizedFile($localLang[$lang], $lang); if ($lFile && $this->checkLocalizedFile(basename($lFile), $lang)) { $originLang[$lang] = $lFile; $localLang[$lang] = []; if (!is_file($lFile)) { continue; } // read the content try { $llang = $this->readLLFile($lFile, $lang); } catch (\Exception $e) { throw $e; } // merge arrays and save origin of current language ArrayUtility::mergeRecursiveWithOverrule($localLang, $llang); } } // check if (!\is_array($localLang)) { throw new LFException('failure.search.noFileContent'); } // copy all to object variables, if everything was ok $this->localLang = $localLang; $this->originLang = $originLang; } /** * Checks if a localized file is found in labels pack (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 = PathUtility::basename($fileRef); if (GeneralUtility::isFirstPartOfStr($fileName, $language . '.')) { return GeneralUtility::getFileAbsFileName($fileRef); } if ($sameLocation) { return GeneralUtility::getFileAbsFileName(str_replace($fileName, $language . '.' . $fileName, $fileRef)); } // Analyze file reference $validatedPrefix = Typo3Lib::getLocalizedFilePrefix($fileRef); if ($validatedPrefix) { // Divide file reference into extension key, directory (if any) and base name: [$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. [$file_extPath, $file_fileName] = $temp; // The filename is prefixed with "[language key]." because it prevents the llxmltranslate tool from detecting it. return Typo3Lib::getLabelsPath() . $language . '/' . $extensionKey . '/' . ($file_extPath ? $file_extPath . '/' : '') . $language . '.' . $file_fileName; } return NULL; } }