diff --git a/README.md b/README.md index 12adcc9..f0a1358 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,15 @@ php artisan translation:scan {--merge : Whether the job should overwrite or merg The command creates your `base_language` .json file in `/resources/lang` +**Add terms** + +To only add your terms run this command: +```bash +php artisan translation:add-terms {--scan : Whether the job should scan before uploading} +``` +This command doesn't remove unsused terms, so remember *NOT* to run `upload` command afterward. + + **Upload translations** To upload your translation terms to poeditor run this command: diff --git a/src/Commands/AddTerms.php b/src/Commands/AddTerms.php new file mode 100755 index 0000000..8fb472e --- /dev/null +++ b/src/Commands/AddTerms.php @@ -0,0 +1,33 @@ +info('⬆️ Preparing to upload terms'); + + if ($this->option('scan')) { + $this->call('translation:scan'); + } + + app(Translation::class)->addTerms(); + + $this->info('⬆️ Finished uploading all terms'); + } catch (Exception $e) { + $this->error($e->getMessage()); + } + } +} diff --git a/src/Translation.php b/src/Translation.php index 1f8ff71..b632723 100755 --- a/src/Translation.php +++ b/src/Translation.php @@ -153,6 +153,28 @@ public function syncTerms(): void } } + public function addTerms(): void + { + try { + $this->setupPoeditorCredentials(); + $entries = $this->getFileContent() + ->map(function ($value, $key) { + return ['term' => $key]; + }) + ->toJson(); + + $this->query('https://api.poeditor.com/v2/terms/add', [ + 'form_params' => [ + 'api_token' => $this->apiKey, + 'id' => $this->projectId, + 'data' => $entries, + ] + ], 'POST'); + } catch (Exception $e) { + throw $e; + } + } + public function syncTranslations(?array $languages = null): void { try { diff --git a/src/TranslationServiceProvider.php b/src/TranslationServiceProvider.php index 6222d49..6a29a7c 100755 --- a/src/TranslationServiceProvider.php +++ b/src/TranslationServiceProvider.php @@ -7,6 +7,7 @@ use Vemcogroup\Translation\Commands\Upload; use Vemcogroup\Translation\Commands\Download; use Vemcogroup\Translation\Commands\CreateJs; +use Vemcogroup\Translation\Commands\AddTerms; class TranslationServiceProvider extends ServiceProvider { @@ -22,6 +23,7 @@ public function boot(): void Upload::class, Download::class, CreateJs::class, + AddTerms::class, ]); } }