/** * Execute the console command. * * @return mixed */ public function handle() { $translationFiles = $this->manager->files(); $this->syncKeysFromFiles($translationFiles); $this->syncKeysBetweenLanguages($translationFiles); $this->info('Done!'); }
/** * Execute the console command. * * @return mixed */ public function handle() { if ($package = $this->option('package')) { $this->manager->setPathToVendorPackage($package); } $this->files = $this->manager->files(); if (empty($this->files)) { $this->warn('No language files were found!'); } $languages = $this->manager->languages(); $this->table(array_merge(['key'], $languages), $this->tableRows()); }
/** * Get an array of keys that have missing values with a hint * from another language translation file if possible. * * ex: [ ['key' => 'product.color.nl', 'hint' => 'en = "color"'] ] * * @param array $languages * @return array */ private function getMissing(array $languages) { $files = $this->manager->files(); // Array of content of all files indexed by fileName.languageKey $filesResults = []; // The final output of the method $missing = []; // Here we collect the file results foreach ($files as $fileName => $languageFiles) { foreach ($languageFiles as $languageKey => $filePath) { $filesResults[$fileName][$languageKey] = $this->manager->getFileContent($filePath); } } $values = Arr::dot($filesResults); $emptyValues = array_filter($values, function ($value) { return $value == ''; }); // Adding all keys that has values = '' foreach ($emptyValues as $dottedValue => $emptyValue) { list($fileName, $languageKey, $key) = explode('.', $dottedValue, 3); $missing[] = "{$fileName}.{$key}:{$languageKey}"; } $missing = array_merge($missing, $this->manager->getKeysExistingInALanguageButNotTheOther($values)); return $missing; }
/** * Array of requested file in different languages. * * @return array */ private function filesFromKey() { try { return $this->manager->files()[$this->file]; } catch (\ErrorException $e) { $this->error(sprintf('Language file %s.php not found!', $this->file)); return []; } }
/** * Array of requested file in different languages. * * @return array */ private function filesFromKey() { try { return $this->manager->files()[$this->fileName]; } catch (\ErrorException $e) { if ($this->confirm(sprintf('Language file %s.php not found, would you like to create it?', $this->fileName))) { $this->manager->createFile(str_replace($this->packageName . '::', '', $this->fileName)); } return []; } }
/** * Rename the given oldKey to the newKey. * * @return void */ private function renameKey() { try { list($file, $key) = explode('.', $this->argument('oldKey'), 2); } catch (\ErrorException $e) { $this->error('Could not recognize the key you want to rename.'); return; } if (Str::contains($this->argument('newKey'), '.')) { $this->error('Please provide the new key must not contain a dot.'); return; } $newKey = preg_replace('/(\\w+)$/i', $this->argument('newKey'), $key); $files = $this->manager->files()[$file]; $currentValues = []; foreach ($files as $languageKey => $filePath) { $content = Arr::dot($this->manager->getFileContent($filePath)); $currentValues[$languageKey] = isset($content[$key]) ? $content[$key] : ''; } $this->manager->removeKey($file, $key); $this->manager->fillKeys($file, [$newKey => $currentValues]); }