diff --git a/README.md b/README.md index 48e781f..a9f214b 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,12 @@ php artisan langman:sync This command will look into all files in `resources/views` and `app` and find all translation keys that are not covered in your translation files, after that it appends those keys to the files with a value equal to an empty string. +### Create missing translation files from collected keys + +``` +php artisan langman:sync --create +``` + ### Filling missing translations ``` diff --git a/src/Commands/SyncCommand.php b/src/Commands/SyncCommand.php index b39a15e..5fd0a34 100644 --- a/src/Commands/SyncCommand.php +++ b/src/Commands/SyncCommand.php @@ -13,7 +13,7 @@ class SyncCommand extends Command * * @var string */ - protected $signature = 'langman:sync'; + protected $signature = 'langman:sync {--create : Create missing translation files}'; /** * The description of the console command. @@ -89,6 +89,21 @@ private function syncKeysFromFiles($translationFiles) } } } + + // create missing translation sections files from found keys. + if ($this->option('create')) { + $missingLangFiles = array_diff( + array_keys($allKeysInFiles), + array_keys($translationFiles) + ); + foreach ($missingLangFiles as $langFile) { + foreach ($translationFiles as $fileName => $languages) { + foreach ($languages as $languageKey => $path) { + $this->fillMissingKeys($langFile, $allKeysInFiles[$langFile], $languageKey); + } + } + } + } } /**