mcamara/laravel-localization
Laravel localization helper for multi-language apps: detect browser language, redirect and persist locale (session/cookie), define routes once with locale prefixes, translate routes, optionally hide default locale, plus helpers like language selector. Supports caching and testing.
App::getLocale(), translation files) while adding a layer for URL-based routing and locale detection. This aligns well with Laravel’s MVC architecture and avoids reinventing core functionality.composer require), and configuration is minimal (publishing the config file and registering middleware). The package supports Laravel 10–13 (PHP 8.2+), ensuring compatibility with modern stacks.LaravelLocalization::setLocale()—is intuitive and non-intrusive. It works alongside Laravel’s native routing, including named routes and model binding.localeSessionRedirect, localeCookieRedirect) for different use cases (e.g., session-based persistence vs. cookie-based). This allows TPMs to tailor behavior to project needs (e.g., multi-device consistency vs. user preference).useAcceptLanguageHeader feature may misfire if users’ browser locales don’t match their preferences (e.g., corporate networks overriding settings). Mitigation: Combine with cookie/session fallback and user-explicit selection.localesMapping (e.g., en-GB → uk) risks conflicts with existing routes or third-party packages. Validation: Test with edge cases like /uk vs. /user/uk.php artisan route:cache) may conflict with dynamic locale-based routes. Mitigation: Exclude localized routes from caching or use the package’s caching-routes feature.@once) could break if localeViewPath middleware dynamically changes paths. Validation: Test with cached views in multi-locale setups.utf8suffix config may cause issues on non-CentOS servers. Validation: Test on target hosting environments.localeViewPath for RTL-specific styles)?/about vs. /en/about)? How will this affect backlinks and analytics?/about → /acerca) be implemented, or will the package’s localizeUrl() helper suffice?resources/lang/) and locale-specific content (e.g., images, videos)?/en/about).localize, localizationRedirect, etc.trans() and JSON/LANG files.localeViewPath for language-specific Blade templates./api/v1/en/users), but requires explicit handling of Accept-Language headers in API clients.App::setLocale() if locale-specific logic is involved./admin, /webhooks) to exclude from the LaravelLocalization group./blog) to test middleware, redirects, and URL helpers.LaravelLocalization::setLocale() group.{{ LaravelLocalization::localizeUrl() }}) and API clients to use localized URLs.spatie/laravel-seo for hreflang tags (requires custom middleware to pass locale to the package).spatie/laravel-cache-control or laravel-http-client; test caching headers per locale.laravel-sanctum or laravel-passport if using session/cookie storage.locale column to user models if personalization is needed (e.g., user()->locale).config/laravellocalization.php (e.g., supportedLocales, hideDefaultLocaleInURL).app/Http/Kernel.php or bootstrap/app.php.LaravelLocalization::setLocale()./admin) from the group.localeSessionRedirect or localeCookieRedirect to the middleware stack (order matters; place before localize).localeViewPath middleware if using language-specific Blade templates.{{ LaravelLocalization::getCurrentLocaleName() }}.LaravelLocalization::localizeUrl().LaravelLocalization::getLocalesOrder()).actingAsUserWithLocale() helper).resources/lang/), which are version-controlled and familiar to developers.laravel-lang for crowd-sourced translations.config('laravellocalization.supportedLocales')).php artisan route:clear)./webhooks) to avoid accidental inclusion.localize before localizationRedirect). Test with php artisan route:list to verify URL structures.LaravelLocalization::localizeUrl() for action URLs toHow can I help you explore Laravel packages today?