Themsaid\Langman\Manager::fillKeys PHP Method

fillKeys() public method

ex. for $keys = ['name' => ['en' => 'name', 'nl' => 'naam']
public fillKeys ( string $fileName, array $keys ) : void
$fileName string
$keys array
return void
    public function fillKeys($fileName, array $keys)
    {
        $appends = [];
        foreach ($keys as $key => $values) {
            foreach ($values as $languageKey => $value) {
                $filePath = $this->path . "/{$languageKey}/{$fileName}.php";
                Arr::set($appends[$filePath], $key, $value);
            }
        }
        foreach ($appends as $filePath => $values) {
            $fileContent = $this->getFileContent($filePath, true);
            $newContent = array_replace_recursive($fileContent, $values);
            $this->writeFile($filePath, $newContent);
        }
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * 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!');
 }
All Usage Examples Of Themsaid\Langman\Manager::fillKeys