Laravel package for wrapping routes in multiple locale prefixes

2.0.0 2020-09-28 11:29 UTC

This package is auto-updated.

Last update: 2021-11-11 10:02:55 UTC


Latest Version on Packagist Total Downloads Test StyleCI

Laravel package for wrapping routes in multiple locale prefixes.


Via Composer

composer require getsupercode/localizater

To detect and change the locale of the application based on the request automatically, you can add this middleware to your app/Http/Kernel:

protected $middlewareGroups = [
    'web' => [
        // ...


By default, the application locales are only going to be en and the default locale is not prefixed. If you want to prefix the default locale, please run the following command to publish the configuration file:

php artisan vendor:publish --provider="Getsupercode\Localizater\LocalizaterServiceProvider" --tag="config"

After installing the package, Adding the middleware and publishing the configuration file. You need to edit the configuration file config/localizater.php in order to add more locales.


The default locale is app.locale located at config/app.php file.

Config: localizater.locales

Add supported locales. It's recommended to write the locale value with its native language.

'locales' => [
    'en' => 'English',
    'fr' => 'Français',
    'ar' => 'العربية',

Config: localizater.rtl_locales

Add RTL direction locales.

'rtl_locales' => ['ar']

Config: localizater.prefix_default

If this option is set to true, Default locale URL will be prefixed.



Config: localizater.prefix_default_name

If this option is set to true, Default locale route name will be prefixed.


Method URI URI Name
GET HEAD /page
GET HEAD /fr/page


Method URI URI Name
GET HEAD /page page
GET HEAD /fr/page


The package will not override the route features you already know. It's just a wrapper function that will create multiple locale routes for you.

// 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');

The above example will give us:

Method URI Name
GET|HEAD / welcome
GET|HEAD /fr fr.welcome
GET|HEAD /user
GET|HEAD /fr/user fr.
POST /user

Route naming

If you add a name to a route it will be prepended by the locale key for example: (fr.welcome)

All locales without a name will have the same prefix name like fr.. And this is normal as you don't need its names.

Localizater attributes

You can add attributes to the localizer group function as you do with the route group function.

Localizater::group(['middleware' => 'auth'], function () {
    Route::view('/home', 'home')->name('home');


Localizater::group(function () {
    Route::group(['middleware' => 'auth'], function () {
        Route::view('/home', 'home')->name('home');

Get route URL in a specified locale

You can get the current route URL in different locale key:

// Current route URL:

locale_route(null, 'fr');

// Output:

Or a named route:

// Route URL:

locale_route('home', 'en');

// Output:

You can pass the same parameters as the route() function after the locale parameter.

// locale_route($route, $locale, $parameters, $absolute);

// Current route
locale_route(null, 'fr', ['status' => 'active'], true);

// Named route
locale_route('home', 'fr', ['status' => 'active'], true);

Get locale language name

You can get the value of the locale key in localizater.locales configuration for the current locale or a specified locale:

// Output: English

// Output: Français

// Output: العربية

Get HTML dir attribute based on current locale

You can get HTML dir attribute based on current locale. The package will search for RTL locales in localizater.rtl_locales config. If the current locale is listed there, The output will be rtl or ltr if it's not listed.

// Current locale is: ar
// Output: rtl

// Current locale is: en
// Output: ltr
<html dir="{{ locale_dir() }}"></html>

You can also get dir attribute for a specified locale:

// Output: rtl

Change log

Please see the changelog for more information on what has changed recently.


composer test


Please see for details.


If you discover any security related issues, please email instead of using the issue tracker.



MIT. Please see the license file for more information.