Localizater Localization Package for Laravel

News

July 31st, 2020

Localizater is a Laravel package for wrapping routes in multiple locale prefixes.

Here’s an example from the readme of the basic usage when defining localized routes:

// routes/web.php
use Getsupercode\Localizater\Facades\Localizater;
use Illuminate\Support\Facades\Route;

Localizater::group(function () {
    Route::view('/', 'welcome')->name('welcome');
    Route::get('/user', 'UserController@index');
});

// Put other (Non-read) route actions outside the `Localizater::group` as you don't need to have multiple locales for those actions.

Route::post('/user', 'UserController@store');

This package will detect and change the locale of the application based on the request automatically via the provided middleware:

protected $middlewareGroups = [
    'web' => [
        \Getsupercode\Localizater\LocalizaterMiddleware::class,
        // ...
    ]
];

Finally, Localizater provides some route helpers to generate locale-based URLs:

// Route URL: example.com/fr/home
// Output: example.com/home
locale_route('home', 'en');

This package provides other configuration options such as defining a default locale, showing the locale in the URL for the default, and configuring the available locales.

You can learn more about this package, get full installation instructions, and view the source code on GitHub at Getsupercode/Localizater. The Laravel Localization documentation is another excellent resource for learning the localization support Laravel provides.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.