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; } }