|
#!/usr/bin/env php |
|
<?php |
|
|
|
if ($argc <=1) { |
|
echo "Please specify a project path:\n $argv[0] /path/to/laravel/project"; |
|
exit(1); |
|
} elseif (!file_exists($argv[1])) { |
|
echo "Please specify a valid project path:\n $argv[1] does not exists"; |
|
exit(1); |
|
} elseif (!file_exists(sprintf('%s/composer.json', $argv[1])) || !property_exists((json_decode(file_get_contents(sprintf('%s/composer.json', $argv[1]))))->require, 'laravel/framework')) { |
|
echo "Please specify a valid Laravel project path:\n Laravel not found inside $argv[1]"; |
|
exit(1); |
|
} |
|
|
|
require sprintf('%s/bootstrap/autoload.php', $argv[1]); |
|
$app = require_once sprintf('%s/bootstrap/app.php', $argv[1]); |
|
$kernel = $app->make('Illuminate\Contracts\Http\Kernel'); |
|
$kernel->handle( |
|
$request = Illuminate\Http\Request::capture() |
|
); |
|
|
|
echo "Searching for localization array to convert to JSON\n"; |
|
foreach (glob(resource_path('lang/*'), GLOB_ONLYDIR) as $directory) { |
|
$lang = basename($directory); |
|
$obj = (object) []; |
|
foreach (glob(resource_path(sprintf('lang/%s/*.php', $lang))) as $file) { |
|
$obj->{basename($file, '.php')} = include($file); |
|
} |
|
|
|
file_put_contents(resource_path(sprintf('lang/%s.json', $lang)), json_encode(array_dot($obj))); |
|
printf(" lang/%s.json built\n", $lang); |
|
} |
|
|
|
echo "Searching for “trans()” calls\n"; |
|
$command = sprintf("grep --exclude-dir={public,vendor,storage,node_modules} --exclude=%s -rwl '%s' -e 'trans('", basename($argv[0]), $argv[1]); |
|
$process = new \Symfony\Component\Process\Process($command); |
|
$process->setTimeout(3600); |
|
$process->run(); |
|
|
|
$file_list = array_filter(explode("\n", $process->getOutput())); |
|
$nb_files = count($file_list); |
|
|
|
if ($nb_files > 0) { |
|
foreach ($file_list as $file) { |
|
printf(" Migrating %s\n", $file); |
|
$command = sprintf("sed -i 's/trans(/__(/g' %s", $file); |
|
$process = new \Symfony\Component\Process\Process($command); |
|
$process->run(); |
|
} |
|
printf("Migrated %d files\n", $nb_files); |
|
} else { |
|
echo " None found\n"; |
|
} |