Skip to content

Commit ce37503

Browse files
committed
Add new lokalise:sync command to sync a single file to by first uploading it with force replace and cleanup and then downloading it. thi s helps to debug the sync
1 parent 6a29053 commit ce37503

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/Commands/SyncFileCommand.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Bambamboole\LaravelLokalise\Commands;
4+
5+
use Bambamboole\LaravelLokalise\LocalTranslationRepository;
6+
use Bambamboole\LaravelLokalise\LokaliseClient;
7+
use Bambamboole\LaravelLokalise\LokaliseService;
8+
use Bambamboole\LaravelLokalise\Models\TranslationFile;
9+
use Illuminate\Console\Command;
10+
11+
class SyncFileCommand extends Command
12+
{
13+
protected $signature = 'lokalise:sync {file}';
14+
15+
protected $description = 'Sync local file in all locales to lokalise. Then download keys formt his file again.';
16+
17+
public function handle(LocalTranslationRepository $repo, LokaliseService $lokaliseService, LokaliseClient $client): int
18+
{
19+
$files = $repo->getTranslationFiles();
20+
$files = collect($files)
21+
->filter(fn (TranslationFile $file) => $file->file->getFilename() === $this->argument('file'))
22+
->map(fn (TranslationFile $file) => $file->file->getRealPath())
23+
->all();
24+
25+
$lokaliseService->uploadSpecificFiles($files);
26+
27+
// @TODO implement proper waiting for process form lokalise
28+
sleep(15);
29+
30+
$translations = $client->getTranslations('resources/lang/%LANG_ISO%/'.$this->argument('file'));
31+
$repo->saveTranslations($translations);
32+
33+
return self::SUCCESS;
34+
}
35+
}

src/LaravelLokaliseServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Bambamboole\LaravelLokalise\Commands\DownloadTranslationFilesCommand;
66
use Bambamboole\LaravelLokalise\Commands\InfoCommand;
7+
use Bambamboole\LaravelLokalise\Commands\SyncFileCommand;
78
use Bambamboole\LaravelLokalise\Commands\UploadTranslationFilesCommand;
89
use Illuminate\Contracts\Foundation\Application;
910
use Illuminate\Filesystem\Filesystem;
@@ -42,6 +43,7 @@ public function boot(): void
4243
InfoCommand::class,
4344
DownloadTranslationFilesCommand::class,
4445
UploadTranslationFilesCommand::class,
46+
SyncFileCommand::class,
4547
]);
4648
}
4749
}

0 commit comments

Comments
 (0)