mcamara/laravel-localization
Laravel localization package for i18n: detect locale from browser, redirect and persist locale via session/cookie, define routes once with localized URL prefixes and translatable routes, optional hiding of default locale, plus helpers like language selectors.
Pros:
App::getLocale(), translation files) while adding dynamic route handling. This reduces boilerplate for multi-language support.localize, localizationRedirect) allows granular control over localization logic (e.g., session/cookie-based redirects, URL normalization)./en/about → /es/sobre-mi) and hidden default locales (e.g., /about instead of /en/about), improving SEO and UX.localizeUrl(), getURLFromRouteNameTranslated()) to simplify frontend localization (Blade templates, JavaScript).route:cache, the package offers partial caching (e.g., route lists via LaravelLocalization::getRoutes()) and testing utilities.Cons:
route:cache: Critical for high-traffic apps (performance overhead, route regeneration on every request).localize, localeSessionRedirect) to avoid conflicts (e.g., infinite redirects).config/laravellocalization.php (e.g., supportedLocales, hideDefaultLocaleInURL).localize before localizationRedirect) may cause infinite loops or broken redirects.hideDefaultLocaleInURL is misconfigured, search engines may index multiple URLs for the same content.localizeUrl() usage in Blade/JavaScript can generate malformed URLs.laravel-localizer for static routes, implying long-term maintenance costs.bootstrap/app.php updates).route:cache a hard requirement? If yes, this package is not suitable (consider laravel-localizer).rel="canonical" tags).localize or redirect middleware?laravel-localizer if static routes become critical?en-US vs. en-GB)?localizeUrl() helpers).localize middleware).localeSessionRedirect/localeCookieRedirect).hideDefaultLocaleInURL and useAcceptLanguageHeader configurations.LaravelLocalization::setLocale()).localeSessionRedirect).localizeUrl()).LaravelLocalization::setLocale().localizeUrl().supportedLocales and localesMapping for custom URLs.laravel-localizer if >10ms latency).trans() cache).resources/lang), route model binding, middleware groups.route:cache: Not supported (dynamic routes).spatie/laravel-seo).locale column to content tables for dynamic localization.php artisan vendor:publish --provider="Mcamara\LaravelLocalization\LaravelLocalizationServiceProvider".supportedLocales and hideDefaultLocaleInURL.app/Http/Kernel.php (or bootstrap/app.php for Laravel 11+).localize → localeSessionRedirect/localeCookieRedirect → localizationRedirect.LaravelLocalization::setLocale().middleware: [localeSessionRedirect]).localizeUrl() in Blade.window.__locale__)./about → /en/about).@lang() directives).config/laravellocalization.php.route:cache).resources/lang/ for each locale.localize middleware in form submissions (see README).trans() or @lang() for localized validation (not Validation::extend()).How can I help you explore Laravel packages today?