My Blog Posts

Laravel Localization Package

Laravel Localization Package


Localizater is a Laravel package to add routes to more than one locale.

An example of basic use when defining localized paths:

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

Automatically detects and changes the application's locale through the middleware software provided by this package:

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

Finally, Localizater provides some route helpers to create 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 for the default URL, and configuring available locales.

You can learn more about this package, get all the setup instructions, and usethe source code at Getsupercode / Localizater on GitHub.



Share this article


Comments (0)

Comment