PHPackages                             josiasmontag/laravel-localization - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. josiasmontag/laravel-localization

ActiveLibrary[Localization &amp; i18n](/categories/localization)

josiasmontag/laravel-localization
=================================

Localization for Laravel framework

1.0.3(1y ago)2336.2k↓40%5[3 issues](https://github.com/josiasmontag/laravel-localization/issues)MITPHPPHP &gt;=7.2.0CI failing

Since Aug 5Pushed 1y ago2 watchersCompare

[ Source](https://github.com/josiasmontag/laravel-localization)[ Packagist](https://packagist.org/packages/josiasmontag/laravel-localization)[ Docs](https://github.com/josiasmontag/laravel-localization)[ RSS](/packages/josiasmontag-laravel-localization/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (4)Versions (23)Used By (0)

Laravel Localization
====================

[](#laravel-localization)

[![Build Status](https://github.com/josiasmontag/laravel-localization/actions/workflows/run-tests.yml/badge.svg)](https://github.com/josiasmontag/laravel-localization/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/584f9cf800bffdcc359615a4d261c3f515adae0925a670fcea09688807183623/68747470733a2f2f706f7365722e707567782e6f72672f6a6f736961736d6f6e7461672f6c61726176656c2d6c6f63616c697a6174696f6e2f642f746f74616c2e737667)](https://packagist.org/packages/josiasmontag/laravel-localization)[![Latest Stable Version](https://camo.githubusercontent.com/91fa68614e11a775550c78b0a753ab02ebedb42ff94c7ddcc2533cfb990553ea/68747470733a2f2f706f7365722e707567782e6f72672f6a6f736961736d6f6e7461672f6c61726176656c2d6c6f63616c697a6174696f6e2f762f737461626c652e737667)](https://packagist.org/packages/josiasmontag/laravel-localization)[![License](https://camo.githubusercontent.com/97886a1c34f0b6794449157fc7b752ce16456f62e0cef9c427d27682fc4d8d03/68747470733a2f2f706f7365722e707567782e6f72672f6a6f736961736d6f6e7461672f6c61726176656c2d6c6f63616c697a6174696f6e2f6c6963656e73652e737667)](https://packagist.org/packages/josiasmontag/laravel-localization)

Introduction
------------

[](#introduction)

The Laravel Localization package is built for Laravel 5.5+ and provides:

- Localized routes with language URL prefixes.
- Domain based localized routes.
- Middleware to detect user language based on HTTP header and cookie.
- Redirect the user to the localized version.
- Possibility to hide the language URL prefix for the default language.
- Possibility to localize a subset of routes only.
- Language Switcher and Hreflang Meta Tags
- Patched `route()` method to use localized routes whenever possible.
- Compatibility with `artisan route:cache`.

Installation
------------

[](#installation)

To get started, use Composer to add the package to your project's dependencies:

```
composer require josiasmontag/laravel-localization

```

Add the `HandleLocalization` Middleware to the `web` group in `App/Http/Kernel.php`:

```
    protected $middlewareGroups = [
        'web' => [

            // Other Middleware

            \Lunaweb\Localization\Middleware\LocalizationHandler::class,
        ],
    ];
```

Configuration
-------------

[](#configuration)

To publish the config file to `config/localization.php`:

```
php artisan vendor:publish --provider "Lunaweb\Localization\LocalizationServiceProvider"

```

Default configuration:

```
return [

    // Add any language you want to support
    'locales' => [
        'en' => ['name' => 'English'],
        'de' => ['name' => 'German'],
    ],

    // The default locale is configured in config/app.php (locale)

    // Default locale will not be shown in the url.
    // If enabled and 'en' is the default language:
    // / -> English page, /de -> German page
    // If disabled:
    // /en -> English Page, /de -> German page
    'hide_default_locale_in_url' => true,

    // Use query parameter if there are no localized routes available.
    // Set it to null to disable usage of query parameter.
    'locale_query_parameter' => 'hl',

    // Enable redirect if there is a localized route available and the user locale was detected (via HTTP header or session)
    'redirect_to_localized_route' =>  true,

    // Try to detect user locale via Accept-Language header.
    'detect_via_http_header' => true,

    // Remember the user locale using a cookie.
    'remember_via_cookie' => true,

    // Cookie expire time in minutes
    'cookie_expires' => 20160 // 14 days

];
```

Usage
-----

[](#usage)

#### Prefix Based Localized Routes

[](#prefix-based-localized-routes)

To add localized routes with language prefixes, edit your `routes/web.php` and use `localizedRoutesGroup` helper:

```
Localization::localizedRoutesGroup(function() {
    Route::get('/', 'HomeController@uploadDocuments')->name('index');
    Route::get('/register', 'RegisterController@showRegisterForm')->name('register');
});
```

Under the hood this will create the following routes for you:

RouteRoute NameLanguage`/``index`English (Default Language)`/de``de.index`German`/fr``fr.index`French`/register``register`English (Default Language)`/de/register``de.register`German`/fr/register``fr.register`French#### Domain Based Localized Routes

[](#domain-based-localized-routes)

To add domain-based localized routes, add the localized domains to your `config/localization.php` configuration:

```
'locales' => [
   'en' => ['domain'=> 'domain.com', 'name' => 'English'],
   'de' => ['domain'=> 'domain.de', 'name' => 'German'],
   'fr' => ['domain'=> 'domain.fr', 'name' => 'French'],
],
```

The example from above will then create the following routes:

RouteRoute NameLanguage`domain.com``index`English (Default Language)`domain.de``de.index`German`domain.fr``fr.index`French`domain.com/register``register`English (Default Language)`domain.de/register``de.register`German`domain.fr/register``fr.register`French#### Localization Specific Routes

[](#localization-specific-routes)

You can manually create language specific routes using the `localization()` macro.

```
Route::get('/contact', 'ContactController@showContactForm')
    ->localization('en')
    ->name('contact');

Route::get('/kontakt', 'ContactController@showContactForm')
    ->localization('de')
    ->name('de.contact');
```

Helpers
-------

[](#helpers)

#### Localized route()

[](#localized-route)

`route()` will automatically use the localized version, if there is any available. Using the example from above, `route('index')` resolves to the `index`, `de.index` or `fr.index` route depending on the user's language.

#### Check if the current route is localized

[](#check-if-the-current-route-is-localized)

```
Localization::isLocalizedRoute()
```

or...

```
Route::current()->getLocalization() === null
```

#### Get the localization of the current route

[](#get-the-localization-of-the-current-route)

```
Route::current()->getLocalization()
```

#### Get the URL to a different language version of the current route

[](#get-the-url-to-a-different-language-version-of-the-current-route)

```
Localization::getLocaleUrl($localeCode)
```

#### Get the route name to a different language version of the current route

[](#get-the-route-name-to-a-different-language-version-of-the-current-route)

```
Localization::getLocaleRoute($localeCode)
```

#### Hreflang Meta Tags

[](#hreflang-meta-tags)

```
@if(Localization::isLocalizedRoute())
   @foreach(Localization::getLocales() as $localeCode => $properties)

   @endforeach
@endif
```

#### Language Switcher

[](#language-switcher)

```

    @foreach(Localization::getLocales() as $localeCode => $properties)

                 {{ $properties['native'] }}

    @endforeach

```

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance43

Moderate activity, may be stable

Popularity37

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~132 days

Recently: every ~408 days

Total

22

Last Release

414d ago

Major Versions

0.8.2 → 1.0.02022-02-09

PHP version history (4 changes)0.1.0PHP &gt;=5.6.0

0.4.0PHP &gt;=7.0.0

0.5.0PHP &gt;=7.1.0

0.6.0PHP &gt;=7.2.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/07b14ffb44d0a4e799d313482990b85e88f70d0f1a3bdbb9189134c499c4e695?d=identicon)[josiasmontag](/maintainers/josiasmontag)

---

Top Contributors

[![josiasmontag](https://avatars.githubusercontent.com/u/1945577?v=4)](https://github.com/josiasmontag "josiasmontag (41 commits)")

---

Tags

languagelaravellaravel-5-packagelocalizationphplaravellocalizationlanguage

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/josiasmontag-laravel-localization/health.svg)

```
[![Health](https://phpackages.com/badges/josiasmontag-laravel-localization/health.svg)](https://phpackages.com/packages/josiasmontag-laravel-localization)
```

###  Alternatives

[mcamara/laravel-localization

Easy localization for Laravel

3.5k9.1M112](/packages/mcamara-laravel-localization)[codezero/laravel-localized-routes

A convenient way to set up, manage and use localized routes in a Laravel app.

543638.1k4](/packages/codezero-laravel-localized-routes)[josiasmontag/laravel-redis-mock

This Laravel package provides a Redis mock for your tests

471.8M16](/packages/josiasmontag-laravel-redis-mock)[codezero/laravel-localizer

Automatically detect and set an app locale that matches your visitor's preference.

50394.3k4](/packages/codezero-laravel-localizer)[opgginc/codezero-laravel-localized-routes

A convenient way to set up, manage and use localized routes in a Laravel app.

2770.1k1](/packages/opgginc-codezero-laravel-localized-routes)[awes-io/localization-helper

Package for convenient work with Laravel's localization features

3527.1k4](/packages/awes-io-localization-helper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
