fillKeys() public method

ex. for $keys = ['name' => ['en' => 'name', 'nl' => 'naam']
public fillKeys ( string $fileName, array $keys ) : void
$fileName string
$keys array
return void
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->info('Looking for missing translations...');
     $languages = $this->manager->languages();
     $missing = $this->getMissing($languages);
     $values = $this->collectValues($missing);
     $input = [];
     foreach ($values as $key => $value) {
         preg_match('/^([^\\.]*)\\.(.*):(.*)/', $key, $matches);
         $input[$matches[1]][$matches[2]][$matches[3]] = $value;
         $this->line("\"<fg=yellow>{$key}</>\" was set to \"<fg=yellow>{$value}</>\" successfully.");
     }
     foreach ($input as $fileName => $values) {
         $this->manager->fillKeys($fileName, $values);
     }
     $this->info('Done!');
 }
Example #2
0
 /**
  * Fill the missing keys with an empty string in the given file.
  *
  * @param string $fileName
  * @param array $foundMissingKeys
  * @param string $languageKey
  * @return void
  */
 private function fillMissingKeys($fileName, array $foundMissingKeys, $languageKey)
 {
     $missingKeys = [];
     foreach ($foundMissingKeys as $missingKey) {
         $missingKeys[$missingKey] = [$languageKey => ''];
         $this->output->writeln("\"<fg=yellow>{$fileName}.{$missingKey}.{$languageKey}</>\" was added.");
     }
     $this->manager->fillKeys($fileName, $missingKeys);
 }
 /**
  * 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]);
 }
 /**
  * Fill a translation key in all languages.
  *
  * @return void
  */
 private function fillKey()
 {
     $languages = $this->manager->languages();
     if ($this->languageKey) {
         if (!in_array($this->languageKey, $languages)) {
             $this->error(sprintf('Language (%s) could not be found!', $this->languageKey));
             return;
         }
         // If a language key was specified then we prompt for it only.
         $languages = [$this->languageKey];
     }
     $values = $this->collectValues($languages);
     $this->manager->fillKeys(str_replace($this->packageName . '::', '', $this->fileName), [$this->key => $values]);
     foreach ($values as $languageKey => $value) {
         $this->line("<fg=yellow>{$this->fileName}.{$this->key}:{$languageKey}</> was set to \"<fg=yellow>{$value}</>\" successfully.");
     }
 }