Repolode
mcamara

mcamara/laravel-localization

Laravel package for i18n URL localization: locale-prefixed routes, browser language detection, translatable route slugs and language selector helpers.

Stars
3,558
Forks
505
Open issues
11
Last commit
2 months ago

What is it?

Laravel Localization adds multilingual URL handling to Laravel applications. Routes are defined once inside a locale prefix group, and the package sets the application locale from the URL segment, so /en/about and /es/acerca both resolve to the same controller while App::getLocale() reflects the active language.

The package can detect a visitor's language from the browser's Accept-Language header, store the chosen locale in a session or cookie, and redirect requests to the localized URL. It can also hide the default locale in URLs, translate route segments through lang files, and provides helpers such as localizeUrl, getSupportedLocales and getCurrentLocaleDirection for building language selectors and locale-aware links.

Routes are generated per request, so php artisan route:cache is not supported by default; a LoadsTranslatedCachedRoutes trait and route:trans:cache command are provided for caching. The README also recommends a successor package, niels-numbers/laravel-localizer, for new projects that need native route caching.

Key features

  • 01Locale-prefixed route groups that let you define routes once for all languages.
  • 02Browser language detection through the Accept-Language header.
  • 03Session and cookie based locale redirect middleware.
  • 04Translatable route segments defined in lang/**/routes.php files.
  • 05Helpers for localized URLs, locale names, native names, direction and script.
  • 06Optional hiding of the default locale in URLs and custom locale URL mappings.

Use cases

  • Building a Laravel website that serves content in several languages under distinct URL prefixes.
  • Adding a language selector that links each page to its equivalent URL in other locales.
  • Serving translated slugs such as /en/article/... and /es/articulo/... for SEO-friendly multilingual sites.

Quick start

  1. 1

    Install the package with Composer

    composer require mcamara/laravel-localization
  2. 2

    Publish the config file

    php artisan vendor:publish --provider="Mcamara\LaravelLocalization\LaravelLocalizationServiceProvider"
  3. 3

    Wrap your localized routes in the LaravelLocalization::setLocale() route group in routes/web.php

Things to know

  • Routes are generated per request, so php artisan route:cache is not supported out of the box.
  • Laravel and PHP version support is tied to specific package versions listed in the compatibility table.

Topics

FAQ

What is laravel-localization?
Laravel package for i18n URL localization: locale-prefixed routes, browser language detection, translatable route slugs and language selector helpers. Laravel Localization adds multilingual URL handling to Laravel applications. Routes are defined once inside a locale prefix group, and the package sets the application locale from the URL segment, so /en/about and /es/acerca both resolve to the same controller while App::getLocale() reflects the active language.
Is laravel-localization free to use? What license does it have?
laravel-localization is open source under the MIT license. Check the license terms before using it in commercial products.
Is laravel-localization still maintained?
Updated within 6 months. The last commit to laravel-localization was on Aug 24, 2026.
What can I use laravel-localization for?
Building a Laravel website that serves content in several languages under distinct URL prefixes. Adding a language selector that links each page to its equivalent URL in other locales. Serving translated slugs such as /en/article/... and /es/articulo/... for SEO-friendly multilingual sites.
How do I install laravel-localization?
Install the package with Composer: composer require mcamara/laravel-localization Publish the config file: php artisan vendor:publish --provider="Mcamara\LaravelLocalization\LaravelLocalizationServiceProvider" Wrap your localized routes in the LaravelLocalization::setLocale() route group in routes/web.php
Where can I get laravel-localization?
The source code and installation instructions are on GitHub: https://github.com/mcamara/laravel-localization

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects