/** * Execute the command. * * @return void */ public function handle() { // get paths of registered namespace hints // e.g user in @lang('user::myview') resolving to app/Modules/User/Resources $resDirs = Config::get('langcheck.usehints') ? Lang::getHints() : array(); $resDirs[base_path() . '/resources/lang'] = 'app'; // check each resource directory foreach ($resDirs as $path => $hint) { // skip vendor directories if (Config::get('langcheck.skipvendor') && strpos($path, "vendor/") !== false) { continue; } // generate path relative to project root $shortPath = substr($path, strlen(base_path() . '/')); $this->info("Checking '{$shortPath}'..."); // load translation files into arrays $langDirs = File::directories($path); $languageData = array(); foreach ($langDirs as $langDir) { $langCode = basename($langDir); $arrays = File::files($langDir); foreach ($arrays as $file) { $fileName = basename($file); $languageData[$langCode][$fileName] = File::getRequire($file); } } // compare language arrays with each other and find missing entries foreach ($languageData as $langCodeA => $langArraysA) { foreach ($langArraysA as $fileNameA => $langArrayA) { foreach ($languageData as $langCodeB => $langArraysB) { if ($langCodeA == $langCodeB) { continue; } if (array_key_exists($fileNameA, $langArraysB)) { $result = $this->array_diff_key_recursive($langArrayA, $langArraysB[$fileNameA]); if (!empty($result)) { $keys = implode($this->arrayKeysRecursive($result), ', '); $this->error(" * File '{$fileNameA}':"); $this->error(" - Locale '{$langCodeB}' missing [{$keys}] existing in locale '{$langCodeA}'"); } } else { $this->error(" * File '{$fileNameA}' existing in locale '{$langCodeA}' is missing for locale '{$langCodeB}'"); } } } } $this->info(''); } }
public function load($name = 'Home', $module = true) { $_name = strtolower($name); if ($module) { $path = app_path('/Modules/' . $name . '/Languages/' . config('app.locale') . '.php'); } else { $path = base_path('resources/lang/' . config('app.locale') . '/' . $_name . '.php'); } if (!in_array($_name, $this->is_loaded) && file_exists($path)) { $language = File::getRequire($path); $this->is_loaded[] = $_name; if (!empty($language)) { $this->_lang = array_merge($this->_lang, $language); $this->lang[$_name] = $language; } unset($language); } }