/** * [findDemanded description] * @param R3H6\LocallangTools\Domain\Model\Dto\TranslationDemand $demand [description] * @return TYPO3\CMS\Extbase\Persistence\ObjectStorage<R3H6\LocallangTools\Domain\Model\Translation> */ public function findDemanded(TranslationDemand $demand) { $demand->setLanguage('de'); $translations = new ObjectStorage(); $files = (array) $demand->getFiles(); if ($demand->getExtensions()) { $extensionPaths = []; foreach ($demand->getExtensions() as $extensionKey) { $extensionPaths[] = 'EXT:' . $extensionKey; } $files = $files + PathUtility::getLocallangPaths($extensionPaths); } elseif (empty($files)) { $files = PathUtility::getLocallangPaths(); } $language = $demand->getLanguage(); if (empty($language)) { $language = self::DEFAULT_LANGUAGE; } foreach ($files as $file) { $filePath = PathUtility::getAbsolutePath($file); $parsedData = $this->localizationFactory->getParsedData($filePath, $language, LocalizationFactory::CHARSET, LocalizationFactory::ERROR_MODE_EXCEPTION); foreach ($parsedData[self::DEFAULT_LANGUAGE] as $key => $value) { $default = $value[0]['source']; $source = isset($parsedData[$language][$key][0]['source']) ? $parsedData[$language][$key][0]['source'] : null; $target = isset($parsedData[$language][$key][0]['target']) ? $parsedData[$language][$key][0]['target'] : null; $translation = GeneralUtility::makeInstance(Translation::class, $file, $key, $language, $default, $source, $target); if ($demand->getState() && $demand->getState() !== $translation->getState()) { continue; } if ($demand->getKey() && stripos($translation->getKey(), $demand->getKey()) === false) { continue; } if ($demand->getSearch() && stripos($translation->getTarget(), $demand->getSearch()) === false && stripos($translation->getSource(), $demand->getSearch()) === false) { continue; } $translations->attach($translation); } } return $translations; }
public static function getLocallangPaths(array $directories = null) { if ($directories === null) { $directories = array('typo3conf/ext/', 'typo3/sysext/'); $directories = array('typo3conf/ext/'); } $files = array(); // Traverse extension locations: foreach ($directories as $path) { $path = static::getAbsolutePath(\TYPO3\CMS\Core\Utility\PathUtility::sanitizeTrailingSeparator($path)); if (is_dir($path)) { $files = array_merge($files, GeneralUtility::getAllFilesAndFoldersInPath(array(), $path, 'xml,xlf', false, 99, 'Tests')); } } // Remove all non-locallang files (looking at the prefix) foreach ($files as $key => $value) { if (strpos(basename($value), 'locallang') !== 0) { unset($files[$key]); } else { $files[$key] = PathUtility::getTypo3PathTo($value); } } return $files; }
public function getFilesOptions() { return PathUtility::getLocallangPaths(); }