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

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

jersyfi/laravel-localization
============================

A package to localize a laravel application

v2.1.0(4y ago)1271MITPHPPHP ^7.2|^8.0

Since Feb 17Pushed 4y ago1 watchersCompare

[ Source](https://github.com/Jersyfi/laravel-localization)[ Packagist](https://packagist.org/packages/jersyfi/laravel-localization)[ Docs](https://github.com/jersyfi/laravel-localization)[ RSS](/packages/jersyfi-laravel-localization/feed)WikiDiscussions v2 Synced 2d ago

READMEChangelog (10)Dependencies (1)Versions (14)Used By (0)

A package to make your application localized
============================================

[](#a-package-to-make-your-application-localized)

[![Packagist Downloads](https://camo.githubusercontent.com/16b93060c3bd61c3ccae2b838a2f6b4ab40f8ff0db33af04ecf8ce90b54f20ee/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6572737966692f6c61726176656c2d6c6f63616c697a6174696f6e)](https://camo.githubusercontent.com/16b93060c3bd61c3ccae2b838a2f6b4ab40f8ff0db33af04ecf8ce90b54f20ee/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6572737966692f6c61726176656c2d6c6f63616c697a6174696f6e)[![Packagist Version](https://camo.githubusercontent.com/9365f37187d9e6009f6526a20d3e7256b3c09e20669aa97b2afca0a34ed5d898/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6572737966692f6c61726176656c2d6c6f63616c697a6174696f6e)](https://camo.githubusercontent.com/9365f37187d9e6009f6526a20d3e7256b3c09e20669aa97b2afca0a34ed5d898/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6572737966692f6c61726176656c2d6c6f63616c697a6174696f6e)[![GitHub License](https://camo.githubusercontent.com/08be6b58119643409886d7330e9d5a0d39dda9334bb1c85b9910ad01c9230c2b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a6572737966692f6c61726176656c2d6c6f63616c697a6174696f6e)](https://camo.githubusercontent.com/08be6b58119643409886d7330e9d5a0d39dda9334bb1c85b9910ad01c9230c2b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a6572737966692f6c61726176656c2d6c6f63616c697a6174696f6e)

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

[](#installation)

You can install the package via composer

```
composer require jersyfi/laravel-localization
```

You need to publish the config file to customize the package

```
php artisan vendor:publish --provider="Jersyfi\Localization\LocalizationServiceProvider" --tag="config"
```

You have the option to publish a migration file for adding a customizable column to a users table for storing the current locale for a logged in user. This is usefull if your application wants to send emails to every user.

```
php artisan vendor:publish --provider="Jersyfi\Localization\LocalizationServiceProvider" --tag="migrations"
```

The published config `localization` looks like so

```
return [

    /**
     * Applications default locale need to be set because the config('app.locale')
     * gives back the current locale and not the value from config
     */
    'default_locale' => 'de',

    /**
     * Application locales determines all locals that exists in the application
     * You can ignore or delete the locales from app.locales if you set some
     */
    'locales' => [
        'en',
        'de'
    ],

    /**
     * Redirect to default locale when not found
     */
    'redirect_default' => false,

    /**
     * Detect user locale via http header
     * When no locale is stored in session user gets redirected
     */
    'detect_locale' => false,

    /**
     * Application can store the prefered_locale in the users database table
     */
    'store_users_database' => true,

    /**
     * Setup for the users database table
     * Only if 'store_users_database' is set to true
     */
    'database' => [
        'users_table_name' => 'users',
        'prefered_locale_column_name' => 'prefered_locale',
    ],

];
```

How to use
----------

[](#how-to-use)

More information can be found in the original Laravel documentation with version 8.x. There you need to know everything about [Routing](https://laravel.com/docs/8.x/routing) and [Localization](https://laravel.com/docs/8.x/localization). When you also want to have translatable models i prefere to use [laravel-translatable](https://github.com/spatie/laravel-translatable) from Spatie.

### Routing

[](#routing)

The middleware is using `redirect_default` to redirect any request when the requested locale was not in `locales`. To detect the browser language when entering the page for the first time the `LocaleController` is using `detect_locale`.

You can redirect to the `default_locale` by accessing the `LocaleController` function called `localize` with the example:

```
use Jersyfi\Localization\Http\Controllers\LocaleController;

Route::get('/', [LocaleController::class, 'localize'])
    ->name('locale');
```

To group a route it is the easiest way to set a prefix named `{locale}` together with the middleware `locale`. Inside this group you can set your own localized routes. An example to get this localized route group:

```
Route::prefix('{locale}')
    ->middleware('locale')
    ->group(function () {

        // your localized routes here
    });
```

### Helpers

[](#helpers)

The helpers can be accesed directly by aliases or by facades. When using aliases in your controller you need to include `use Localization`. In below examples the used values are from the above config file so that you can compare it.

Return the given locale or the current app locale with replaced separator.

```
$slug = Localization::getLocaleSlug('en_GB'); // en-gb
$slug = Localization::getLocaleSlug(); // de
```

Return all available locales set in the localization config.

```
$locales = Localization::getLocales(); // ['en', 'de']
```

Return application default locale set in the localization config.

```
$locale = Localization::getDefaultLocale(); // de
```

Return all available locales from localization config without the default locale.

```
$locales = Localization::getLocalesWithoutDefault(); // ['en']
```

Return all available locales from localization config without the current locale.

```
$locales = Localization::getLocalesWithoutCurrent(); // ['de']
```

Return the current Route URL

```
$url = Localization::currentRouteURL(); // https://test.de/de/home?query=true
```

Return the current Route URL with any different locale set in the localization config. The function replaces the {locale} set in routes with the given locale.

```
$url = Localization::currentRouteLocaleURL('en'); // https://test.de/en/home?query=true
```

Return the current Route URL with default locale set in the localization config.

```
$url = Localization::currentRouteDefaultLocaleURL(); // https://test.de/de/home?query=true
```

Check if the locales are valid

```
$valid = Localization::localeIsValid('de'); // true
$valid = Localization::localeIsValid('de', 'en'); // true
$valid = Localization::localeIsValid('de', 'sp'); // false
```

Examples
--------

[](#examples)

### Route to named routes

[](#route-to-named-routes)

We create a simple index Route named `home` calling whatever you want. In this example we call a Controller. Then you can call your route from whereever you want with `route('home')`.

```
Route::get('/', [LocaleController::class, 'localize'])
    ->name('locale');

Route::prefix('{locale}')
    ->middleware('locale')
    ->group(function () {

        // your localized routes here
        Route::get('/', [HomeController::class, 'index'])
            ->name('home');
    });
```

```
Home
```

### Create a canonical link

[](#create-a-canonical-link)

You need to call the helper function `Localization::currentRouteDefaultLocaleURL()`

```

```

### Create alternate links

[](#create-alternate-links)

To get all alternate links without the default locale you can call the helper function `Localization::getLocalesWithoutDefault()` inside a foreach loop. Inside the href of the html you can call the helper function `Localization::currentRouteLocaleURL()` and pass the `$locale` to it.

```
@foreach(Localization::getLocalesWithoutDefault() as $locale)

@endforeach
```

### Create a language selector

[](#create-a-language-selector)

When you want to create a language selector first you need the current locale slug. For this you can call the helper function `Localization::getLocaleSlug()`. To loop the other locales you can decide if you want to display all available locales with `Localization::getLocales()` or if you want to display the available locales without the current locale with `Localization::getLocalesWithoutCurrent()`. Inside the foreach loop you can call the helper function `Localization::currentRouteLocaleURL($locale)` to get the link and `Localization::getLocalSlug($locale)` for the locale slug.

```
{{ Localization::getLocaleSlug() }}

    @foreach(Localization::getLocalesWithoutCurrent() as $locale)

            {{ Localization::getLocalSlug($locale) }}

    @endforeach

```

Changelog
---------

[](#changelog)

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

Credits
-------

[](#credits)

- [Jérôme Bastian Winkel](https://github.com/jersyfi)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity65

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

Recently: every ~4 days

Total

14

Last Release

1635d ago

Major Versions

v1.x-dev → v2.0.02021-11-04

PHP version history (2 changes)v1.2.1PHP ^8.0

v1.5.1PHP ^7.2|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/64214261?v=4)[Jérôme Bastian Winkel](/maintainers/jersyfi)[@Jersyfi](https://github.com/Jersyfi)

---

Top Contributors

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

---

Tags

laravellaravel-frameworklaravel-localizationlaravel-packagelocalizationlocalizemultilanguagephplaravellocalizationlocalelaravel localizationmultilangualjersyfi

### Embed Badge

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

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

###  Alternatives

[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)[jayesh/laravel-gemini-translator

An interactive command to extract and generate Laravel translations using Gemini AI.

691.7k1](/packages/jayesh-laravel-gemini-translator)[longman/laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x

5514.4k1](/packages/longman-laravel-multilang)[awes-io/localization-helper

Package for convenient work with Laravel's localization features

3527.1k4](/packages/awes-io-localization-helper)[cariboufute/locale-route

A testable route package with localization for Laravel 5 to 12

206.7k](/packages/cariboufute-locale-route)

PHPackages © 2026

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