Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added autodetector feature #147

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion lib/lang.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions src/Mariuzzo/LaravelJsLocalization/Commands/LangJsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,23 @@ public function handle()
'no-lib' => $this->option('no-lib'),
'source' => $this->option('source'),
'no-sort' => $this->option('no-sort'),
'autodetect' => $this->option('autodetect'),
];


if ($options['autodetect']) {
$this->info('Autodetect enabled... If this takes too long, edit the glob\'s in config/js-localization.php to be more specific');
$usageSearchFiles = $this->generator->usageSearchFiles($this->getUsageSearchFiles());
$bar = $this->output->createProgressBar(count($usageSearchFiles));
$bar->start();
foreach ($usageSearchFiles as $file){
$this->generator->usageSearch($file);
$bar->advance();
}
$bar->finish();
$this->info("\n");
}

if ($this->generator->generate($target, $options)) {
$this->info("Created: {$target}");

Expand Down Expand Up @@ -100,6 +115,20 @@ protected function getDefaultPath()
return Config::get('localization-js.path', public_path('messages.js'));
}

/**
* Return the glob's to search.
*
* @return array
*/
protected function getUsageSearchFiles()
{
return Config::get('localization-js.usageSearchFiles', [
'public/**/*.js',
'resources/assets/**/*.js',
'resources/views/**/*',
]);
}

/**
* Return all command options.
*
Expand All @@ -113,6 +142,7 @@ protected function getOptions()
['json', 'j', InputOption::VALUE_NONE, 'Only output the messages json.', null],
['source', 's', InputOption::VALUE_REQUIRED, 'Specifying a custom source folder', null],
['no-sort', 'ns', InputOption::VALUE_NONE, 'Do not sort the messages', null],
['autodetect', 'a', InputOption::VALUE_NONE, 'Autodetect which messages to include', null],
];
}
}
Loading