v0.9.0
Initial public release.
Architecture is stable and battle-tested in the maintainer's own project,
but the package hasn't seen broad production validation yet. Bug reports
welcome via GitHub issues. The 0.9.x line gives room for breaking-change
adjustments based on early-adopter feedback before locking the API down
in 1.0.0.
Install
composer require niels-numbers/laravel-localizer:^0.9See the README
for setup.
Added
Route::localize()macro: registers each route twice (one with a{locale}prefix, one without). Fully compatible withphp artisan route:cache.Route::translate()macro: per-locale URI paths vialang/{locale}/routes.php(e.g./about,/de/ueber,/fr/a-propos), keyed on the full URI.hide_default_localeoption: hides the prefix for the default locale (/aboutinstead of/en/about).SetLocalemiddleware: resolves the active locale from URL → session → cookie → detector chain →app.fallback_locale.RedirectLocalemiddleware: redirects between prefixed and unprefixed variants to enforce the canonical form, preserving query strings. Skips non-safe methods (POST/PUT/PATCH/DELETE) to avoid losing the request body via the 302 → GET browser downgrade.- Detector chain:
UserDetector(reads from authenticated user) andBrowserDetector(Accept-Language); custom detectors vialocalizer.detectorsconfig. UrlGeneratoroverride: makesroute('about')pick the locale-correct variant based onApp::getLocale(), with explicit['locale' => …]override.- Template helpers on the
Routefacade:Route::localizedUrl($locale)— canonical URL of the current page in another locale, for<link rel="alternate" hreflang="...">and sitemaps.Route::localizedSwitcherUrl($locale)— always-prefixed URL, for in-page language switchers.Route::hasLocalized($name)/Route::isLocalized()— predicates for conditional rendering.
LocalizerZiggyadapter pattern: container-bindTighten\Ziggy\Ziggyto a subclass that rewrites the route manifest based on the current locale.- Wayfinder helper pattern:
localizedRoute()lookup wrapping the generated route modules. - Locale propagation guidance for non-HTTP contexts (mailables, notifications, queued jobs) via
Mail::to()->locale(),HasLocalePreference, andLocalizable::withLocale(). - Runtime active-locales subset for multitenancy:
Localizer::activeLocales(),isActive(),setActiveLocales(?array). Narrow the user-reachable locales per request without breakingroute:cache(supported = static union; active = runtime subset). - Mixed routes support:
SetLocaleandRedirectLocaleskip routes not registered throughRoute::localize()/Route::translate(), detected via alocale_typeaction attribute the macros set. Plain routes (e.g./admin,/api/health) coexist safely in the samewebmiddleware group — no spurious redirects to non-existent locale-prefixed paths. - Inertia + SPA language switcher guide (experimental) at
docs/inertia-spa-language-switch.md. - CI matrix: PHP 8.2–8.4 × Laravel 9–12 (Testbench 7–10).
Requirements
- PHP 8.2 / 8.3 / 8.4
- Laravel 9, 10, 11, or 12