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:
localize, localeSessionRedirect), promoting separation of concerns and reusability across routes/controllers.supportedLocales, localesMapping) and hooks (e.g., urlsIgnored for opt-out routes).Cons:
route:cache incompatible), which may impact performance in high-traffic apps. Mitigated by the package’s caching middleware, but requires manual setup.niels-numbers/laravel-localizer for new projects (static routes + route:cache support).bootstrap/app.php).spatie/laravel-translatable) are unlikely but should be tested.LaravelLocalization::fakeLocale()), easing CI/CD pipelines.route:list and consider the caching middleware.laravel-debugbar or Blackfire.localizationRedirect middleware and validate with Screaming Frog.spatie/laravel-hreflang if needed.laravel-localizer if long-term maintenance is a priority.localeSessionRedirect vs. localeCookieRedirect).urlsIgnored to opt out.route:cache? If yes, evaluate the trade-offs of dynamic routes vs. migrating to laravel-localizer./about vs. /en/about)? Test with real users.laravel-localizer be prioritized?fakeLocale() helper.Accept-Language header parsing). Verify php -m | grep intl is enabled.SESSION_DRIVER (e.g., database, redis) is configured.LaravelLocalization::localizeUrl() integrate seamlessly with Blade.i18next.lang/en.json). No schema changes required.spatie/laravel-translatable), ensure consistency with the package’s App::setLocale()./blog/post-123 vs. /en/blog/post-123).supportedLocales, hideDefaultLocaleInURL).LaravelLocalization::setLocale() groups.localizeUrl()).laravel-localizer, use a feature flag to toggle between packages:
// config/app.php
'providers' => [
// ...
ConditionalProvider::class,
],
// app/Providers/ConditionalProvider.php
class ConditionalProvider extends ServiceProvider {
public function register() {
if (config('app.use_localizer')) {
$this->app->register(\NielsNumbers\LaravelLocalizer\LaravelLocalizerServiceProvider::class);
} else {
$this->app->register(\Mcamara\LaravelLocalization\LaravelLocalizationServiceProvider::class);
}
}
}
bootstrap/app.php.php -v.route:cache. Use the package’s caching middleware or migrate to laravel-localizer.Accept-Language headers are respected (configure useAcceptLanguageHeader).spatie/laravel-medialibrary, spatie/laravel-translatable, etc., but validate locale consistency.How can I help you explore Laravel packages today?