- Which Laravel and PHP versions does mcamara/laravel-localization support, and how do I install it?
- Version 2.0.x supports Laravel 10 through 13 on PHP 8.2 or higher, and you install it with a single Composer require. After that, publish the config file with php artisan vendor:publish so config/laravellocalization.php is available for customization. The package adds no database tables, queues, credentials, or external services, so the integration surface is small and easy to reverse.
- Can I run php artisan route:cache with mcamara/laravel-localization?
- Not out of the box. The package registers localized routes dynamically per request, which is incompatible with Laravel route caching, and the README calls this out as its defining limitation. You can mitigate it with urlsIgnored and careful route scoping, or adopt a package with statically registered routes. If your deploy pipeline warms route:cache, treat this as a deployment architecture decision rather than a minor tweak.
- How do I register the LaravelLocalization middleware in Laravel 11 or 12?
- In Laravel 11 and later, register the package's named middleware aliases in bootstrap/app.php through the withMiddleware closure instead of app/Http/Kernel.php. On Laravel 10 and earlier, the same aliases go into the $routeMiddleware array in the HTTP Kernel. Middleware order matters, because the route and locale detection middleware must run before anything that generates localized URLs.
- How do I hide the default locale from URLs, so English shows /about instead of /en/about?
- Set hideDefaultLocaleInURL to true in config/laravellocalization.php. The default locale then resolves without a prefix while every other supported locale keeps one. Decide this before launch, because changing it afterwards rewrites every public URL and breaks bookmarks and search engine indexes.
- Why do my localized POST requests fail with MethodNotAllowedHttpException?
- This normally means a form action or route points at a URL without the locale prefix, so the request never matches the localized route group. Generate every link and form action through LaravelLocalization::localizeUrl() or a route inside the localized group, and make sure the redirect middleware does not intercept POST requests and drop the body. The README explicitly lists POST is not working and MethodNotAllowedHttpException as recurring, user-visible pitfalls.
- How do I create translated route segments like /es/acerca and /en/about?
- Define a per-locale segment map for the route inside the LaravelLocalization::group() wrapper, so each language supplies its own slug for the same named route. LaravelLocalization::getLocalizedURL() then builds the correct segment for the active locale. Translated segments are optional, and they multiply content operations work because every slug has to be maintained in every language.
- How does mcamara/laravel-localization detect and remember a visitor's language?
- With useAcceptLanguageHeader enabled, the package negotiates the visitor's locale from the Accept-Language header against your supportedLocales and localesMapping. The redirect middleware then sends the visitor to the matching localized URL. Persistence is handled by localeSessionRedirect, which stores the locale server-side, or localeCookieRedirect, which writes a cookie that survives the session; pick based on your consent posture and whether your CDN cache key varies by cookie.
- Will localized URLs cause duplicate content or SEO problems?
- Unlocalized URLs that serve varying content create duplicate-content and crawler ambiguity, which is why the README strongly recommends the redirect middleware and why it is effectively mandatory. Plan 301 redirects from any existing unlocalized or legacy-locale paths before switching the package on. Decide hideDefaultLocaleInURL up front as well, because flipping it later changes every indexed URL.
- How do I write tests for localized routes with this package?
- The package explicitly supports testing, so you can hit localized URLs in feature tests by generating them with LaravelLocalization::getLocalizedURL() or by asserting against the expected prefixed path. Set the locale in the test rather than depending on session or cookie state left by a previous request. Assert both the localized response and the redirect behaviour of the detection middleware.
- Is mcamara/laravel-localization still maintained, and what should I use for a new project?
- It is actively maintained, but by a single maintainer focused on compatibility updates, security, and small bug fixes rather than new architecture. The README itself recommends niels-numbers/laravel-localizer as the modern successor, offering the same feature set with statically registered routes that support route:cache natively. For greenfield apps or cache-warmed deploy pipelines, evaluate the successor first; existing applications can stay on this package safely.