enadstack/laravel-localization
| Install | |
|---|---|
composer require enadstack/laravel-localization |
|
| Latest Version: | v0.1.0 |
| PHP: | ^8.3 |
| Laravel: | 11 · 12 · 13 |
| License: | MIT |
| Last Updated: | Oct 8, 2026 |
| Links: | GitHub · Packagist |
Laravel Localization
Cookie based, RTL aware language switching for Laravel + Inertia apps. Pairs with the
enadstack-ui-react components (use-translation, language-switcher, auth layouts).
SetLocalemiddleware (registered globally, reads an unencryptedlocalecookie)POST /localeroute (namelocale.update) that remembers the choice for a yearSharedPropsfor Inertia:locale,dir,localesandtranslations(sent once per locale)- Ready
en/arlang files (validation,passwords,pagination,ui)
Install
composer require enadstack/laravel-localization
php artisan vendor:publish --tag=localization-config # config/localization.php
php artisan vendor:publish --tag=localization-lang # lang/{en,ar}/...
Share the props in app/Http/Middleware/HandleInertiaRequests.php:
use Enadstack\Localization\Support\SharedProps;
public function share(Request $request): array
{
return [
...parent::share($request),
...app(SharedProps::class)->toArray(),
];
}
Set the default language with APP_LOCALE (the fallback is APP_FALLBACK_LOCALE).
Configure (config/localization.php)
| Key | Purpose |
|---|---|
locales |
code => ['label', 'dir'], each needs a lang/<code> folder |
cookie |
cookie name and lifetime |
register_middleware |
prepend SetLocale globally (turn off to register it yourself) |
route |
enable, uri, name and middleware of the switch route |
translations.groups |
lang files sent to the frontend. Never list validation or passwords. |
translations.ttl |
minutes the client keeps the once prop |
To add a language: add it to locales, create lang/<code>/*.php with the same keys.
Keep key parity with a test (see the TranslationFilesTest idea in the host app).
Why a global middleware?
Inertia sorts its middleware right after the session, ahead of the web group. The locale must be set
before Inertia builds its shared props, so SetLocale is prepended globally and the cookie is
excluded from encryption.
Documentation
Tests
composer install && composer test
Related Packages
Minimal i18n for Laravel Inertia — share PHP and JSON translations with t() and...
Bridge Laravel JSON translations with React apps built on Inertia.js
A fork of the official Laravel + Vue starter kit with built-in internationalizat...
A fork of the official Laravel + React starter kit with built-in internationaliz...
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| v0.1.0 | ^8.3 | ^11.0| | MIT |