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

Additional params for import and export endpoint #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions config/loco.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,17 @@

return [
'api_key' => env('LOCO_API_KEY'),

/**
* Additional params to use for the export endpoint
* https://localise.biz/api/docs/export/exportall
*/
'export_params' => [],

/**
* Additional params to use for the import endpoint
* https://localise.biz/api/docs/import/import
*
*/
'import_params' => [],
];
10 changes: 10 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,13 @@ To publish the configuration file, run:
```sh
php artisan vendor:publish --provider="Jobilla\Loco\LocoServiceProvider"
```

There are two different endpoints used for import and export. It is possible to set different parameters on those endpoints. Parameters for export endpoint can be found [here](https://localise.biz/api/docs/export/exportall). Parameters for import endpoint can be found [here](https://localise.biz/api/docs/import/import). Those paramters can be set in configuration file of the package.

For example, this is how order parameter can be set in configuration file:

```php
'export_params' => [
'order' => 'id',
],
```
7 changes: 4 additions & 3 deletions src/Commands/DownloadTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ class DownloadTranslations extends Command
*/
public function handle(ApiClient $client, Translator $translator, FilesystemManager $storage)
{
$res = $client->exportAll([
'ext' => 'json',
]);
$res = $client->exportAll(array_merge(
config('loco.export_params', []),
['ext' => 'json']
));

$translations = $this->dropEmptyString(json_decode((string)$res, JSON_OBJECT_AS_ARRAY));
$fs = $storage->createLocalDriver(['root' => resource_path('lang')]);
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/UploadTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public function handle(ApiClient $client, Translator $translator, FilesystemMana

$this->info("Sending $locale translations to Loco...");
$locale = str_replace('_', '-', $locale);
$res = $client->import([
$res = $client->import(array_merge(config('loco.import_params', []), [
'locale' => $locale,
'ext' => 'json',
'data' => json_encode($translations)
]);
]));
$this->info("✔ $locale upload complete: {$res['message']}");
}

Expand Down