composer require goodcat/laravel-l10n
Laravel L10n
An opinionated Laravel package for app localization. Define localized routes, translate their URIs and domains, generate URLs in any language, and detect the user's preferred locale.
At a glance
Add lang() to a route and list the languages it should be available in. Translate its URI in your language files, if you want to:
Route::get('/products/{product}', [ProductController::class, 'show'])
->lang(['es', 'it'])
->name('products.show');
return [
'products/{product}' => 'productos/{product}',
];
Your application now serves the same page in three languages, each one with its own URL and its own application locale:
/products/42in English/es/productos/42in Spanish/it/products/42in Italian
Links keep working as before, and follow the language of the page the user is reading:
route('products.show', $product); // current language
route('products.show', [$product, 'lang' => 'es']); // "/es/productos/42"
Built on Laravel
laravel-l10n adds a single method to your routes and relies on what Laravel already provides for everything else:
- the fallback locale from
config/app.phpis the language of your original routes; - language files in
lang/hold the translated URIs, next to your other translations; - the
route()andaction()helpers, redirects and signed URLs generate localized URLs without new APIs; - route caching, middleware, route model binding and route groups work as usual on translated routes;
- the
HasLocalePreferenceinterface, already used by notifications and mailables, provides the user's preferred language.
If you know Laravel's routing, you already know most of laravel-l10n.
Guides
01
Localized Routes
Define localized routes and translate their URIs and domains.
Read more →
02
URL Generation
Generate URLs in the current language or in any other one.
Read more →
03
Locale Preference
Detect the user’s preferred language and redirect to it.
Read more →
04
JavaScript
Generate localized URLs with Wayfinder or Ziggy.
Read more →
Features
Helpers
Read the user’s preferred locales, get the route’s language, and match routes regardless of the locale.
Blade Components
Render alternate hreflang links and a locale switcher in your Blade layouts.
Localized Views
Organize language-specific Blade views in folders named after their locale.
Was this page helpful?
Thanks for your feedback!