Download the PHP package niels-numbers/laravel-localizer without Composer
On this page you can find all versions of the php package niels-numbers/laravel-localizer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download niels-numbers/laravel-localizer
More information about niels-numbers/laravel-localizer
Files in niels-numbers/laravel-localizer
Package laravel-localizer
Short Description Detects the user’s preferred language and redirects to the matching localized URL.
License MIT
Informations about the package laravel-localizer
Laravel Localizer
Laravel can already prefix routes with /{locale}. What it does not
do: detect a visitor's language, redirect them there, remember the
choice, and keep route('about') returning the right URL. This package
adds exactly that.
Documentation: localizer.adam-nielsen.de
Successor to
mcamara/laravel-localization. Coming from there? See the migration guide.
What you get
Wrap your routes once:
The page is now reachable in every configured language:
| URL | Language |
|---|---|
/about |
en (default, prefix hidden) |
/de/about |
de |
/fr/about |
fr |
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
- 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. - From then on the URL decides:
/de/aboutshows German and remembers it in session and cookie. A link to plain/aboutsends that visitor back to/de/about. - One canonical URL per page: the default language has no prefix,
so
/en/aboutredirects to/about.
A language switcher is one helper call per language:
Route::localizedSwitcherUrl('fr'). See
Language Switcher.
Install
Then set your locales, register two middlewares and wrap your routes. The setup guide walks through the three steps.
Coming from mcamara/laravel-localization?
Same job, different wiring. Every localized route is a plain, static
Laravel route, so php artisan 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.
License & credits
MIT licensed. Created by Adam Nielsen, building on prior work by
@mcamara (original
laravel-localization),
@codezero-be (deprecated
laravel-localized-routes, whose static-route ideas inspired this
rewrite) and
@jordyvanderhaegen (current
maintainer of the original, whose
issue #921
motivated this package).
All versions of laravel-localizer with dependencies
codezero/browser-locale Version ^3.0
illuminate/support Version ^9.0 || ^10.0 || ^11.0 || ^12.0 || ^13.0