/** * Adds the config files to * the local config files var * * @param array $configs */ public function addConfigFiles($configs) { $files = array(); for ($i = 0, $len = count($configs); $i < $len; $i++) { $dir = PathHelper::normalizePath($configs[$i]['dir']); if (!is_dir($dir)) { continue; } $files[$dir] = DirHelper::getFilesByType($dir, $configs[$i]['type'], true); } $files = DirHelper::flattenTree($files); for ($i = 0, $len = count($files); $i < $len; $i++) { $this->configFiles[] = $files[$i]; } // Reload config file list $this->updateFiles(); }
/** * Get a translation from a file by a path * * @param string|arary $path * @return string */ public static function get($path) { $project = ProjectManager::getActiveProject(); $project = $project ? $project : ProjectManager::getDefaultProject(); $pathParts = ArrayHelper::clean(explode(self::SUBPATH_SEPERATOR, $path)); $localeDir = PathHelper::createPath(array($project->getTranslationPath(), Locale::getKey())); $entryPoint = ''; $entryPointIndex = 0; // Check if path is empty if (empty($pathParts)) { return ''; } // Get entry point file for ($i = 0, $len = count($pathParts); $i < $len; $i++) { $isFile = false; $localeDir = PathHelper::getRealPath($localeDir); for ($x = 0, $lenX = count(self::$translationTypes); $x < $lenX; $x++) { $fileExt = self::$translationTypes[$x]; $pathPart = $pathParts[$i]; $isFile = is_file($localeDir . $pathPart . '.' . $fileExt); // Escape loop if file was found if (true == $isFile) { break; } } // Attach current "dir" to the localdir (next level) $localeDir .= $pathPart; // Excape loop if entry point was found if (true == $isFile) { $entryPointIndex = $i; $entryPoint = $localeDir . '.' . $fileExt; break; } } /** * If there is no entry point take * all supported translation files * from the given directory */ if (empty($entryPoint) && is_dir($localeDir)) { $files = DirHelper::scanDir($localeDir); $names = array(); foreach ($files as $file) { $extension = pathinfo($file['path'], PATHINFO_EXTENSION); $filename = pathinfo($file['path'], PATHINFO_FILENAME); if (array_search($extension, self::$translationTypes) !== false) { $names[] = $filename; } } return $names; } // if (true == empty($entryPoint)) { // throw new Translator\Exception\EntryPointNotFoundException("No entry point (file) found for: " . (string) $path); // } $pathParts = array_slice($pathParts, $entryPointIndex + 1); $pathParts = ArrayHelper::clean($pathParts); // The default translation value $value = $path; /** * Operate with the key functions for different file types. * At this point we are handling valid values */ switch ($fileExt) { case self::$translationTypes[0]: $value = self::getValueByKeyPHP($entryPoint, $pathParts); break; case self::$translationTypes[1]: $value = self::getValueByKeyCSV($entryPoint, $pathParts); break; } /** * If the value is a array and empty it doesn't * need to be returned. Return a empty string * instead */ if (empty($value)) { return ''; } else { return $value; } }