From 45df93692a2ad73cdd537481dee0dd9b6f33340c Mon Sep 17 00:00:00 2001 From: Konstantinos Arvanitakis Date: Mon, 28 Sep 2026 13:44:15 +0300 Subject: [PATCH] Chore: Adding Validation Translation Seeder from 3dealer --- .../Seeders/ValidationTranslationsSeeder.php | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 src/Localization/Database/Seeders/ValidationTranslationsSeeder.php diff --git a/src/Localization/Database/Seeders/ValidationTranslationsSeeder.php b/src/Localization/Database/Seeders/ValidationTranslationsSeeder.php new file mode 100644 index 0000000..a06df7f --- /dev/null +++ b/src/Localization/Database/Seeders/ValidationTranslationsSeeder.php @@ -0,0 +1,114 @@ +validate()` call in a + * consuming app (checkout addresses, cart, product reviews, stock checks). + * + * Spatie's DB loader (spatie/laravel-translation-loader, wired in + * LocalizationServiceProvider) merges this group over Laravel's file-based + * validation.php — without this, Greek requests fall back to Laravel's + * untranslated English defaults. Only the rule keys and field attributes + * actually in use are seeded; add more as new rules/fields show up. + * + * Additive and idempotent: a key that already exists is left untouched, so + * anything edited in the Filament Language Lines UI wins on a re-run. Runs + * explicitly — `php artisan db:seed --class="Modules\Core\Localization\ + * Database\Seeders\ValidationTranslationsSeeder"` — it is not wired into any + * app's own DatabaseSeeder. + * + * Greek copy uses the project's informal register (εσύ/σου). + */ +class ValidationTranslationsSeeder extends Seeder +{ + public function run(): void + { + $translations = app(TranslationService::class); + + foreach ($this->lines() as $key => [$en, $el]) { + $exists = LanguageLine::query() + ->where('group', 'validation') + ->where('key', $key) + ->exists(); + + if ($exists) { + $this->command?->warn("validation.{$key} already exists — skipped"); + + continue; + } + + $translations->create('validation', $key, ['en' => $en, 'el' => $el]); + $this->command?->info("validation.{$key} added"); + } + } + + /** + * key => [English, Greek]. + * + * @return array + */ + private function lines(): array + { + return [ + // ── Rule messages ───────────────────────────────────────────── + 'required' => ['The :attribute field is required.', 'Το πεδίο :attribute είναι υποχρεωτικό.'], + 'email' => ['The :attribute field must be a valid email address.', 'Το πεδίο :attribute πρέπει να είναι έγκυρη διεύθυνση email.'], + 'string' => ['The :attribute field must be a string.', 'Το πεδίο :attribute πρέπει να είναι κείμενο.'], + 'integer' => ['The :attribute field must be an integer.', 'Το πεδίο :attribute πρέπει να είναι ακέραιος αριθμός.'], + 'boolean' => ['The :attribute field must be true or false.', 'Το πεδίο :attribute πρέπει να είναι true ή false.'], + 'min.numeric' => ['The :attribute field must be at least :min.', 'Το πεδίο :attribute πρέπει να είναι τουλάχιστον :min.'], + 'max.string' => ['The :attribute field must not be greater than :max characters.', 'Το πεδίο :attribute δεν πρέπει να ξεπερνά τους :max χαρακτήρες.'], + 'between.numeric' => ['The :attribute field must be between :min and :max.', 'Το πεδίο :attribute πρέπει να είναι μεταξύ :min και :max.'], + 'exists' => ['The selected :attribute is invalid.', 'Η επιλεγμένη τιμή για το πεδίο :attribute δεν είναι έγκυρη.'], + // Product custom-field photo uploads (CustomFieldUploadController, CartController). + 'file' => ['The :attribute field must be a file.', 'Το πεδίο :attribute πρέπει να είναι αρχείο.'], + 'mimes' => ['The :attribute field must be a file of type: :values.', 'Το πεδίο :attribute πρέπει να είναι αρχείο τύπου: :values.'], + 'max.file' => ['The :attribute field must not be greater than :max kilobytes.', 'Το αρχείο στο πεδίο :attribute δεν πρέπει να ξεπερνά τα :max kilobytes.'], + 'uploaded' => ['The :attribute failed to upload.', 'Η μεταφόρτωση στο πεδίο :attribute απέτυχε.'], + + // ── Field names (checkout: billing/shipping address) ────────── + 'attributes.contact_email' => ['email', 'email'], + 'attributes.billing_first_name' => ['first name', 'όνομα'], + 'attributes.billing_last_name' => ['last name', 'επώνυμο'], + 'attributes.billing_company_name' => ['company name', 'επωνυμία εταιρείας'], + 'attributes.billing_tax_identifier' => ['tax ID', 'ΑΦΜ'], + 'attributes.billing_line_one' => ['address', 'διεύθυνση'], + 'attributes.billing_line_two' => ['address line 2', 'διεύθυνση (γραμμή 2)'], + 'attributes.billing_city' => ['city', 'πόλη'], + 'attributes.billing_state' => ['region', 'νομό / περιοχή'], + 'attributes.billing_postcode' => ['postcode', 'ταχυδρομικό κώδικα'], + 'attributes.billing_country_id' => ['country', 'χώρα'], + 'attributes.billing_contact_phone' => ['phone', 'τηλέφωνο'], + 'attributes.shipping_first_name' => ['first name', 'όνομα'], + 'attributes.shipping_last_name' => ['last name', 'επώνυμο'], + 'attributes.shipping_company_name' => ['company name', 'επωνυμία εταιρείας'], + 'attributes.shipping_line_one' => ['address', 'διεύθυνση'], + 'attributes.shipping_line_two' => ['address line 2', 'διεύθυνση (γραμμή 2)'], + 'attributes.shipping_city' => ['city', 'πόλη'], + 'attributes.shipping_state' => ['region', 'νομό / περιοχή'], + 'attributes.shipping_postcode' => ['postcode', 'ταχυδρομικό κώδικα'], + 'attributes.shipping_country_id' => ['country', 'χώρα'], + 'attributes.shipping_contact_phone' => ['phone', 'τηλέφωνο'], + 'attributes.shipping_delivery_instructions' => ['delivery notes', 'σχόλια για την παράδοση'], + + // ── Field names (cart) ───────────────────────────────────────── + 'attributes.purchasable_id' => ['product', 'προϊόν'], + 'attributes.quantity' => ['quantity', 'ποσότητα'], + 'attributes.code' => ['coupon code', 'κωδικό κουπονιού'], + + // ── Field names (product reviews / stock check) ──────────────── + 'attributes.variant' => ['variant', 'παραλλαγή'], + 'attributes.rating' => ['rating', 'βαθμολογία'], + 'attributes.content' => ['review text', 'κείμενο κριτικής'], + 'attributes.name' => ['name', 'όνομα'], + 'attributes.email' => ['email', 'email'], + ]; + } +}