From 69a3cfd2c6dee5ec5f2199793d3de3b308ddc7e6 Mon Sep 17 00:00:00 2001 From: Taher Odeh Date: Thu, 28 Mar 2019 17:35:42 +0200 Subject: [PATCH 1/3] Support creating missing translation files --- src/Commands/SyncCommand.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Commands/SyncCommand.php b/src/Commands/SyncCommand.php index b39a15e..30eb5fd 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') === 'true') { + $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); + } + } + } + } } /** From 248be2c87d8e1a9174f0572f300924bc751fac0c Mon Sep 17 00:00:00 2001 From: Taher Odeh Date: Thu, 28 Mar 2019 17:44:40 +0200 Subject: [PATCH 2/3] documentation --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) 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 ``` From 2ac45b460247adeff81cb34932cc58d787cf185f Mon Sep 17 00:00:00 2001 From: Taher Odeh Date: Mon, 1 Apr 2019 16:15:52 +0300 Subject: [PATCH 3/3] bug fix --- src/Commands/SyncCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/SyncCommand.php b/src/Commands/SyncCommand.php index 30eb5fd..5fd0a34 100644 --- a/src/Commands/SyncCommand.php +++ b/src/Commands/SyncCommand.php @@ -91,7 +91,7 @@ private function syncKeysFromFiles($translationFiles) } // create missing translation sections files from found keys. - if ($this->option('create') === 'true') { + if ($this->option('create')) { $missingLangFiles = array_diff( array_keys($allKeysInFiles), array_keys($translationFiles)