public function handle()
{
$locale = $this->argument('locales');
$force = $this->option('force') ? 'f' : 'n';
$sourcePath = base_path('vendor/caouecs/laravel-lang/src');
$targetPath = base_path('resources/lang/');
if (!is_dir($targetPath) || !is_writable($targetPath)) {
return $this->error('The lang path "resources/lang/" does not exist or not writable.');
}
$files = [];
$published = [];
if ($locale == 'all') {
$files = $sourcePath . '/*';
$message = 'all';
} else {
foreach (explode(',', $locale) as $filename) {
$file = $sourcePath . '/' . trim($filename);
if (!file_exists($file)) {
$this->error("lang '{$filename}' not found.");
continue;
}
$published[] = $filename;
$files[] = $file;
}
if (empty($files)) {
return;
}
$files = implode(' ', $files);
$message = json_encode($published);
}
$process = new Process("cp -r{$force} {$files} {$targetPath}");
$process->run(function ($type, $buffer) {
if (Process::ERR === $type) {
return $this->error(trim($buffer));
}
});
$type = $force == 'f' ? 'overwrite' : 'no overwrite';
$this->info("published languages <comment>({$type})</comment>: {$message}.");
}