/** * Finds all the languages * * @throws \Exception */ private function findLanguages() { $dir = Utils::getLangDirectory(); if (!file_exists($dir)) { throw new \Exception('Cannot find the laravel language directory: ' . $dir); } foreach (new \DirectoryIterator($dir) as $dir) { if (!$dir->isDot() && $dir->isDir()) { $this->push((string) $dir); } } }
public function findNamespaces(Languages $languages) { $languages->each(function ($lang) { $dir = Utils::getLangDirectory($lang); if (!file_exists($dir)) { throw new \Exception('Cannot read directory for language ' . $lang); } foreach (new \DirectoryIterator($dir) as $file) { if ($file->isFile()) { $basename = $file->getBasename('.php'); if (!$this->contains($basename)) { $this->push($basename); } } } }); return $this; }
public function findMissingNamespaceEntries($namespace) { if (!$this->namespaces->contains($namespace)) { throw new \Exception('Invalid namespace: ' . $namespace); } $missing = []; $entries = []; $unique = []; foreach ($this->languages as $lang) { $filename = Utils::getLanguageFilename($lang, $namespace); if (in_array($filename, $this->skipFiles)) { continue; } $entries[$lang] = $this->loadLanguageFile($lang, $namespace); $unique = array_merge($unique, array_keys($entries[$lang])); } foreach (array_unique($unique) as $entry) { foreach (array_keys($entries) as $lang) { $error = null; if (!isset($entries[$lang][$entry])) { $error = new MissingEntryError(); } else { if (is_string($entries[$lang][$entry]) && !strlen(trim($entries[$lang][$entry]))) { $error = new EmptyEntryError(); } } if ($error) { $error->language = $lang; $error->namespace = $namespace; $error->entry = $entry; $missing[] = $error; } } } return $missing; }