From 594fa41527cbfca94175aac8ee1f32e41895a0d0 Mon Sep 17 00:00:00 2001 From: Konstantinos Arvanitakis Date: Thu, 27 Aug 2026 01:08:34 +0300 Subject: [PATCH] Feature: Localization Restructuring to follow a stricter pattern --- docs/localization.md | 8 ++++---- docs/product-search.md | 2 +- .../LanguageLineResource/Pages/CreateLanguageLine.php | 2 +- .../LanguageLineResource/Pages/EditLanguageLine.php | 2 +- src/Localization/{ => Middleware}/LocaleMiddleware.php | 2 +- .../{ => Observers}/LanguageCacheObserver.php | 2 +- src/Localization/Services/LanguageCache.php | 2 +- src/Localization/{ => Services}/TranslationReader.php | 2 +- src/Localization/{ => Services}/TranslationService.php | 2 +- src/Providers/LocalizationServiceProvider.php | 4 ++-- 10 files changed, 14 insertions(+), 14 deletions(-) rename src/Localization/{ => Middleware}/LocaleMiddleware.php (98%) rename src/Localization/{ => Observers}/LanguageCacheObserver.php (93%) rename src/Localization/{ => Services}/TranslationReader.php (93%) rename src/Localization/{ => Services}/TranslationService.php (97%) diff --git a/docs/localization.md b/docs/localization.md index 9a3bff9..4544a5c 100644 --- a/docs/localization.md +++ b/docs/localization.md @@ -50,7 +50,7 @@ fine — just keep admin/Livewire/webhook routes registered outside of it (as th ## Behavior -`Modules\Core\Localization\LocaleMiddleware`: +`Modules\Core\Localization\Middleware\LocaleMiddleware`: 1. Reads the first path segment (`request()->segment(1)`). 2. Matches it against `Lunar\Models\Language::code`. @@ -68,7 +68,7 @@ and invalidated automatically. Adding, editing, or removing a language via the F ### How invalidation is wired (event-driven, not the observer itself) -`Modules\Core\Localization\LanguageCacheObserver` observes `Lunar\Models\Language`'s +`Modules\Core\Localization\Observers\LanguageCacheObserver` observes `Lunar\Models\Language`'s `created`/`updated`/`deleted` Eloquent events, but it's a thin trigger only — it doesn't do any invalidation work itself. It dispatches one of three events from `Modules\Core\Localization\Events` (`LanguageCreated`, `LanguageUpdated` — carrying the old @@ -195,13 +195,13 @@ a third language automatically adds a third input, no resource changes needed. ### `TranslationService` — writes go through here, not the model directly -`Modules\Core\Localization\TranslationService` wraps create/update/delete on `LanguageLine` and +`Modules\Core\Localization\Services\TranslationService` wraps create/update/delete on `LanguageLine` and dispatches a domain event after each write, following this project's standard event-driven pattern (see `modules.md`'s "Splitting Service Providers" / event-listener convention — the same shape as `Modules\Core\Auth\Events\UserCreated`): ```php -use Modules\Core\Localization\TranslationService; +use Modules\Core\Localization\Services\TranslationService; app(TranslationService::class)->create('storefront', 'nav.wishlist', [ 'en' => 'Wishlist', diff --git a/docs/product-search.md b/docs/product-search.md index 564c5a4..5cb05a1 100644 --- a/docs/product-search.md +++ b/docs/product-search.md @@ -36,7 +36,7 @@ Returns an `Illuminate\Database\Eloquent\Collection` of `Lunar\Models\Product` (`variants`, `brand`, `media`, etc.) are available on the results as normal. `$locale` defaults to `App::getLocale()` — already set correctly on every storefront request by -`Modules\Core\Localization\LocaleMiddleware` (see `localization.md`), so callers in controllers +`Modules\Core\Localization\Middleware\LocaleMiddleware` (see `localization.md`), so callers in controllers don't need to pass it explicitly. --- diff --git a/src/Localization/Filament/Resources/LanguageLineResource/Pages/CreateLanguageLine.php b/src/Localization/Filament/Resources/LanguageLineResource/Pages/CreateLanguageLine.php index 7870fe2..8705623 100644 --- a/src/Localization/Filament/Resources/LanguageLineResource/Pages/CreateLanguageLine.php +++ b/src/Localization/Filament/Resources/LanguageLineResource/Pages/CreateLanguageLine.php @@ -5,7 +5,7 @@ namespace Modules\Core\Localization\Filament\Resources\LanguageLineResource\Page use Filament\Resources\Pages\CreateRecord; use Illuminate\Database\Eloquent\Model; use Modules\Core\Localization\Filament\Resources\LanguageLineResource; -use Modules\Core\Localization\TranslationService; +use Modules\Core\Localization\Services\TranslationService; class CreateLanguageLine extends CreateRecord { diff --git a/src/Localization/Filament/Resources/LanguageLineResource/Pages/EditLanguageLine.php b/src/Localization/Filament/Resources/LanguageLineResource/Pages/EditLanguageLine.php index 80c864a..02b9740 100644 --- a/src/Localization/Filament/Resources/LanguageLineResource/Pages/EditLanguageLine.php +++ b/src/Localization/Filament/Resources/LanguageLineResource/Pages/EditLanguageLine.php @@ -7,7 +7,7 @@ use Filament\Actions\Action; use Filament\Resources\Pages\EditRecord; use Illuminate\Database\Eloquent\Model; use Modules\Core\Localization\Filament\Resources\LanguageLineResource; -use Modules\Core\Localization\TranslationService; +use Modules\Core\Localization\Services\TranslationService; use Spatie\TranslationLoader\LanguageLine; class EditLanguageLine extends EditRecord diff --git a/src/Localization/LocaleMiddleware.php b/src/Localization/Middleware/LocaleMiddleware.php similarity index 98% rename from src/Localization/LocaleMiddleware.php rename to src/Localization/Middleware/LocaleMiddleware.php index edb1d58..da1352c 100644 --- a/src/Localization/LocaleMiddleware.php +++ b/src/Localization/Middleware/LocaleMiddleware.php @@ -1,6 +1,6 @@