Skip to content

Laravel LocalizerLocale detection and redirects for Laravel routes

Laravel can prefix routes with /{locale}. This package adds what is missing - detect the visitor's language, redirect them there, remember the choice, and keep route('about') returning the right URL.

Example

php
Route::localize(function () {
    Route::get('/about', AboutController::class)->name('about');
});

The page is now reachable in every configured language:

URLLanguage
/abouten (default, prefix hidden)
/de/aboutde
/fr/aboutfr

The default language has no prefix because hide_default_locale is on by default. Turn it off and every URL carries a prefix: /about then redirects to /en/about.

route('about') keeps working as before and returns the URL for the current language: in Blade, controllers, jobs, mails and, with the JavaScript route helpers, in your Vue or React frontend.

Want /de/ueber and /fr/a-propos instead of /de/about? See Translated URL Paths.

What happens on a visit

  1. First visit: someone opens /about. The package reads their browser language (or your own detectors) and redirects them, for example to /de/about. English visitors stay on /about.
  2. From then on the URL decides: /de/about shows German and remembers it in session and cookie. A link to plain /about sends that visitor back to /de/about.
  3. One canonical URL per page: the default language has no prefix, so /en/about redirects to /about.

A language switcher is one helper call per language: Route::localizedSwitcherUrl('fr'). See Language Switcher.

Coming from mcamara/laravel-localization?

This package is its successor. Same job, different wiring: every localized route is a plain, static Laravel route, so route:cache works, translated routes switch reliably and Livewire works out of the box. The migration guide covers the differences step by step.

Not sure you need this package at all? See when to use it and how it compares to mcamara/laravel-localization, codezero-be/laravel-localized-routes and spatie/laravel-translatable.

Released under the MIT License.