Feature: Localization Restructuring to follow a stricter pattern
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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.
|
||||
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user