PHPackages                             outerweb/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. outerweb/localization

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

outerweb/localization
=====================

This package adds multi-language support to your Laravel application.

v1.1.1(2mo ago)2121MITPHPPHP ^8.0

Since Dec 26Pushed 2mo agoCompare

[ Source](https://github.com/outer-web/localization)[ Packagist](https://packagist.org/packages/outerweb/localization)[ Docs](https://github.com/outer-web/localization)[ RSS](/packages/outerweb-localization/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (5)Used By (0)

Localization
============

[](#localization)

[![Latest Version on Packagist](https://camo.githubusercontent.com/341dd26c6df02ba7e8e8e914cb1d35fcf040b5b1eba158f7e2bbf5b5dbb3de0a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f757465727765622f6c6f63616c697a6174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/outerweb/localization)[![Total Downloads](https://camo.githubusercontent.com/644d58abacc018178db55575941ac89a63b3511d01276b03b954fb6adf912da7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f757465727765622f6c6f63616c697a6174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/outerweb/localization)

This package adds multi-language support to your Laravel application:

- Multiple locales configuration
- Localized routes
- Translatable route segments
- Automatic user locale detection

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

[](#installation)

You can install the package via composer:

```
composer require outerweb/localization
```

Add the `Outerweb\Localization\Http\Middleware\SetLocale` middleware to the `web` middleware group in `app/Http/Kernel.php`: This will automatically set the locale for each request by going through the following steps:

1. Check if the locale is set in the URL (e.g. `http://example.com/en`)
2. Check if the locale is set in a cookie
3. Check for a matching locale in the preferred languages of the user's browser
4. Use the fallback locale

```
protected $middlewareGroups = [
    'web' => [
        // ...
        \Outerweb\Localization\Http\Middleware\SetLocale::class,
    ],
];
```

You can publish the config file with:

```
php artisan vendor:publish --tag="localization-config"
```

This is the contents of the published config file:

```
return [
    /**
     * The cookies that this package will use internally..
     * If your app already uses some other cookie name,
     * you can change it here to make it more uniform.
     */
    'cookies' => [
        'locale' => 'locale',
    ],

    /**
     * If you prefer to define this in config/app.php,
     * leave this as null. It will then fallback to
     * the app.fallback_locale config value.
     */
    'fallback_locale' => null,

    /**
     * If you prefer to define this in config/app.php,
     * leave this as null. It will then fallback to
     * the app.supported_locales config value.
     */
    'supported_locales' => null,

    /**
     * The name of the translations file in the
     * lang directory. (default: routes.php)
     */
    'translations_file_name' => 'routes',
];
```

Usage
-----

[](#usage)

### Defining routes

[](#defining-routes)

Define the routes you want to localize like this:

```
Route::localized(function () {
    Route::get('/', function () {
        return view('welcome');
    })
        ->name('home');
});
```

This will then generate the home route for each locale you have defined in the `supported_locales` config value.

For example, if you have defined `en` and `nl` as supported locales, the following routes will be generated:

- `http://example.com/en` (route name: `en.home`)
- `http://example.com/nl` (route name: `nl.home`)

You can also define a fallback route that will redirect to the localized route:

```
Route::fallback(function () {
    return redirect()->localizedRoute('home');
});
```

### Translating route segments

[](#translating-route-segments)

You can translate each route segment by adding it to the configured translations file in the `lang` directory.

For example, if you defined a route `/about-us` and you support the locales `en` and `nl`, you can add this to the configured translations files:

In `lang/en/routes.php`:

```
return [
    'about-us' => 'about-us',
];
```

In `lang/nl/routes.php`:

```
return [
    'about-us' => 'over-ons',
];
```

This will then generate the following routes:

- `http://example.com/en/about-us` (route name: `en.about-us`)
- `http://example.com/nl/over-ons` (route name: `nl.about-us`)

### Generating localized URLs

[](#generating-localized-urls)

When using localized routes, you cannot use the `route()` helper to generate URLs. Instead, you can use the `localizedRoute()` helper:

```
localizedRoute('home'); // http://example.com/en (route name: en.home)
localizedRoute('blog.show', ['blog' => 'my-blog-post']); // http://example.com/en/blog/my-blog-post (route name: en.blog.show)
localizedRoute('home', [], 'nl'); // http://example.com/nl (route name: nl.home)
```

As you can see above, this one takes the same parameters as the `route()` helper.

### Getting the localized routes for the current route

[](#getting-the-localized-routes-for-the-current-route)

You can get the localized routes for the current route like this:

```
localization()->localizedRoutesForCurrentRoute();
```

This will for example return the following array if you are on the 'about-us' page:

```
[
    'en' => 'http://example.com/en/about-us',
    'nl' => 'http://example.com/nl/over-ons',
]
```

This can be useful if you want to generate a language switcher.

### Getting the localized routes for a specific route

[](#getting-the-localized-routes-for-a-specific-route)

You can get the localized routes for a specific route like this:

```
localization()->localizedRoutesForRoute('home');
```

In this example, the result would be:

```
[
    'en' => 'http://example.com/en',
    'nl' => 'http://example.com/nl',
]
```

This can be useful if you want to tell Google about the other localized versions of a page. (See [this article](https://developers.google.com/search/docs/specialty/international/localized-versions) for more information)

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Credits
-------

[](#credits)

- [Simon Broekaert](https://github.com/SimonBroekaert)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance84

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 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 ~264 days

Total

4

Last Release

82d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d5a072b1191f02ac21a84af067a579b6f3323da7e45197369a7540f98c152407?d=identicon)[outerweb.be](/maintainers/outerweb.be)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[mcamara/laravel-localization

Easy localization for Laravel

3.5k9.1M112](/packages/mcamara-laravel-localization)[typicms/base

A modular multilingual CMS built with Laravel, enabling developers to manage structured content like pages, news, events, and more.

1.6k20.3k](/packages/typicms-base)[statikbe/laravel-filament-chained-translation-manager

A translation manager tool for Laravel Filament, that makes use of the Laravel Chained Translator.

92108.7k](/packages/statikbe-laravel-filament-chained-translation-manager)[outerweb/filament-translatable-fields

Filament integration for spatie/laravel-translatable

3582.9k8](/packages/outerweb-filament-translatable-fields)[cactus-galaxy/filament-astrotomic

Filament support for Astrotomic's Laravel Translatable package.

2516.3k](/packages/cactus-galaxy-filament-astrotomic)[34ml/filament-translatable-field

A laravel filament field that handle translation

182.7k](/packages/34ml-filament-translatable-field)

PHPackages © 2026

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