Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Localizer

Laravel Localizer Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Detect users' language and serve localized routes in Laravel

Frequently asked questions about Laravel Localizer
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.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor