niels-numbers/laravel-localizer
Locale-aware routing for Laravel with static, route:cache-ready localized routes. Auto-detects language, redirects to prefixed URLs, and resolves route() to the correct locale. Successor to mcamara/laravel-localization.
/en/about, /fr/about) with a single Route::localize() wrapper, auto-generating static routes while preserving Laravel’s route() helper consistency.RedirectLocale, SetLocale) to handle redirects, session/cookie persistence, and locale detection (e.g., Accept-Language header). This aligns with Laravel’s declarative middleware pattern, reducing custom logic.LocalizerBladeRouteGeneratorV2, TypeScript helpers) ensures client-side route consistency without breaking SSR or hydration. This is critical for modern SPAs.Localizer::currentLocaleDirection(), addressing UX needs for languages like Arabic or Hebrew without requiring custom middleware.mcamara/laravel-localization (deprecated) with a drop-in API (Route::localize()). Migration path is well-documented, reducing risk.with_locale.about, without_locale.about), ensuring compatibility with route:cache and Laravel’s router optimizations.DetectorInterface, enabling context-aware localization (e.g., user preferences over browser headers).SetLocale must run after StartSession and before SubstituteBindings to avoid breaking translated route bindings (e.g., {post:slug}). Misconfiguration risks 404s or incorrect locale resolution.
LocalizerBladeRouteGeneratorV2 for Ziggy v2). Mismatches may break client-side routing.
@routes Blade directive.ext-intl for BCP 47 script detection. Fallback to built-in maps may miss edge cases (e.g., rare scripts).
localizer.rtl_scripts config if needed; test with target locales.localizer.detectors.)en for unsupported languages) be handled?/about) hide the prefix (hide_default_locale: true) or always show it (e.g., /en/about)?spatie/laravel-typescript-transformer helpers suffice?route:cache be used? If yes, verify static route generation works with Route::localize().Route::baseName() to normalize route names.)LocalizerBladeRouteGeneratorV2 binding (Laravel 11+).route() helper.mcamara/laravel-localization:
composer.json and run composer update.Route::group(['prefix' => '{locale}'], ...) with Route::localize(...).RedirectLocale and SetLocale (order-critical).LocalizerBladeRouteGeneratorV2 in AppServiceProvider.resources/js/route.ts./about → /de/about).route() helper returns correct URLs in Blade/JS.php artisan route:cache.DetectorInterface for non-standard sources (e.g., database, API).localizer.rtl_scripts if needed.Route::group with Route::localize().localizer.php (detectors, default locale, hidden prefix).RedirectLocale and SetLocale to web middleware group (order: StartSession → SetLocale → SubstituteBindings).config/localizer.php (detectors, locales, RTL rules), reducing code changes.LocalizerBladeRouteGeneratorV2).php artisan route:list to verify static routes (with_locale.*, without_locale.*).php artisan route:middleware.Accept-Language headers and detector chain output for edge cases.@routes Blade directive and TypeScript helpers in all locales.route:cache further optimizes.RedirectLocale) adds minimal latency (~1–2ms for redirects).Accept-Language in session reduces repeated header parsing.lang/de.json) via CDN or edge caching.| Scenario | Impact | Mitigation |
|---|---|---|
| Middleware order wrong | 404s on translated routes | Validate with php artisan route:middleware. |
Accept-Language missing |
Default locale used | Extend detector chain (e.g., user session). |
| Ziggy binding misconfigured | Client-side routes broken | Test @routes in all locales. |
| RTL/LTR misclassification | Incorrect dir attribute |
Extend localizer.rtl_scripts config. |
| Route cache stale | Redirects to wrong locale | Clear cache after locale additions. |
Route::localize() usage and middleware order./about → /de/about).hide_default_locale: false to exposeHow can I help you explore Laravel packages today?