add locale manager
This commit is contained in:
101
app/Repos/System/Locale/LocaleManagerRepo.php
Normal file
101
app/Repos/System/Locale/LocaleManagerRepo.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repos\System\Locale;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Http\Client\PendingRequest;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
class LocaleManagerRepo
|
||||
{
|
||||
/**
|
||||
* Locale app path
|
||||
*/
|
||||
protected string $localeAppPath;
|
||||
|
||||
/**
|
||||
* Locale app url
|
||||
*/
|
||||
protected string $localeAppUrl;
|
||||
|
||||
/**
|
||||
* Locale app api token
|
||||
*/
|
||||
protected string $localeAppApiToken;
|
||||
|
||||
/**
|
||||
* Files system
|
||||
*/
|
||||
protected Filesystem $fileSystem;
|
||||
|
||||
/**
|
||||
* Locale manager app
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->localeAppPath = config('app.locale_app.path');
|
||||
$this->localeAppUrl = config('app.locale_app.url');
|
||||
$this->localeAppApiToken = config('app.locale_app.api_token');
|
||||
|
||||
$this->fileSystem = new Filesystem();
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic way of new
|
||||
*/
|
||||
public static function make(): self
|
||||
{
|
||||
return new self();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run locale manager
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$this->exportTranslations()
|
||||
->syncTranslationsWithLocaleApp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Locale app translations directory
|
||||
*/
|
||||
public function localeAppTranslationsDirectory(): string
|
||||
{
|
||||
return $this->localeAppPath . DIRECTORY_SEPARATOR . 'lang';
|
||||
}
|
||||
|
||||
/**
|
||||
* Export translations to translate app
|
||||
*/
|
||||
public function exportTranslations(): self
|
||||
{
|
||||
$this->fileSystem->mirror(lang_path(), $this->localeAppTranslationsDirectory());
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync translations with locale app
|
||||
*/
|
||||
public function syncTranslationsWithLocaleApp(): self
|
||||
{
|
||||
$response = Http::acceptJson()->withHeaders([
|
||||
'Api-Token' => $this->localeAppApiToken,
|
||||
])
|
||||
->retry(
|
||||
times: 3,
|
||||
sleepMilliseconds: 50,
|
||||
throw: false,
|
||||
when: function (Exception $exception, PendingRequest $request) {
|
||||
return true;
|
||||
})
|
||||
->post(
|
||||
url: $this->localeAppUrl . '/api/import-translations',
|
||||
data: []
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ use App\Nova\Resources\Order\Card\Requisite\CardRequisite;
|
||||
use App\Nova\Resources\Order\Loan\LoanOrder;
|
||||
use App\Nova\Resources\Order\Loan\LoanPaidOffLetterOrder;
|
||||
use App\Nova\Resources\Order\Loan\LoanType;
|
||||
use App\Nova\Resources\System\Locale\LocaleManagerResource;
|
||||
use App\Nova\Resources\System\Location\Province;
|
||||
use App\Nova\Resources\System\Roles\Permission;
|
||||
use App\Nova\Resources\System\Roles\Role;
|
||||
@@ -64,6 +65,11 @@ class NovaMenuRepo
|
||||
MenuItem::resource(Province::class),
|
||||
MenuItem::resource(Branch::class),
|
||||
])->collapsedByDefault(),
|
||||
|
||||
MenuGroup::make(__('Locale'), [
|
||||
MenuItem::resource(LocaleManagerResource::class),
|
||||
])->collapsedByDefault(),
|
||||
|
||||
])->icon('cog')->collapsedByDefault(),
|
||||
|
||||
MenuSection::make(__('Backups'))
|
||||
|
||||
Reference in New Issue
Block a user