diff --git a/README.md b/README.md index e50349e..12adcc9 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,12 @@ To upload your translation terms to poeditor run this command: php artisan translation:upload {--scan : Whether the job should scan before uploading} ``` +You are also able to upload your local translations if you have locale changes +```bash +php artisan translation:upload {--translations=all : Upload translations for language sv,da,...} +``` + + **Download translation languages** To download languages from poeditor run this command: diff --git a/src/Commands/Upload.php b/src/Commands/Upload.php index ed60cd8..3055d7f 100755 --- a/src/Commands/Upload.php +++ b/src/Commands/Upload.php @@ -10,7 +10,7 @@ class Upload extends Command { protected $signature = 'translation:upload {--scan : Whether the job should scan before uploading} - {--translations-for-language=all : Upload translations for language sv,da,...} + {--translations=all : Upload translations for language sv,da,...} '; protected $description = 'Upload all translations to POEditor'; @@ -26,8 +26,8 @@ public function handle(): void app(Translation::class)->syncTerms(); - if ($this->hasOption('translations-for-language')) { - $language = $this->option('translations-for-language') === null ? null : explode(',', $this->option('translations-for-language')); + if ($this->hasOption('translations')) { + $language = in_array($this->option('translations'), [null, 'all'], true) ? null : explode(',', $this->option('translations')); app(Translation::class)->syncTranslations($language); } diff --git a/src/Translation.php b/src/Translation.php index 5f77834..1f8ff71 100755 --- a/src/Translation.php +++ b/src/Translation.php @@ -155,14 +155,13 @@ public function syncTerms(): void public function syncTranslations(?array $languages = null): void { - $translations = $this->getTranslations($languages); - - $this->setupPoeditorCredentials(); + try { + $this->setupPoeditorCredentials(); + $translations = $this->getTranslations($languages); - foreach ($translations as $language => $entries) { - try { + foreach ($translations as $language => $entries) { $json = collect($entries) - ->mapToGroups(function ($value, $key) { + ->mapToGroups(static function ($value, $key) { return [[ 'term' => $key, 'translation' => [ @@ -181,9 +180,9 @@ public function syncTranslations(?array $languages = null): void 'data' => $json, ] ], 'POST'); - } catch (Exception $e) { - throw $e; } + } catch (Exception $e) { + throw $e; } }