Comparison & Background
When to use this package
Use it for:
- automatic locale detection (browser, session, cookie, custom)
- automatic redirects to localized routes
- hidden default locale in URLs (
/aboutinstead of/en/about) - fully translatable routes (
/en/humansvs/de/menschen)
You don't need it if you're fine with example.com/de/blog / example.com/en/blog only and don't need detection or unprefixed defaults.
Comparison to other packages
mcamara/laravel-localization
The original package this one succeeds. Still maintained by @jordyvanderhaegen for Laravel/PHP compatibility, security, and small bug fixes. Long legacy codebase whose original architecture comes with limitations that motivated this rewrite - see Why migrate.
codezero-be/laravel-localized-routes (deprecated)
Route-per-locale (Nx routes per definition). No longer maintained, but its design ideas influenced this one - here only two routes per definition.
spatie/laravel-translatable
Translates Eloquent model fields, not routes. Works alongside this package for translatable slugs.
Background
I (Adam Nielsen) was a collaborator on the original mcamara/laravel-localization. Since @mcamara has moved on from Laravel, @jordyvanderhaegen continues to maintain it for compatibility and small fixes. This rewrite addresses long-standing limitations that follow from the original's runtime route generation.
The original generated dynamic routes (cache + compatibility issues). laravel-localized-routes solved this with static per-locale routes (Nx per definition). This package takes the middle path: each route registered twice (one with {locale}, one without).
Credits
- @mcamara: original creator of laravel-localization.
- @codezero-be: developed a static route-per-locale approach (e.g.
en.index,de.index,es.index). While this package follows a different routing strategy (two routes per definition: one with{locale}and one without), many classes and much of the implementation style are adapted from laravel-localized-routes. - @jordyvanderhaegen: co-maintainer of laravel-localization; his issue mcamara/laravel-localization#921 was the motivation for writing this package.
Since @codezero-be is no longer with us, I want to acknowledge his great work and influence on this package. Many of his ideas live on here, and I hope this helps to keep his contributions useful to the Laravel community for years to come.