- How do I migrate from mcamara/laravel-localization to niels-numbers/laravel-localizer?
- Replace `Route::group(['prefix' => '{locale}'], ...)` with `Route::localize(...)` and update middleware to use `RedirectLocale` and `SetLocale`. The package provides a migration guide in its [documentation](https://localizer.adam-nielsen.de/migration) to handle breaking changes like static route generation and detector chains.
- Does this package work with Laravel route caching (`php artisan route:cache`)?
- Yes, the package generates static routes (e.g., `without_locale.about` and `with_locale.about`) that are fully compatible with Laravel’s route caching. Routes registered via `Route::localize()` will be cached without issues, ensuring performance benefits in production.
- Can I customize how the locale is detected (e.g., prioritize user session over browser headers)?
- Absolutely. The package supports a detector chain via `DetectorInterface`, allowing you to define custom logic. For example, you can prioritize a user model attribute, database settings, or cookies. Configure this in the `localizer.detectors` array in your config file.
- Will this break my existing `route('about')` helpers in Blade or JavaScript?
- No, the package ensures `route('about')` resolves to the correct locale automatically. For frontend frameworks like Ziggy or Inertia, use `LocalizerBladeRouteGeneratorV2` to maintain consistency with server-side routes. The package provides TypeScript helpers for Wayfinder and other setups.
- How do I handle RTL (right-to-left) languages like Arabic or Hebrew?
- The package includes built-in RTL/LTR direction detection via `Localizer::currentLocaleDirection()`. It relies on PHP’s `ext-intl` for BCP 47 script detection. If needed, extend the `localizer.rtl_scripts` config to include additional scripts or fall back to a custom map for edge cases.
- Should I hide the locale prefix for my default language (e.g., `/about` instead of `/en/about`)?
- Yes, set `hide_default_locale` to `true` in your config. This ensures URLs like `/about` (default locale) redirect to `/en/about` only if the user’s locale doesn’t match. The package handles this seamlessly while preserving SEO-friendly URLs.
- Does this package support Laravel 13 and PHP 8.4?
- Yes, the package is fully compatible with Laravel 9–13 and PHP 8.2–8.4. It includes CI tests for these versions, and the documentation covers setup for modern Laravel stacks, including Ziggy v2 and Inertia.js.
- How do I integrate this with Google Analytics or other tracking tools?
- Use `Route::baseName()` to normalize route names for analytics. For example, `route('about')` might resolve to `/en/about`, but `Route::baseName('about')` returns `about`, ensuring consistent tracking across locales. This avoids duplicate entries for localized routes.
- What middleware order is required for locale detection and redirects?
- The `SetLocale` middleware must run **after** `StartSession` and **before** `SubstituteBindings` to avoid breaking route bindings (e.g., `{post:slug}`). The package enforces this in its docs and CI tests. Misconfiguration can cause 404s or incorrect locale resolution.
- Are there alternatives to this package for Laravel localization?
- Yes, alternatives include `spatie/laravel-translatable` (for model translations) or `mcamara/laravel-localization` (deprecated). However, `niels-numbers/laravel-localizer` stands out for its seamless route caching, Ziggy/Inertia support, and RTL handling. It’s the direct successor to `mcamara/laravel-localization` with modern improvements.