From 2cc338c41299ebf9f8bc413203e8180d20f3fcd7 Mon Sep 17 00:00:00 2001 From: "H. C. Kruse" Date: Thu, 9 May 2024 11:06:22 +0200 Subject: [PATCH 1/4] feat: Add zh_HANS locale code --- app/Models/System/Language.php | 14 ++++++++-- config/language.php | 6 ++-- ...cale_code_attribute_in_languages_table.php | 28 +++++++++++++++++++ .../seeders/System/LanguageTableSeeder.php | 13 +++++++-- 4 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 database/migrations/update/system/2024_05_09_103833_change_locale_code_attribute_in_languages_table.php diff --git a/app/Models/System/Language.php b/app/Models/System/Language.php index 382b7967f..db2fb7d3d 100644 --- a/app/Models/System/Language.php +++ b/app/Models/System/Language.php @@ -15,16 +15,26 @@ class Language extends Model { use HasFactory; + public const ENGLISH = 'en_EN'; + public const GERMAN = 'de_DE'; + public const CHINESE = 'zh_HANS'; + + public $incrementing = false; protected $primaryKey = 'locale_code'; public function scopeGerman(Builder $query): Builder { - return $query->where('local_code', 'de_DE'); + return $query->where('local_code', self::GERMAN); } public function scopeEnglish(Builder $query): Builder { - return $query->where('local_code', 'en_EN'); + return $query->where('local_code', self::ENGLISH); + } + + public function scopeChinese(Builder $query): Builder + { + return $query->where('local_code', self::CHINESE); } } diff --git a/config/language.php b/config/language.php index 5e82608b6..3d200f8ec 100644 --- a/config/language.php +++ b/config/language.php @@ -3,13 +3,15 @@ declare(strict_types=1); return [ - 'english' => 'en_EN', - 'german' => 'de_DE', + 'english' => \App\Models\System\Language::ENGLISH, + 'german' => \App\Models\System\Language::GERMAN, + 'chinese' => \App\Models\System\Language::CHINESE, // @Todo Codes need to be updated if more are added 'codes' => [ 'de_DE', 'en_EN', + 'zh_HANS', ], 'enable_galactapedia_language_links' => env('GALACTAPEDIA_LANGUAGE_LINKS', false), diff --git a/database/migrations/update/system/2024_05_09_103833_change_locale_code_attribute_in_languages_table.php b/database/migrations/update/system/2024_05_09_103833_change_locale_code_attribute_in_languages_table.php new file mode 100644 index 000000000..77fb56a56 --- /dev/null +++ b/database/migrations/update/system/2024_05_09_103833_change_locale_code_attribute_in_languages_table.php @@ -0,0 +1,28 @@ +char('locale_code', 25)->change(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('languages', static function (Blueprint $table) { + $table->char('locale_code', 5)->change(); + }); + } +}; diff --git a/database/seeders/System/LanguageTableSeeder.php b/database/seeders/System/LanguageTableSeeder.php index bd151a42b..294c6084b 100644 --- a/database/seeders/System/LanguageTableSeeder.php +++ b/database/seeders/System/LanguageTableSeeder.php @@ -18,7 +18,7 @@ class LanguageTableSeeder extends Seeder */ public function run(): void { - if (DB::table('languages')->where('locale_code', 'en_EN')->exists()) { + if (DB::table('languages')->where('locale_code', Language::ENGLISH)->exists()) { return; } @@ -26,14 +26,21 @@ public function run(): void DB::table('languages')->insert( [ - 'locale_code' => 'en_EN', + 'locale_code' => Language::ENGLISH, 'created_at' => $now, 'updated_at' => $now, ] ); DB::table('languages')->insert( [ - 'locale_code' => 'de_DE', + 'locale_code' => Language::GERMAN, + 'created_at' => $now, + 'updated_at' => $now, + ] + ); + DB::table('languages')->insert( + [ + 'locale_code' => Language::CHINESE, 'created_at' => $now, 'updated_at' => $now, ] From afd760b8aaac6b59139bac022c44bc9d7452c5b1 Mon Sep 17 00:00:00 2001 From: "H. C. Kruse" Date: Thu, 9 May 2024 11:06:38 +0200 Subject: [PATCH 2/4] refactor: Use locale constants --- app/Console/Commands/SC/ImportMissions.php | 6 +-- .../Galactapedia/TranslateArticles.php | 3 +- .../Controllers/Api/AbstractApiController.php | 38 +++++++-------- .../Api/V2/AbstractApiV2Controller.php | 6 ++- .../Resources/AbstractTranslationResource.php | 12 +++-- .../Resources/SC/Vehicle/VehicleResource.php | 5 +- app/Http/Resources/TranslationCollection.php | 2 +- .../Resources/TranslationResourceFactory.php | 6 +-- .../Rsi/CommLink/Import/ImportCommLink.php | 48 +++++-------------- .../CommLink/Translate/TranslateCommLinks.php | 5 +- app/Jobs/SC/Import/Item.php | 3 +- .../Galactapedia/ImportArticle.php | 24 ++++------ .../Starmap/Import/ImportCelestialObject.php | 13 ++--- .../Starmap/Import/ImportStarsystem.php | 12 ++--- .../Starmap/Translate/TranslateSystems.php | 9 ++-- .../Wiki/CommLink/CreateCommLinkWikiPage.php | 24 +++------- .../Translation/AbstractHasTranslations.php | 12 ++++- .../CommLink/CommLinkTranslationFactory.php | 5 +- .../ManufacturerTranslationFactory.php | 5 +- lang/de.json | 1 + lang/en.json | 1 + 21 files changed, 99 insertions(+), 141 deletions(-) diff --git a/app/Console/Commands/SC/ImportMissions.php b/app/Console/Commands/SC/ImportMissions.php index 82981a6cf..5b8ab7022 100644 --- a/app/Console/Commands/SC/ImportMissions.php +++ b/app/Console/Commands/SC/ImportMissions.php @@ -8,7 +8,7 @@ use App\Models\SC\Reputation\Reward; use App\Models\SC\Reputation\Scope; use App\Models\SC\Reputation\Standing; -use Exception; +use App\Models\System\Language; use Illuminate\Console\Command; use Illuminate\Support\Facades\File; @@ -168,7 +168,7 @@ private function importGiver(): void if (! empty($data['description'])) { $giver->translations()->updateOrCreate([ - 'locale_code' => 'en_EN', + 'locale_code' => Language::ENGLISH, ], [ 'translation' => $data['description'], ]); @@ -240,7 +240,7 @@ private function importMissions(): void if (! str_starts_with($data['description'], '@')) { $mission->translations()->updateOrCreate([ - 'locale_code' => 'en_EN', + 'locale_code' => Language::ENGLISH, ], [ 'translation' => $data['description'], ]); diff --git a/app/Console/Commands/StarCitizen/Galactapedia/TranslateArticles.php b/app/Console/Commands/StarCitizen/Galactapedia/TranslateArticles.php index e6ca15a99..466c12f71 100644 --- a/app/Console/Commands/StarCitizen/Galactapedia/TranslateArticles.php +++ b/app/Console/Commands/StarCitizen/Galactapedia/TranslateArticles.php @@ -7,6 +7,7 @@ use App\Console\Commands\AbstractQueueCommand; use App\Jobs\StarCitizen\Galactapedia\TranslateArticle; use App\Models\StarCitizen\Galactapedia\Article; +use App\Models\System\Language; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Collection; @@ -39,7 +40,7 @@ public function handle(): int 'translations', function (Builder $query) { $query - ->where('locale_code', 'en_EN') + ->where('locale_code', Language::ENGLISH) ->whereRaw("translation <> ''"); } ) diff --git a/app/Http/Controllers/Api/AbstractApiController.php b/app/Http/Controllers/Api/AbstractApiController.php index 6ddff0b78..9f58f5e77 100644 --- a/app/Http/Controllers/Api/AbstractApiController.php +++ b/app/Http/Controllers/Api/AbstractApiController.php @@ -6,6 +6,7 @@ use App\Events\ApiRouteCalled; use App\Http\Controllers\Controller; +use App\Models\System\Language; use App\Transformers\Api\LocalizableTransformerInterface; use App\Transformers\Api\V1\AbstractV1Transformer as V1Transformer; use Carbon\Carbon; @@ -62,8 +63,9 @@ description: 'Localization to use.', collectionFormat: 'csv', enum: [ - 'de_DE', - 'en_EN', + Language::ENGLISH, + Language::GERMAN, + Language::CHINESE, ] ), )] @@ -131,7 +133,7 @@ abstract class AbstractApiController extends Controller /** * AbstractApiController constructor. * - * @param Request $request API Request + * @param Request $request API Request */ public function __construct(Request $request) { @@ -158,12 +160,12 @@ protected function processRequestParams(): void */ private function processLimit(): void { - if ($this->request->has(self::LIMIT) && null !== $this->request->get(self::LIMIT, null)) { - $itemLimit = (int)$this->request->get(self::LIMIT); + if ($this->request->has(self::LIMIT) && $this->request->get(self::LIMIT, null) !== null) { + $itemLimit = (int) $this->request->get(self::LIMIT); if ($itemLimit > 0) { $this->limit = $itemLimit; - } elseif (0 === $itemLimit) { + } elseif ($itemLimit === 0) { $this->limit = 0; } else { $this->errors[self::LIMIT] = static::INVALID_LIMIT_STRING; @@ -176,15 +178,13 @@ private function processLimit(): void */ private function processLocale(): void { - if ($this->request->has(self::LOCALE) && null !== $this->request->get(self::LOCALE, null)) { + if ($this->request->has(self::LOCALE) && $this->request->get(self::LOCALE, null) !== null) { $this->setLocale($this->request->get(self::LOCALE)); } } /** * Set the Locale - * - * @param string $localeCode */ protected function setLocale(string $localeCode): void { @@ -215,9 +215,7 @@ protected function disablePagination(): self * Creates the API Response, Collection if no pagination, Paginator if a limit is set * Item if a single model is given * - * @param Builder|Model|Collection $query - * - * @return Response + * @param Builder|Model|Collection $query */ protected function getResponse($query): Response { @@ -253,7 +251,6 @@ protected function getResponse($query): Response 'forwarded-for' => $this->request->header('X-Forwarded-For', '127.0.0.1'), ]); - $resource = new \League\Fractal\Resource\Collection( $query->get(), $this->transformer @@ -275,11 +272,11 @@ protected function getMeta(): array 'processed_at' => Carbon::now()->toDateTimeString(), ]; - if (!empty($this->errors)) { + if (! empty($this->errors)) { $meta['errors'] = $this->errors; } - if (!empty($this->transformer->getAvailableIncludes())) { + if (! empty($this->transformer->getAvailableIncludes())) { $meta['valid_relations'] = array_map( 'Illuminate\Support\Str::snake', $this->transformer->getAvailableIncludes() @@ -294,7 +291,7 @@ protected function getMeta(): array */ private function processIncludes(): void { - if ($this->request->has('include') && null !== $this->request->get('include', null)) { + if ($this->request->has('include') && $this->request->get('include', null) !== null) { $this->checkIncludes($this->request->get('include', [])); } } @@ -302,11 +299,11 @@ private function processIncludes(): void /** * Processes the given 'include' model relation key * - * @param string|array $relations + * @param string|array $relations */ protected function checkIncludes($relations): void { - if (!is_array($relations)) { + if (! is_array($relations)) { $relations = explode(',', $relations); } @@ -322,7 +319,7 @@ static function ($relation) { ) ->each( function ($relation) { - if (!in_array($relation, $this->transformer->getAvailableIncludes(), true)) { + if (! in_array($relation, $this->transformer->getAvailableIncludes(), true)) { $this->errors['include'][] = sprintf(static::INVALID_RELATION_STRING, Str::snake($relation)); } } @@ -331,9 +328,6 @@ function ($relation) { /** * Cleans the name for query use - * - * @param string $name - * @return string */ protected function cleanQueryName(string $name): string { diff --git a/app/Http/Controllers/Api/V2/AbstractApiV2Controller.php b/app/Http/Controllers/Api/V2/AbstractApiV2Controller.php index df583a982..9d98e9142 100644 --- a/app/Http/Controllers/Api/V2/AbstractApiV2Controller.php +++ b/app/Http/Controllers/Api/V2/AbstractApiV2Controller.php @@ -6,6 +6,7 @@ use App\Events\ApiRouteCalled; use App\Http\Controllers\Controller; +use App\Models\System\Language; use Illuminate\Http\Request; use OpenApi\Attributes as OA; use Spatie\QueryBuilder\AllowedInclude; @@ -48,8 +49,9 @@ schema: new OA\Schema( description: 'Localization to use.', enum: [ - 'de_DE', - 'en_EN', + Language::ENGLISH, + Language::GERMAN, + Language::CHINESE, ] ), )] diff --git a/app/Http/Resources/AbstractTranslationResource.php b/app/Http/Resources/AbstractTranslationResource.php index 2f87e9513..a1c5a34b1 100644 --- a/app/Http/Resources/AbstractTranslationResource.php +++ b/app/Http/Resources/AbstractTranslationResource.php @@ -19,8 +19,9 @@ title: 'Grouped Translations', description: 'Translations of an entity', properties: [ - new OA\Property(property: 'en_EN', type: 'string'), - new OA\Property(property: 'de_DE', type: 'string'), + new OA\Property(property: Language::ENGLISH, type: 'string'), + new OA\Property(property: Language::GERMAN, type: 'string'), + new OA\Property(property: Language::CHINESE, type: 'string'), ], type: 'object' )] @@ -38,6 +39,7 @@ protected function getTranslation($model, Request $request, $translationKey = 't $translations = $model->translationsCollection(); $locale = $request->get('locale'); + if (! empty($locale)) { return $this->getSingleTranslation($translations, $request->get('locale'), $translationKey); } @@ -45,7 +47,7 @@ protected function getTranslation($model, Request $request, $translationKey = 't $translations = $translations->map( function ($translation) use ($translationKey, $translations) { if ($translation instanceof Language) { - return $this->getSingleTranslation($translations, 'en_EN', $translationKey); + return $this->getSingleTranslation($translations, Language::ENGLISH, $translationKey); } return $this->getSingleTranslation($translation, $translationKey); @@ -75,8 +77,8 @@ private function getSingleTranslation($translations, string $locale, $translatio if ($translations->has($locale) && ! $translations->get($locale) instanceof Language) { $translation = $translations->get($locale)[$translationKey]; - } elseif ($translations->has('en_EN')) { - $translation = $translations->get('en_EN')[$translationKey]; + } elseif ($translations->has(Language::ENGLISH)) { + $translation = $translations->get(Language::ENGLISH)[$translationKey]; } return $translation; diff --git a/app/Http/Resources/SC/Vehicle/VehicleResource.php b/app/Http/Resources/SC/Vehicle/VehicleResource.php index 50941f1a6..603830bb3 100644 --- a/app/Http/Resources/SC/Vehicle/VehicleResource.php +++ b/app/Http/Resources/SC/Vehicle/VehicleResource.php @@ -8,6 +8,7 @@ use App\Http\Resources\SC\ItemSpecification\ArmorResource; use App\Http\Resources\SC\Shop\ShopResource; use App\Http\Resources\TranslationResourceFactory; +use App\Models\System\Language; use Illuminate\Http\Request; use Illuminate\Support\Str; use OpenApi\Attributes as OA; @@ -353,10 +354,10 @@ public function toArray(Request $request): array 'armor' => new ArmorResource($this->armor), ]), 'foci' => [ - ['en_EN' => $this->career], + [Language::ENGLISH => $this->career], ], 'type' => [ - 'en_EN' => $this->role, + Language::ENGLISH => $this->role, ], 'description' => TranslationResourceFactory::getTranslationResource($request, $this), 'size_class' => $this->size, diff --git a/app/Http/Resources/TranslationCollection.php b/app/Http/Resources/TranslationCollection.php index bf7b8d8b7..3b5447277 100644 --- a/app/Http/Resources/TranslationCollection.php +++ b/app/Http/Resources/TranslationCollection.php @@ -15,7 +15,7 @@ class TranslationCollection extends ResourceCollection * @param Request $request * @return array */ - public function toArray($request): array + public function toArray(Request $request): array { $out = []; foreach ($this->collection as $translation) { diff --git a/app/Http/Resources/TranslationResourceFactory.php b/app/Http/Resources/TranslationResourceFactory.php index fb1bc00b2..651112dfc 100644 --- a/app/Http/Resources/TranslationResourceFactory.php +++ b/app/Http/Resources/TranslationResourceFactory.php @@ -4,6 +4,7 @@ namespace App\Http\Resources; +use App\Models\System\Language; use App\Models\System\Translation\AbstractHasTranslations; use Illuminate\Http\Request; use Illuminate\Http\Resources\MissingValue; @@ -12,8 +13,7 @@ class TranslationResourceFactory { /** - * @param Request $request - * @param AbstractBaseResource|AbstractHasTranslations|MissingValue $model + * @param AbstractBaseResource|AbstractHasTranslations|MissingValue $model * @return TranslationCollection|mixed */ public static function getTranslationResource(Request $request, $model): mixed @@ -33,7 +33,7 @@ public static function getTranslationResource(Request $request, $model): mixed $transformed = $collection->toArray($request); if ($request->has('locale')) { - return $transformed[$request->get('locale')] ?? $transformed['en_EN'] ?? new MissingValue(); + return $transformed[$request->get('locale')] ?? $transformed[Language::ENGLISH] ?? new MissingValue(); } return $collection; diff --git a/app/Jobs/Rsi/CommLink/Import/ImportCommLink.php b/app/Jobs/Rsi/CommLink/Import/ImportCommLink.php index 1d0f001d2..d26a444a8 100644 --- a/app/Jobs/Rsi/CommLink/Import/ImportCommLink.php +++ b/app/Jobs/Rsi/CommLink/Import/ImportCommLink.php @@ -7,6 +7,7 @@ use App\Jobs\Rsi\CommLink\Download\DownloadCommLink; use App\Models\Rsi\CommLink\CommLink; use App\Models\Rsi\CommLink\CommLinksChanged; +use App\Models\System\Language; use App\Services\Parser\CommLink\Content; use App\Services\Parser\CommLink\Image; use App\Services\Parser\CommLink\Link; @@ -55,30 +56,22 @@ class ImportCommLink implements ShouldQueue */ private string $file; - /** - * @var CommLink|null - */ private ?CommLink $commLinkModel; /** * True if the given file content should be imported into the comm link model. - * - * @var bool */ private bool $forceImport; - /** - * @var Crawler - */ private Crawler $crawler; /** * Create a new job instance. * - * @param int $id Comm-Link ID - * @param string $file Current File Name - * @param CommLink|null $commLink Optional Comm-Link Model to update - * @param bool $forceImport Flag to Force Import from current file + * @param int $id Comm-Link ID + * @param string $file Current File Name + * @param CommLink|null $commLink Optional Comm-Link Model to update + * @param bool $forceImport Flag to Force Import from current file */ public function __construct(int $id, string $file, ?CommLink $commLink = null, bool $forceImport = false) { @@ -91,7 +84,6 @@ public function __construct(int $id, string $file, ?CommLink $commLink = null, b /** * Execute the job. * - * @return void * * @throws FileNotFoundException */ @@ -102,8 +94,8 @@ public function handle(): void [ 'id' => $this->commLinkId, 'file' => $this->file, - 'comm_link_already_in_db' => null !== $this->commLinkModel, - 'force_import' => true === $this->forceImport, + 'comm_link_already_in_db' => $this->commLinkModel !== null, + 'force_import' => $this->forceImport === true, ] ); @@ -119,13 +111,13 @@ public function handle(): void $subscribers = $this->crawler->filter(self::SUBSCRIBERS_SELECTOR); $specialPage = $this->crawler->filter(self::SPECIAL_PAGE_SELECTOR); - if (0 === $post->count() && 0 === $subscribers->count() && 0 === $specialPage->count()) { + if ($post->count() === 0 && $subscribers->count() === 0 && $specialPage->count() === 0) { app('Log')::info("Comm-Link with id {$this->commLinkId} has no content"); return; } - if (null === $this->commLinkModel || $this->forceImport) { + if ($this->commLinkModel === null || $this->forceImport) { $this->createCommLink(); // Updates or Creates } else { $this->checkCommLinkForChanges(); @@ -172,8 +164,6 @@ private function createCommLink(): void /** * Creates the Comm-Link Dara Array from Metadata. - * - * @return array */ private function getCommLinkData(): array { @@ -201,15 +191,13 @@ private function getCommLinkData(): array /** * Adds or Updates the default english Translation to the Comm-Link. - * - * @param CommLink $commLink */ private function addEnglishCommLinkTranslation(CommLink $commLink): void { $contentParser = new Content($this->crawler); $commLink->translations()->updateOrCreate( [ - 'locale_code' => 'en_EN', + 'locale_code' => Language::ENGLISH, ], [ 'translation' => $contentParser->getContent(), @@ -220,8 +208,6 @@ private function addEnglishCommLinkTranslation(CommLink $commLink): void /** * Syncs extracted Comm-Link Image Ids. - * - * @param CommLink $commLink */ private function syncImageIds(CommLink $commLink): void { @@ -230,9 +216,7 @@ private function syncImageIds(CommLink $commLink): void } /** - * Syncs extrated Comm-Link Link Ids. - * - * @param CommLink $commLink + * Syncs extracted Comm-Link Link Ids. */ private function syncLinkIds(CommLink $commLink): void { @@ -250,7 +234,7 @@ private function checkCommLinkForChanges(): void if ($this->contentHasChanged()) { $hadContent = true; - if (null === optional($this->commLinkModel->english())->translation) { + if (optional($this->commLinkModel->english())->translation === null) { $hadContent = false; } else { // Don't update the current File if Content has Changed and Translation is not null @@ -284,8 +268,6 @@ private function checkCommLinkForChanges(): void /** * Checks if Local Content is Equal to DB Content. - * - * @return bool */ private function contentHasChanged(): bool { @@ -296,8 +278,6 @@ private function contentHasChanged(): bool /** * Returns the first file in a comm-link folder or null - * - * @return string|null */ private function getFirstCommLinkFileName(): ?string { @@ -308,10 +288,6 @@ private function getFirstCommLinkFileName(): ?string /** * Creates a timestamp from a comm-link filename - * - * @param string $file - * - * @return string|null */ private function createTimestampFromFile(string $file): ?string { diff --git a/app/Jobs/Rsi/CommLink/Translate/TranslateCommLinks.php b/app/Jobs/Rsi/CommLink/Translate/TranslateCommLinks.php index f7b6d5aa6..4b277c051 100644 --- a/app/Jobs/Rsi/CommLink/Translate/TranslateCommLinks.php +++ b/app/Jobs/Rsi/CommLink/Translate/TranslateCommLinks.php @@ -5,6 +5,7 @@ namespace App\Jobs\Rsi\CommLink\Translate; use App\Models\Rsi\CommLink\CommLink; +use App\Models\System\Language; use App\Traits\Jobs\GetCommLinkWikiPageInfoTrait as GetCommLinkWikiPageInfo; use App\Traits\LoginWikiBotAccountTrait as LoginWikiBotAccount; use Illuminate\Bus\Queueable; @@ -57,7 +58,7 @@ public function handle(): void CommLink::query()->whereHas( 'translations', function (Builder $query) { - $query->where('locale_code', 'en_EN')->whereRaw("translation <> ''"); + $query->where('locale_code', Language::ENGLISH)->whereRaw("translation <> ''"); } ) ->whereIn('cig_id', $this->commLinkIds) @@ -69,7 +70,7 @@ function (Collection $commLinks) { } catch (RuntimeException $e) { app('Log')::error($e->getMessage()); - if (strpos($e->getMessage(), 'Guru Meditation') !== false) { + if (str_contains($e->getMessage(), 'Guru Meditation')) { $this->release(60); } else { $this->fail($e); diff --git a/app/Jobs/SC/Import/Item.php b/app/Jobs/SC/Import/Item.php index d58c006e0..d71540474 100644 --- a/app/Jobs/SC/Import/Item.php +++ b/app/Jobs/SC/Import/Item.php @@ -12,6 +12,7 @@ use App\Models\SC\Item\ItemType; use App\Models\SC\Item\Tag; use App\Models\SC\Manufacturer; +use App\Models\System\Language; use App\Services\ManufacturerFixer; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; @@ -68,7 +69,7 @@ public function handle(): void if (! empty($this->data['description'])) { $itemModel->translations()->updateOrCreate([ - 'locale_code' => 'en_EN', + 'locale_code' => Language::ENGLISH, ], [ 'translation' => $this->data['description'], ]); diff --git a/app/Jobs/StarCitizen/Galactapedia/ImportArticle.php b/app/Jobs/StarCitizen/Galactapedia/ImportArticle.php index b66c748ec..666f749be 100644 --- a/app/Jobs/StarCitizen/Galactapedia/ImportArticle.php +++ b/app/Jobs/StarCitizen/Galactapedia/ImportArticle.php @@ -9,6 +9,7 @@ use App\Models\StarCitizen\Galactapedia\Category; use App\Models\StarCitizen\Galactapedia\Tag; use App\Models\StarCitizen\Galactapedia\Template; +use App\Models\System\Language; use App\Traits\CreateRelationChangelogTrait; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; @@ -19,19 +20,18 @@ class ImportArticle extends AbstractBaseDownloadData implements ShouldQueue { + use CreateRelationChangelogTrait; use Dispatchable; use InteractsWithQueue; use Queueable; use SerializesModels; - use CreateRelationChangelogTrait; private string $articleId; + private Article $article; /** * Create a new job instance. - * - * @param string $articleId */ public function __construct(string $articleId) { @@ -42,15 +42,13 @@ public function __construct(string $articleId) /** * Execute the job. - * - * @return void */ public function handle(): void { $result = $this->makeClient()->post('galactapedia/graphql', [ - 'query' => << <<<'QUERY' +query ArticleByID($query: ID!) { + Article(id: $query) { id title slug @@ -90,7 +88,7 @@ public function handle(): void $result = $result->json() ?? []; - if (!isset($result['data']['Article'])) { + if (! isset($result['data']['Article'])) { return; } @@ -111,7 +109,7 @@ public function handle(): void $this->article->translations()->updateOrCreate( [ - 'locale_code' => 'en_EN', + 'locale_code' => Language::ENGLISH, ], [ 'translation' => Article::normalizeContent($data['body']), @@ -130,7 +128,6 @@ public function handle(): void /** * Syncs all article templates * - * @param array $data * * @return array Changed templates */ @@ -159,7 +156,6 @@ private function syncTemplates(array $data): array /** * Syncs all article categories * - * @param array $data * * @return array Changed categories */ @@ -191,7 +187,6 @@ private function syncCategories(array $data): array /** * Syncs all article tags * - * @param array $data * * @return array Changed tags */ @@ -223,7 +218,6 @@ private function syncTags(array $data): array /** * Syncs all related articles * - * @param array $data * * @return array changed data */ @@ -250,8 +244,6 @@ private function syncRelatedArticles(array $data): array /** * Checks if an article with a given title exists under multiple ids * if so, the older article will be disabled - * - * @param array $data */ private function disableDuplicates(array $data): void { diff --git a/app/Jobs/StarCitizen/Starmap/Import/ImportCelestialObject.php b/app/Jobs/StarCitizen/Starmap/Import/ImportCelestialObject.php index 7067f291c..9cf3b2d10 100644 --- a/app/Jobs/StarCitizen/Starmap/Import/ImportCelestialObject.php +++ b/app/Jobs/StarCitizen/Starmap/Import/ImportCelestialObject.php @@ -5,6 +5,7 @@ namespace App\Jobs\StarCitizen\Starmap\Import; use App\Models\StarCitizen\Starmap\CelestialObject\CelestialObject as CelestialObjectModel; +use App\Models\System\Language; use App\Services\Parser\Starmap\Affiliation; use App\Services\Parser\Starmap\CelestialSubtype; use Illuminate\Bus\Queueable; @@ -24,11 +25,6 @@ class ImportCelestialObject implements ShouldQueue use Queueable; use SerializesModels; - protected const LANGUAGE_EN = 'en_EN'; - - /** - * @var Collection - */ protected Collection $rawData; /** @@ -39,8 +35,7 @@ class ImportCelestialObject implements ShouldQueue /** * Create a new job instance. * - * @param array|Collection $rawData - * @param int $starsystemId + * @param array|Collection $rawData */ public function __construct($rawData, int $starsystemId) { @@ -50,8 +45,6 @@ public function __construct($rawData, int $starsystemId) /** * Execute the job. - * - * @return void */ public function handle(): void { @@ -75,7 +68,7 @@ public function handle(): void $celestialObject->translations()->updateOrCreate( [ 'celestial_object_id' => $celestialObject->id, - 'locale_code' => self::LANGUAGE_EN, + 'locale_code' => Language::ENGLISH, ], [ 'translation' => $description, diff --git a/app/Jobs/StarCitizen/Starmap/Import/ImportStarsystem.php b/app/Jobs/StarCitizen/Starmap/Import/ImportStarsystem.php index 3b4f1540c..988b0a586 100644 --- a/app/Jobs/StarCitizen/Starmap/Import/ImportStarsystem.php +++ b/app/Jobs/StarCitizen/Starmap/Import/ImportStarsystem.php @@ -5,6 +5,7 @@ namespace App\Jobs\StarCitizen\Starmap\Import; use App\Models\StarCitizen\Starmap\Starsystem\Starsystem; +use App\Models\System\Language; use App\Services\Parser\Starmap\Affiliation; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; @@ -23,17 +24,12 @@ class ImportStarsystem implements ShouldQueue use Queueable; use SerializesModels; - protected const LANGUAGE_EN = 'en_EN'; - - /** - * @var Collection - */ protected Collection $rawData; /** * Create a new job instance. * - * @param array|Collection $rawData + * @param array|Collection $rawData */ public function __construct($rawData) { @@ -42,8 +38,6 @@ public function __construct($rawData) /** * Execute the job. - * - * @return void */ public function handle(): void { @@ -62,7 +56,7 @@ public function handle(): void $starsystem->translations()->updateOrCreate( [ 'starsystem_id' => $starsystem->id, - 'locale_code' => self::LANGUAGE_EN, + 'locale_code' => Language::ENGLISH, ], [ 'translation' => $description, diff --git a/app/Jobs/StarCitizen/Starmap/Translate/TranslateSystems.php b/app/Jobs/StarCitizen/Starmap/Translate/TranslateSystems.php index c308af235..4f6c54cbd 100644 --- a/app/Jobs/StarCitizen/Starmap/Translate/TranslateSystems.php +++ b/app/Jobs/StarCitizen/Starmap/Translate/TranslateSystems.php @@ -5,6 +5,7 @@ namespace App\Jobs\StarCitizen\Starmap\Translate; use App\Models\StarCitizen\Starmap\Starsystem\Starsystem; +use App\Models\System\Language; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Database\Eloquent\Builder; @@ -32,8 +33,6 @@ class TranslateSystems implements ShouldQueue /** * Execute the job. - * - * @return void */ public function handle(): void { @@ -42,7 +41,7 @@ public function handle(): void Starsystem::query()->whereHas( 'translations', function (Builder $query) { - $query->where('locale_code', 'en_EN')->whereRaw("translation <> ''"); + $query->where('locale_code', Language::ENGLISH)->whereRaw("translation <> ''"); } ) ->chunk( @@ -50,7 +49,7 @@ function (Builder $query) { function (Collection $systems) { $systems->each( function (Starsystem $starsystem) { - if (null !== optional($starsystem->german())->translation) { + if (optional($starsystem->german())->translation !== null) { return; } @@ -78,7 +77,7 @@ function (Starsystem $starsystem) { app('Log')::warning($e->getMessage()); return; - } catch (CallException | AuthenticationException | InvalidArgumentException $e) { + } catch (CallException|AuthenticationException|InvalidArgumentException $e) { app('Log')::warning( sprintf('%s: %s', 'Translation failed with Message', $e->getMessage()) ); diff --git a/app/Jobs/Wiki/CommLink/CreateCommLinkWikiPage.php b/app/Jobs/Wiki/CommLink/CreateCommLinkWikiPage.php index 9116dea12..2adec9a62 100644 --- a/app/Jobs/Wiki/CommLink/CreateCommLinkWikiPage.php +++ b/app/Jobs/Wiki/CommLink/CreateCommLinkWikiPage.php @@ -6,6 +6,7 @@ use App\Jobs\Wiki\ApproveRevisions; use App\Models\Rsi\CommLink\CommLink; +use App\Models\System\Language; use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\GuzzleException; use Illuminate\Bus\Queueable; @@ -27,14 +28,8 @@ class CreateCommLinkWikiPage implements ShouldQueue use Queueable; use SerializesModels; - /** - * @var CommLink - */ private CommLink $commLink; - /** - * @var string - */ private string $template; /** @@ -45,9 +40,7 @@ class CreateCommLinkWikiPage implements ShouldQueue /** * Create a new job instance. * - * @param CommLink $commLink - * @param string $token - * @param string $template The Template to include before every translation + * @param string $template The Template to include before every translation */ public function __construct(CommLink $commLink, string $token, string $template) { @@ -58,24 +51,21 @@ public function __construct(CommLink $commLink, string $token, string $template) /** * Execute the job. - * - * @return void */ public function handle(): void { $this->createCommLinkPage(config('services.wiki_translations.locale'), "Comm-Link:{$this->commLink->cig_id}"); if (config('services.wiki_translations.create_english_subpage') === true) { - $this->createCommLinkPage('en_EN', "Comm-Link:{$this->commLink->cig_id}/en"); + $this->createCommLinkPage(Language::ENGLISH, "Comm-Link:{$this->commLink->cig_id}/en"); } } /** * Handle the actual creation * - * @param string $language Text language - * @param string $title MediaWiki Page Title - * @return void + * @param string $language Text language + * @param string $title MediaWiki Page Title */ private function createCommLinkPage(string $language, string $title): void { @@ -88,7 +78,7 @@ private function createCommLinkPage(string $language, string $title): void $text = optional($this->commLink->english())->translation; } - if ($text !== null && !Normalizer::isNormalized($text)) { + if ($text !== null && ! Normalizer::isNormalized($text)) { $text = Normalizer::normalize($text); } @@ -113,7 +103,7 @@ private function createCommLinkPage(string $language, string $title): void $this->release(60); return; - } catch (GuzzleException | RuntimeException $e) { + } catch (GuzzleException|RuntimeException $e) { app('Log')::error('Could not get an CSRF Token', $e->getResponse()->getErrors()); $this->fail($e); diff --git a/app/Models/System/Translation/AbstractHasTranslations.php b/app/Models/System/Translation/AbstractHasTranslations.php index 2169cac90..1cd6ae6e6 100644 --- a/app/Models/System/Translation/AbstractHasTranslations.php +++ b/app/Models/System/Translation/AbstractHasTranslations.php @@ -30,7 +30,7 @@ abstract public function translations(); */ public function english(): ?Model { - return $this->translations->keyBy(self::LOCALE_CODE)->get('en_EN', null); + return $this->translations->keyBy(self::LOCALE_CODE)->get(Language::ENGLISH, null); } /** @@ -38,7 +38,15 @@ public function english(): ?Model */ public function german(): ?Model { - return $this->translations->keyBy(self::LOCALE_CODE)->get('de_DE', null); + return $this->translations->keyBy(self::LOCALE_CODE)->get(Language::GERMAN, null); + } + + /** + * @return Model|null + */ + public function chinese(): ?Model + { + return $this->translations->keyBy(self::LOCALE_CODE)->get(Language::CHINESE, null); } public function localeCode(): BelongsTo diff --git a/database/factories/Rsi/CommLink/CommLinkTranslationFactory.php b/database/factories/Rsi/CommLink/CommLinkTranslationFactory.php index 92ace1fc1..00932c14b 100644 --- a/database/factories/Rsi/CommLink/CommLinkTranslationFactory.php +++ b/database/factories/Rsi/CommLink/CommLinkTranslationFactory.php @@ -5,6 +5,7 @@ namespace Database\Factories\Rsi\CommLink; use App\Models\Rsi\CommLink\CommLinkTranslation; +use App\Models\System\Language; use Illuminate\Database\Eloquent\Factories\Factory; class CommLinkTranslationFactory extends Factory @@ -24,7 +25,7 @@ class CommLinkTranslationFactory extends Factory public function definition() { return [ - 'locale_code' => 'en_EN', + 'locale_code' => Language::ENGLISH, 'translation' => $this->faker->randomHtml(2, 3), ]; } @@ -34,7 +35,7 @@ public function german() return $this->state( function (array $attributes) { return [ - 'locale_code' => 'de_DE', + 'locale_code' => Language::GERMAN, 'translation' => $this->faker->randomHtml(2, 3), ]; } diff --git a/database/factories/StarCitizen/Manufacturer/ManufacturerTranslationFactory.php b/database/factories/StarCitizen/Manufacturer/ManufacturerTranslationFactory.php index c9ae5e78a..3e15feefe 100644 --- a/database/factories/StarCitizen/Manufacturer/ManufacturerTranslationFactory.php +++ b/database/factories/StarCitizen/Manufacturer/ManufacturerTranslationFactory.php @@ -5,6 +5,7 @@ namespace Database\Factories\StarCitizen\Manufacturer; use App\Models\StarCitizen\Manufacturer\ManufacturerTranslation; +use App\Models\System\Language; use Illuminate\Database\Eloquent\Factories\Factory; class ManufacturerTranslationFactory extends Factory @@ -24,7 +25,7 @@ class ManufacturerTranslationFactory extends Factory public function definition() { return [ - 'locale_code' => 'en_EN', + 'locale_code' => Language::ENGLISH, 'known_for' => 'Lorem Ipsum', 'description' => 'Lorem Ipsum dolor sit amet', ]; @@ -35,7 +36,7 @@ public function german() return $this->state( function (array $attributes) { return [ - 'locale_code' => 'de_DE', + 'locale_code' => Language::GERMAN, 'known_for' => 'Deutsches Lorem Ipsum', 'description' => 'Deutsches Lorem Ipsum', ]; diff --git a/lang/de.json b/lang/de.json index 9b40c7632..2c3640aa6 100644 --- a/lang/de.json +++ b/lang/de.json @@ -1,6 +1,7 @@ { "de_DE": "Deutsch", "en_EN": "Englisch", + "zh_HANS": "Chinesisch", "created_at": "Erstelldatum", "translation": "Übersetzung", diff --git a/lang/en.json b/lang/en.json index 861ed25d3..1975f5c32 100644 --- a/lang/en.json +++ b/lang/en.json @@ -1,6 +1,7 @@ { "de_DE": "German", "en_EN": "English", + "zh_HANS": "Chinese", "API": "API", From 0f452bc492931e1ad06a60d2525d8850aaf75203 Mon Sep 17 00:00:00 2001 From: "H. C. Kruse" Date: Thu, 9 May 2024 12:52:29 +0200 Subject: [PATCH 3/4] refactor: Update item specification creation jobs --- app/Console/Commands/SC/ImportItems.php | 7 ++-- .../SC/Import/AbstractItemCreationJob.php | 20 ++++++++++ app/Jobs/SC/Import/Clothing.php | 15 ++----- app/Jobs/SC/Import/Food.php | 15 ++----- app/Jobs/SC/Import/Grenade.php | 15 ++----- app/Jobs/SC/Import/HackingChip.php | 15 ++----- app/Jobs/SC/Import/Knife.php | 15 ++----- app/Jobs/SC/Import/MiningLaser.php | 20 ++-------- app/Jobs/SC/Import/MiningModule.php | 15 ++----- app/Jobs/SC/Import/PersonalWeapon.php | 15 ++----- app/Jobs/SC/Import/Vehicle.php | 2 +- app/Jobs/SC/Import/VehicleItem.php | 16 ++------ app/Jobs/SC/Import/WeaponAttachment.php | 16 ++------ app/Jobs/SC/Import/WeaponModifier.php | 16 ++------ .../Parser/SC/AbstractCommodityItem.php | 40 +++++++++++++------ app/Services/Parser/SC/Item.php | 5 ++- app/Services/Parser/SC/Weapon.php | 2 +- 17 files changed, 89 insertions(+), 160 deletions(-) create mode 100644 app/Jobs/SC/Import/AbstractItemCreationJob.php diff --git a/app/Console/Commands/SC/ImportItems.php b/app/Console/Commands/SC/ImportItems.php index cc3497a7a..64cb8e319 100644 --- a/app/Console/Commands/SC/ImportItems.php +++ b/app/Console/Commands/SC/ImportItems.php @@ -46,7 +46,6 @@ class ImportItems extends AbstractQueueCommand */ public function handle(): int { - $labels = (new Labels())->getData(); $manufacturers = (new Manufacturers())->getData(); $files = File::allFiles(scdata('items')) + Storage::allFiles(scdata('ships')); @@ -67,13 +66,13 @@ public function handle(): int ->tap(function (Collection $chunks) { $this->createProgressBar($chunks->count()); }) - ->each(function (Collection $chunk) use ($labels, $manufacturers) { + ->each(function (Collection $chunk) use ($manufacturers) { $this->bar->advance(); - $chunk->map(function (string $file) use ($labels, $manufacturers) { + $chunk->map(function (string $file) use ($manufacturers) { return [ 'file' => $file, - 'item' => (new Item($file, $labels, $manufacturers))->getData(), + 'item' => (new Item($file, $manufacturers))->getData(), ]; }) ->filter(function (array $data) { diff --git a/app/Jobs/SC/Import/AbstractItemCreationJob.php b/app/Jobs/SC/Import/AbstractItemCreationJob.php new file mode 100644 index 000000000..82f07d3e6 --- /dev/null +++ b/app/Jobs/SC/Import/AbstractItemCreationJob.php @@ -0,0 +1,20 @@ +labels = new Labels(); + } +} diff --git a/app/Jobs/SC/Import/Clothing.php b/app/Jobs/SC/Import/Clothing.php index 7d8e906f9..392a8f8a8 100644 --- a/app/Jobs/SC/Import/Clothing.php +++ b/app/Jobs/SC/Import/Clothing.php @@ -4,39 +4,30 @@ namespace App\Jobs\SC\Import; -use App\Services\Parser\SC\Labels; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Filesystem\FileNotFoundException; -use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use JsonException; -class Clothing implements ShouldQueue +class Clothing extends AbstractItemCreationJob { use Dispatchable; use InteractsWithQueue; use Queueable; use SerializesModels; - private string $filePath; - - public function __construct(string $filePath) - { - $this->filePath = $filePath; - } - /** * Execute the job. */ public function handle(): void { - $labels = (new Labels())->getData(); + $this->loadLabels(); try { - $parser = new \App\Services\Parser\SC\Clothing($this->filePath, $labels); + $parser = new \App\Services\Parser\SC\Clothing($this->filePath, $this->labels); } catch (FileNotFoundException|JsonException $e) { $this->fail($e); diff --git a/app/Jobs/SC/Import/Food.php b/app/Jobs/SC/Import/Food.php index 41e8afd9f..77a1c564e 100644 --- a/app/Jobs/SC/Import/Food.php +++ b/app/Jobs/SC/Import/Food.php @@ -5,38 +5,29 @@ namespace App\Jobs\SC\Import; use App\Models\SC\Food\FoodEffect; -use App\Services\Parser\SC\Labels; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Filesystem\FileNotFoundException; -use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use JsonException; -class Food implements ShouldQueue +class Food extends AbstractItemCreationJob { use Dispatchable; use InteractsWithQueue; use Queueable; use SerializesModels; - private string $filePath; - - public function __construct(string $filePath) - { - $this->filePath = $filePath; - } /** * Execute the job. */ public function handle(): void { - $labels = (new Labels())->getData(); - + $this->loadLabels(); try { - $parser = new \App\Services\Parser\SC\Food($this->filePath, $labels); + $parser = new \App\Services\Parser\SC\Food($this->filePath, $this->labels); } catch (FileNotFoundException|JsonException $e) { $this->fail($e); diff --git a/app/Jobs/SC/Import/Grenade.php b/app/Jobs/SC/Import/Grenade.php index 8585abe25..fe1c0673b 100644 --- a/app/Jobs/SC/Import/Grenade.php +++ b/app/Jobs/SC/Import/Grenade.php @@ -4,38 +4,29 @@ namespace App\Jobs\SC\Import; -use App\Services\Parser\SC\Labels; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Filesystem\FileNotFoundException; -use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use JsonException; -class Grenade implements ShouldQueue +class Grenade extends AbstractItemCreationJob { use Dispatchable; use InteractsWithQueue; use Queueable; use SerializesModels; - private string $filePath; - - public function __construct(string $filePath) - { - $this->filePath = $filePath; - } /** * Execute the job. */ public function handle(): void { - $labels = (new Labels())->getData(); - + $this->loadLabels(); try { - $parser = new \App\Services\Parser\SC\Grenade($this->filePath, $labels); + $parser = new \App\Services\Parser\SC\Grenade($this->filePath, $this->labels); } catch (FileNotFoundException|JsonException $e) { $this->fail($e); diff --git a/app/Jobs/SC/Import/HackingChip.php b/app/Jobs/SC/Import/HackingChip.php index 6bf8696f9..a23759282 100644 --- a/app/Jobs/SC/Import/HackingChip.php +++ b/app/Jobs/SC/Import/HackingChip.php @@ -4,38 +4,29 @@ namespace App\Jobs\SC\Import; -use App\Services\Parser\SC\Labels; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Filesystem\FileNotFoundException; -use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use JsonException; -class HackingChip implements ShouldQueue +class HackingChip extends AbstractItemCreationJob { use Dispatchable; use InteractsWithQueue; use Queueable; use SerializesModels; - private string $filePath; - - public function __construct(string $filePath) - { - $this->filePath = $filePath; - } /** * Execute the job. */ public function handle(): void { - $labels = (new Labels())->getData(); - + $this->loadLabels(); try { - $parser = new \App\Services\Parser\SC\HackingChip($this->filePath, $labels); + $parser = new \App\Services\Parser\SC\HackingChip($this->filePath, $this->labels); } catch (FileNotFoundException|JsonException $e) { $this->fail($e); diff --git a/app/Jobs/SC/Import/Knife.php b/app/Jobs/SC/Import/Knife.php index 5386757f5..658150ff5 100644 --- a/app/Jobs/SC/Import/Knife.php +++ b/app/Jobs/SC/Import/Knife.php @@ -5,39 +5,30 @@ namespace App\Jobs\SC\Import; use App\Models\SC\MeleeCombatConfig\MeleeCombatConfig; -use App\Services\Parser\SC\Labels; use App\Services\Parser\SC\Weapon; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Filesystem\FileNotFoundException; -use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use JsonException; -class Knife implements ShouldQueue +class Knife extends AbstractItemCreationJob { use Dispatchable; use InteractsWithQueue; use Queueable; use SerializesModels; - private string $filePath; - - public function __construct(string $filePath) - { - $this->filePath = $filePath; - } /** * Execute the job. */ public function handle(): void { - $labels = (new Labels())->getData(); - + $this->loadLabels(); try { - $parser = new Weapon($this->filePath, $labels); + $parser = new Weapon($this->filePath, $this->labels); } catch (FileNotFoundException|JsonException $e) { $this->fail($e); diff --git a/app/Jobs/SC/Import/MiningLaser.php b/app/Jobs/SC/Import/MiningLaser.php index 04b901cf9..8ec9a3b79 100644 --- a/app/Jobs/SC/Import/MiningLaser.php +++ b/app/Jobs/SC/Import/MiningLaser.php @@ -4,43 +4,29 @@ namespace App\Jobs\SC\Import; -use App\Services\Parser\SC\Labels; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Filesystem\FileNotFoundException; -use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; -use Illuminate\Support\Collection; use JsonException; -class MiningLaser implements ShouldQueue +class MiningLaser extends AbstractItemCreationJob { use Dispatchable; use InteractsWithQueue; use Queueable; use SerializesModels; - private string $filePath; - - public function __construct(string $filePath) - { - $this->filePath = $filePath; - } /** * Execute the job. */ public function handle(): void { - $labels = (new Labels())->getData(); - $this->createMiningLaserModel($labels); - } - - private function createMiningLaserModel(Collection $labels): void - { + $this->loadLabels(); try { - $parser = new \App\Services\Parser\SC\MiningLaser($this->filePath, $labels); + $parser = new \App\Services\Parser\SC\MiningLaser($this->filePath, $this->labels); } catch (FileNotFoundException|JsonException $e) { $this->fail($e); diff --git a/app/Jobs/SC/Import/MiningModule.php b/app/Jobs/SC/Import/MiningModule.php index f1a044b1d..570fe88b8 100644 --- a/app/Jobs/SC/Import/MiningModule.php +++ b/app/Jobs/SC/Import/MiningModule.php @@ -4,38 +4,29 @@ namespace App\Jobs\SC\Import; -use App\Services\Parser\SC\Labels; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Filesystem\FileNotFoundException; -use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use JsonException; -class MiningModule implements ShouldQueue +class MiningModule extends AbstractItemCreationJob { use Dispatchable; use InteractsWithQueue; use Queueable; use SerializesModels; - private string $filePath; - - public function __construct(string $filePath) - { - $this->filePath = $filePath; - } /** * Execute the job. */ public function handle(): void { - $labels = (new Labels())->getData(); - + $this->loadLabels(); try { - $parser = new \App\Services\Parser\SC\MiningModule($this->filePath, $labels); + $parser = new \App\Services\Parser\SC\MiningModule($this->filePath, $this->labels); } catch (FileNotFoundException|JsonException $e) { $this->fail($e); diff --git a/app/Jobs/SC/Import/PersonalWeapon.php b/app/Jobs/SC/Import/PersonalWeapon.php index 477d7a7d2..f7bde01f5 100644 --- a/app/Jobs/SC/Import/PersonalWeapon.php +++ b/app/Jobs/SC/Import/PersonalWeapon.php @@ -5,11 +5,9 @@ namespace App\Jobs\SC\Import; use App\Models\SC\Char\PersonalWeapon\PersonalWeapon as PersonalWeaponModel; -use App\Services\Parser\SC\Labels; use App\Services\Parser\SC\Weapon; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Filesystem\FileNotFoundException; -use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; @@ -17,29 +15,22 @@ use Illuminate\Support\Collection; use JsonException; -class PersonalWeapon implements ShouldQueue +class PersonalWeapon extends AbstractItemCreationJob { use Dispatchable; use InteractsWithQueue; use Queueable; use SerializesModels; - private string $filePath; - - public function __construct(string $filePath) - { - $this->filePath = $filePath; - } /** * Execute the job. */ public function handle(): void { - $labels = (new Labels())->getData(); - + $this->loadLabels(); try { - $parser = new Weapon($this->filePath, $labels); + $parser = new Weapon($this->filePath, $this->labels); } catch (JsonException|FileNotFoundException $e) { $this->fail($e->getMessage()); diff --git a/app/Jobs/SC/Import/Vehicle.php b/app/Jobs/SC/Import/Vehicle.php index 1ef0a759b..bdfa24183 100644 --- a/app/Jobs/SC/Import/Vehicle.php +++ b/app/Jobs/SC/Import/Vehicle.php @@ -51,7 +51,7 @@ public function __construct(array $shipData) public function handle(): void { - $labels = (new Labels())->getData(); + $labels = new Labels(); $manufacturers = (new Manufacturers())->getData(); $vehicle = $this->shipData; diff --git a/app/Jobs/SC/Import/VehicleItem.php b/app/Jobs/SC/Import/VehicleItem.php index 22dd674af..14e4f13a9 100644 --- a/app/Jobs/SC/Import/VehicleItem.php +++ b/app/Jobs/SC/Import/VehicleItem.php @@ -22,10 +22,8 @@ use App\Models\SC\ItemSpecification\TractorBeam; use App\Models\SC\Vehicle\VehicleItem as VehicleItemModel; use App\Models\SC\Vehicle\Weapon\VehicleWeapon; -use App\Services\Parser\SC\Labels; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Filesystem\FileNotFoundException; -use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Foundation\Bus\Dispatchable; @@ -34,29 +32,21 @@ use Illuminate\Support\Arr; use JsonException; -class VehicleItem implements ShouldQueue +class VehicleItem extends AbstractItemCreationJob { use Dispatchable; use InteractsWithQueue; use Queueable; use SerializesModels; - private string $filePath; - - public function __construct(string $filePath) - { - $this->filePath = $filePath; - } - /** * Execute the job. */ public function handle(): void { - $labels = (new Labels())->getData(); - + $this->loadLabels(); try { - $parser = new \App\Services\Parser\SC\VehicleItems\VehicleItem($this->filePath, $labels); + $parser = new \App\Services\Parser\SC\VehicleItems\VehicleItem($this->filePath, $this->labels); } catch (FileNotFoundException|JsonException $e) { $this->fail($e); diff --git a/app/Jobs/SC/Import/WeaponAttachment.php b/app/Jobs/SC/Import/WeaponAttachment.php index d74062b69..aa5749b99 100644 --- a/app/Jobs/SC/Import/WeaponAttachment.php +++ b/app/Jobs/SC/Import/WeaponAttachment.php @@ -6,38 +6,28 @@ use App\Models\SC\Char\PersonalWeapon\IronSight; use App\Models\SC\Char\PersonalWeapon\PersonalWeaponMagazine; -use App\Services\Parser\SC\Labels; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Filesystem\FileNotFoundException; -use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use JsonException; -class WeaponAttachment implements ShouldQueue +class WeaponAttachment extends AbstractItemCreationJob { use Dispatchable; use InteractsWithQueue; use Queueable; use SerializesModels; - private string $filePath; - - public function __construct(string $filePath) - { - $this->filePath = $filePath; - } - /** * Execute the job. */ public function handle(): void { - $labels = (new Labels())->getData(); - + $this->loadLabels(); try { - $parser = new \App\Services\Parser\SC\WeaponAttachment($this->filePath, $labels); + $parser = new \App\Services\Parser\SC\WeaponAttachment($this->filePath, $this->labels); } catch (FileNotFoundException|JsonException $e) { $this->fail($e); diff --git a/app/Jobs/SC/Import/WeaponModifier.php b/app/Jobs/SC/Import/WeaponModifier.php index 291529086..06f2bcd17 100644 --- a/app/Jobs/SC/Import/WeaponModifier.php +++ b/app/Jobs/SC/Import/WeaponModifier.php @@ -5,38 +5,28 @@ namespace App\Jobs\SC\Import; use App\Models\SC\Item\ItemWeaponModifierData; -use App\Services\Parser\SC\Labels; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Filesystem\FileNotFoundException; -use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use JsonException; -class WeaponModifier implements ShouldQueue +class WeaponModifier extends AbstractItemCreationJob { use Dispatchable; use InteractsWithQueue; use Queueable; use SerializesModels; - private string $filePath; - - public function __construct(string $filePath) - { - $this->filePath = $filePath; - } - /** * Execute the job. */ public function handle(): void { - $labels = (new Labels())->getData(); - + $this->loadLabels(); try { - $parser = new \App\Services\Parser\SC\WeaponModifier($this->filePath, $labels); + $parser = new \App\Services\Parser\SC\WeaponModifier($this->filePath, $this->labels); } catch (FileNotFoundException|JsonException $e) { $this->fail($e); diff --git a/app/Services/Parser/SC/AbstractCommodityItem.php b/app/Services/Parser/SC/AbstractCommodityItem.php index b62ce560a..4da236c4d 100644 --- a/app/Services/Parser/SC/AbstractCommodityItem.php +++ b/app/Services/Parser/SC/AbstractCommodityItem.php @@ -16,13 +16,13 @@ abstract class AbstractCommodityItem protected Collection $item; - protected Collection $labels; + protected Labels $labels; /** * @throws FileNotFoundException * @throws JsonException */ - public function __construct(string $filePath, Collection $labels) + public function __construct(string $filePath, Labels $labels) { $this->filePath = $filePath; $item = File::get($filePath); @@ -84,6 +84,19 @@ protected function tryExtractDataFromDescription(string $description, array $wan } } + return $out + [ + 'description' => $this->getDescriptionText($description), + ]; + } + + /** + * Tries to remove the leading part of a description containing data + * + * @param string $description + * @return string + */ + protected function getDescriptionText(string $description): string + { $exploded = explode("\n\n", $description); if (count($exploded) === 1) { @@ -91,21 +104,17 @@ protected function tryExtractDataFromDescription(string $description, array $wan } $exploded = array_filter($exploded, static function (string $part) { - return preg_match('/\w:[\s| ]/u', $part) !== 1; + return preg_match('/(:|\w:[\s| ])/u', $part) !== 1; }); - $exploded = trim(implode("\n\n", $exploded)); - - return $out + [ - 'description' => $exploded, - ]; + return trim(implode("\n\n", $exploded)); } protected function getName(array $attachDef, string $default): string { $key = substr($attachDef['Localization']['Name'], 1); - $name = $this->labels->get($key); - $nameP = $this->labels->get($key.',P'); + $name = $this->labels->getData()->get($key); + $nameP = $this->labels->getData()->get($key.',P'); $name = $this->cleanString(trim($name ?? $nameP ?? $default)); return empty($name) ? $default : $name; @@ -116,9 +125,16 @@ protected function getDescriptionKey(array $attachDef): string return substr($attachDef['Localization']['Description'], 1); } - protected function getDescription(array $attachDef): string + protected function getDescription(array $attachDef, string $locale = 'en'): string { - return $this->cleanString($this->labels->get($this->getDescriptionKey($attachDef), '')); + switch ($locale) { + case 'zh': + return $this->cleanString($this->labels->getDataZh()->get($this->getDescriptionKey($attachDef), '')); + + default: + case 'en': + return $this->cleanString($this->labels->getData()->get($this->getDescriptionKey($attachDef), '')); + } } protected function getManufacturer(array $attachDef, Collection $manufacturers): array diff --git a/app/Services/Parser/SC/Item.php b/app/Services/Parser/SC/Item.php index 6f57adb6f..ad6a36cbf 100644 --- a/app/Services/Parser/SC/Item.php +++ b/app/Services/Parser/SC/Item.php @@ -29,11 +29,11 @@ final class Item extends AbstractCommodityItem * @throws FileNotFoundException * @throws JsonException */ - public function __construct(string $fileName, Collection $labels, Collection $manufacturers) + public function __construct(string $fileName, Collection $manufacturers) { + parent::__construct($fileName, new Labels()); $items = File::get($fileName); $this->item = collect(json_decode($items, true, 512, JSON_THROW_ON_ERROR)); - $this->labels = $labels; $this->manufacturers = $manufacturers; } @@ -135,6 +135,7 @@ public function getData(): ?array 'required_tags' => $attachDef['RequiredTags'] ?? null, 'sub_type' => $attachDef['SubType'], 'description' => $descriptionData['description'] ?? null, + 'description_zh' => $this->getDescriptionText($this->getDescription($attachDef, 'zh')), 'manufacturer_description' => $descriptionData['manufacturer'] ?? null, 'manufacturer' => $manufacturer, 'size' => $attachDef['Size'], diff --git a/app/Services/Parser/SC/Weapon.php b/app/Services/Parser/SC/Weapon.php index 3d7731848..38a0d8360 100644 --- a/app/Services/Parser/SC/Weapon.php +++ b/app/Services/Parser/SC/Weapon.php @@ -152,7 +152,7 @@ private function buildMode(array $mode): array $base = [ 'mode' => $mode['name'], - 'localised' => $this->labels->get(substr($mode['localisedName'], 1)), + 'localised' => $this->labels->getData()->get(substr($mode['localisedName'], 1)), ]; switch (strtolower($mode['name'])) { From 20b910a5e663207e68665b87ffb41b90b6d18b61 Mon Sep 17 00:00:00 2001 From: "H. C. Kruse" Date: Thu, 9 May 2024 12:54:43 +0200 Subject: [PATCH 4/4] feat: Import zh_CN item translations --- .gitmodules | 3 + app/Jobs/SC/Import/Item.php | 8 ++ app/Jobs/SC/Import/Vehicle.php | 2 - app/Models/System/Language.php | 2 +- app/Services/Parser/SC/Labels.php | 15 ++++ config/language.php | 2 +- ...cale_code_attribute_in_languages_table.php | 74 +++++++++++++++++-- .../seeders/System/LanguageTableSeeder.php | 34 +-------- lang/de.json | 2 +- lang/en.json | 2 +- storage/app/api/.gitignore | 3 +- storage/app/api/ScToolBoxLocales | 1 + 12 files changed, 104 insertions(+), 44 deletions(-) create mode 160000 storage/app/api/ScToolBoxLocales diff --git a/.gitmodules b/.gitmodules index a022ec4fa..50f17df67 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "storage/app/api/scunpacked-data"] path = storage/app/api/scunpacked-data url = https://github.com/StarCitizenWiki/scunpacked-data.git +[submodule "storage/app/api/ScToolBoxLocales"] + path = storage/app/api/ScToolBoxLocales + url = https://github.com/StarCitizenToolBox/LocalizationData diff --git a/app/Jobs/SC/Import/Item.php b/app/Jobs/SC/Import/Item.php index d71540474..30cfe21a7 100644 --- a/app/Jobs/SC/Import/Item.php +++ b/app/Jobs/SC/Import/Item.php @@ -75,6 +75,14 @@ public function handle(): void ]); } + if (! empty($this->data['description_zh'])) { + $itemModel->translations()->updateOrCreate([ + 'locale_code' => Language::CHINESE, + ], [ + 'translation' => $this->data['description_zh'], + ]); + } + $data = collect($this->data['description_data'] ?? [])->filter(function ($value, $key) { return $key !== 'description'; })->each(function ($value, $key) use ($itemModel) { diff --git a/app/Jobs/SC/Import/Vehicle.php b/app/Jobs/SC/Import/Vehicle.php index bdfa24183..8e29a5b03 100644 --- a/app/Jobs/SC/Import/Vehicle.php +++ b/app/Jobs/SC/Import/Vehicle.php @@ -51,7 +51,6 @@ public function __construct(array $shipData) public function handle(): void { - $labels = new Labels(); $manufacturers = (new Manufacturers())->getData(); $vehicle = $this->shipData; @@ -76,7 +75,6 @@ public function handle(): void if (! $vehicleModel->item === null || ! optional($vehicleModel->item)->exists) { $itemParser = new \App\Services\Parser\SC\Item( $vehicle['filePath'], - $labels, $manufacturers ); diff --git a/app/Models/System/Language.php b/app/Models/System/Language.php index db2fb7d3d..1f657c54b 100644 --- a/app/Models/System/Language.php +++ b/app/Models/System/Language.php @@ -17,7 +17,7 @@ class Language extends Model public const ENGLISH = 'en_EN'; public const GERMAN = 'de_DE'; - public const CHINESE = 'zh_HANS'; + public const CHINESE = 'zh_CN'; public $incrementing = false; diff --git a/app/Services/Parser/SC/Labels.php b/app/Services/Parser/SC/Labels.php index b349ad500..3b3243078 100644 --- a/app/Services/Parser/SC/Labels.php +++ b/app/Services/Parser/SC/Labels.php @@ -12,6 +12,7 @@ final class Labels { private Collection $labels; + private Collection $zhTranslations; /** * Labels contain all available translations @@ -23,10 +24,24 @@ public function __construct() { $items = File::get(scdata('labels.json')); $this->labels = collect(json_decode($items, true, 512, JSON_THROW_ON_ERROR)); + $this->loadChinese(); } public function getData(): Collection { return $this->labels; } + + public function getDataZh(): Collection + { + return $this->zhTranslations; + } + + private function loadChinese(): void + { + $this->zhTranslations = collect(parse_ini_file( + storage_path('app/api/ScToolBoxLocales/chinese_(simplified)/global.ini'), + scanner_mode: INI_SCANNER_RAW + )); + } } diff --git a/config/language.php b/config/language.php index 3d200f8ec..f9b291720 100644 --- a/config/language.php +++ b/config/language.php @@ -11,7 +11,7 @@ 'codes' => [ 'de_DE', 'en_EN', - 'zh_HANS', + 'zh_CN', ], 'enable_galactapedia_language_links' => env('GALACTAPEDIA_LANGUAGE_LINKS', false), diff --git a/database/migrations/update/system/2024_05_09_103833_change_locale_code_attribute_in_languages_table.php b/database/migrations/update/system/2024_05_09_103833_change_locale_code_attribute_in_languages_table.php index 77fb56a56..9bd961e78 100644 --- a/database/migrations/update/system/2024_05_09_103833_change_locale_code_attribute_in_languages_table.php +++ b/database/migrations/update/system/2024_05_09_103833_change_locale_code_attribute_in_languages_table.php @@ -11,9 +11,40 @@ */ public function up(): void { - Schema::table('languages', static function (Blueprint $table) { - $table->char('locale_code', 25)->change(); - }); + /** DROP Foreign Key Constraints */ + Schema::table('comm_link_translations', static fn (Blueprint $table) => $table->dropForeign(['locale_code'])); + Schema::table('sc_item_translations', static fn (Blueprint $table) => $table->dropForeign('fk_sc_i_tra_locale')); + Schema::table('star_citizen_unpacked_item_translations', static fn (Blueprint $table) => $table->dropForeign('sc_unpacked_item_translations_locale')); + Schema::table('galactapedia_article_translations', static fn (Blueprint $table) => $table->dropForeign(['locale_code'])); + Schema::table('manufacturer_translations', static fn (Blueprint $table) => $table->dropForeign(['locale_code'])); + Schema::table('production_note_translations', static fn (Blueprint $table) => $table->dropForeign(['locale_code'])); + Schema::table('production_status_translations', static fn (Blueprint $table) => $table->dropForeign(['locale_code'])); + Schema::table('celestial_object_translations', static fn (Blueprint $table) => $table->dropForeign(['locale_code'])); + Schema::table('starsystem_translations', static fn (Blueprint $table) => $table->dropForeign(['locale_code'])); + Schema::table('vehicle_focus_translations', static fn (Blueprint $table) => $table->dropForeign(['locale_code'])); + Schema::table('vehicle_size_translations', static fn (Blueprint $table) => $table->dropForeign(['locale_code'])); + Schema::table('vehicle_type_translations', static fn (Blueprint $table) => $table->dropForeign(['locale_code'])); + Schema::table('vehicle_translations', static fn (Blueprint $table) => $table->dropForeign(['locale_code'])); + Schema::table('transcript_translations', static fn (Blueprint $table) => $table->dropForeign('new_transcript_locale_code')); + Schema::table('relay_transcript_translations', static fn (Blueprint $table) => $table->dropForeign('transcript_translations_locale_code_foreign')); + + Schema::table('languages', static fn (Blueprint $table) => $table->char('locale_code', 25)->change()); + Schema::table('comm_link_translations', static fn (Blueprint $table) => $table->char('locale_code', 25)->change()); + Schema::table('sc_item_translations', static fn (Blueprint $table) => $table->char('locale_code', 25)->change()); + Schema::table('star_citizen_unpacked_item_translations', static fn (Blueprint $table) => $table->char('locale_code', 25)->change()); + Schema::table('galactapedia_article_translations', static fn (Blueprint $table) => $table->char('locale_code', 25)->change()); + Schema::table('manufacturer_translations', static fn (Blueprint $table) => $table->char('locale_code', 25)->change()); + Schema::table('production_note_translations', static fn (Blueprint $table) => $table->char('locale_code', 25)->change()); + Schema::table('production_status_translations', static fn (Blueprint $table) => $table->char('locale_code', 25)->change()); + Schema::table('celestial_object_translations', static fn (Blueprint $table) => $table->char('locale_code', 25)->change()); + Schema::table('starsystem_translations', static fn (Blueprint $table) => $table->char('locale_code', 25)->change()); + Schema::table('vehicle_focus_translations', static fn (Blueprint $table) => $table->char('locale_code', 25)->change()); + Schema::table('vehicle_size_translations', static fn (Blueprint $table) => $table->char('locale_code', 25)->change()); + Schema::table('vehicle_type_translations', static fn (Blueprint $table) => $table->char('locale_code', 25)->change()); + Schema::table('vehicle_translations', static fn (Blueprint $table) => $table->char('locale_code', 25)->change()); + Schema::table('transcript_translations', static fn (Blueprint $table) => $table->char('locale_code', 25)->change()); + Schema::table('relay_transcript_translations', static fn (Blueprint $table) => $table->char('locale_code', 25)->change()); + } /** @@ -21,8 +52,39 @@ public function up(): void */ public function down(): void { - Schema::table('languages', static function (Blueprint $table) { - $table->char('locale_code', 5)->change(); - }); + Schema::table('languages', static fn (Blueprint $table) => $table->char('locale_code', 5)->change()); + Schema::table('comm_link_translations', static fn (Blueprint $table) => $table->char('locale_code', 5)->change()); + Schema::table('sc_item_translations', static fn (Blueprint $table) => $table->char('locale_code', 5)->change()); + Schema::table('star_citizen_unpacked_item_translations', static fn (Blueprint $table) => $table->char('locale_code', 5)->change()); + Schema::table('galactapedia_article_translations', static fn (Blueprint $table) => $table->char('locale_code', 5)->change()); + Schema::table('manufacturer_translations', static fn (Blueprint $table) => $table->char('locale_code', 5)->change()); + Schema::table('production_note_translations', static fn (Blueprint $table) => $table->char('locale_code', 5)->change()); + Schema::table('production_status_translations', static fn (Blueprint $table) => $table->char('locale_code', 5)->change()); + Schema::table('celestial_object_translations', static fn (Blueprint $table) => $table->char('locale_code', 5)->change()); + Schema::table('starsystem_translations', static fn (Blueprint $table) => $table->char('locale_code', 5)->change()); + Schema::table('vehicle_focus_translations', static fn (Blueprint $table) => $table->char('locale_code', 5)->change()); + Schema::table('vehicle_size_translations', static fn (Blueprint $table) => $table->char('locale_code', 5)->change()); + Schema::table('vehicle_type_translations', static fn (Blueprint $table) => $table->char('locale_code', 5)->change()); + Schema::table('vehicle_translations', static fn (Blueprint $table) => $table->char('locale_code', 5)->change()); + Schema::table('transcript_translations', static fn (Blueprint $table) => $table->char('locale_code', 5)->change()); + Schema::table('relay_transcript_translations', static fn (Blueprint $table) => $table->char('locale_code', 5)->change()); + + /** Re-Add Keys */ + Schema::table('comm_link_translations', static fn (Blueprint $table) => $table->foreign('locale_code')->references('locale_code')->on('languages')); + Schema::table('sc_item_translations', static fn (Blueprint $table) => $table->foreign('locale_code')->references('locale_code')->on('languages')); + Schema::table('star_citizen_unpacked_item_translations', static fn (Blueprint $table) => $table->foreign('locale_code')->references('locale_code')->on('languages')); + Schema::table('galactapedia_article_translations', static fn (Blueprint $table) => $table->foreign('locale_code')->references('locale_code')->on('languages')); + Schema::table('manufacturer_translations', static fn (Blueprint $table) => $table->foreign('locale_code')->references('locale_code')->on('languages')); + Schema::table('production_note_translations', static fn (Blueprint $table) => $table->foreign('locale_code')->references('locale_code')->on('languages')); + Schema::table('production_status_translations', static fn (Blueprint $table) => $table->foreign('locale_code')->references('locale_code')->on('languages')); + Schema::table('celestial_object_translations', static fn (Blueprint $table) => $table->foreign('locale_code')->references('locale_code')->on('languages')); + Schema::table('starsystem_translations', static fn (Blueprint $table) => $table->foreign('locale_code')->references('locale_code')->on('languages')); + Schema::table('vehicle_focus_translations', static fn (Blueprint $table) => $table->foreign('locale_code')->references('locale_code')->on('languages')); + Schema::table('vehicle_size_translations', static fn (Blueprint $table) => $table->foreign('locale_code')->references('locale_code')->on('languages')); + Schema::table('vehicle_type_translations', static fn (Blueprint $table) => $table->foreign('locale_code')->references('locale_code')->on('languages')); + Schema::table('vehicle_translations', static fn (Blueprint $table) => $table->foreign('locale_code')->references('locale_code')->on('languages')); + Schema::table('vehicle_translations', static fn (Blueprint $table) => $table->foreign('locale_code')->references('locale_code')->on('languages')); + Schema::table('transcript_translations', static fn (Blueprint $table) => $table->foreign('locale_code')->references('locale_code')->on('languages')); + Schema::table('relay_transcript_translations', static fn (Blueprint $table) => $table->foreign('locale_code')->references('locale_code')->on('languages')); } }; diff --git a/database/seeders/System/LanguageTableSeeder.php b/database/seeders/System/LanguageTableSeeder.php index 294c6084b..81af13c21 100644 --- a/database/seeders/System/LanguageTableSeeder.php +++ b/database/seeders/System/LanguageTableSeeder.php @@ -5,45 +5,17 @@ namespace Database\Seeders\System; use App\Models\System\Language; -use Carbon\Carbon; use Illuminate\Database\Seeder; -use Illuminate\Support\Facades\DB; class LanguageTableSeeder extends Seeder { /** * Run the database seeds. - * - * @return void */ public function run(): void { - if (DB::table('languages')->where('locale_code', Language::ENGLISH)->exists()) { - return; - } - - $now = Carbon::now(); - - DB::table('languages')->insert( - [ - 'locale_code' => Language::ENGLISH, - 'created_at' => $now, - 'updated_at' => $now, - ] - ); - DB::table('languages')->insert( - [ - 'locale_code' => Language::GERMAN, - 'created_at' => $now, - 'updated_at' => $now, - ] - ); - DB::table('languages')->insert( - [ - 'locale_code' => Language::CHINESE, - 'created_at' => $now, - 'updated_at' => $now, - ] - ); + Language::query()->firstOrCreate(['locale_code' => Language::ENGLISH]); + Language::query()->firstOrCreate(['locale_code' => Language::GERMAN]); + Language::query()->firstOrCreate(['locale_code' => Language::CHINESE]); } } diff --git a/lang/de.json b/lang/de.json index 2c3640aa6..1951b08a4 100644 --- a/lang/de.json +++ b/lang/de.json @@ -1,7 +1,7 @@ { "de_DE": "Deutsch", "en_EN": "Englisch", - "zh_HANS": "Chinesisch", + "zh_CN": "Chinesisch", "created_at": "Erstelldatum", "translation": "Übersetzung", diff --git a/lang/en.json b/lang/en.json index 1975f5c32..de06a600a 100644 --- a/lang/en.json +++ b/lang/en.json @@ -1,7 +1,7 @@ { "de_DE": "German", "en_EN": "English", - "zh_HANS": "Chinese", + "zh_CN": "Chinese", "API": "API", diff --git a/storage/app/api/.gitignore b/storage/app/api/.gitignore index 4f060dcfd..6afde06b1 100644 --- a/storage/app/api/.gitignore +++ b/storage/app/api/.gitignore @@ -3,4 +3,5 @@ !starmap !vehicles !stats -!scunpacked-data \ No newline at end of file +!scunpacked-data +!ScToolBoxLocales \ No newline at end of file diff --git a/storage/app/api/ScToolBoxLocales b/storage/app/api/ScToolBoxLocales new file mode 160000 index 000000000..0d691c7f9 --- /dev/null +++ b/storage/app/api/ScToolBoxLocales @@ -0,0 +1 @@ +Subproject commit 0d691c7f93ec66092a5dde908cd151479a7c1613