New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

enadstack/laravel-localization

Cookie based multi-language (RTL aware) support for Laravel + Inertia apps: locale middleware, language switch route, shared Inertia props and ready en/ar lang files.
5
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
Maintainer: Enadabuzaid

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).

  • SetLocale middleware (registered globally, reads an unencrypted locale cookie)
  • POST /locale route (name locale.update) that remembers the choice for a year
  • SharedProps for Inertia: locale, dir, locales and translations (sent once per locale)
  • Ready en / ar lang 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

tooinfinity/lingua

Zero-config localization for Laravel 12 with Inertia.js and React

3 0
alecscodes/inertia-i18n

Minimal i18n for Laravel Inertia — share PHP and JSON translations with t() and...

1 0
sematico/laravel-inertia-i18n

Bridge Laravel JSON translations with React apps built on Inertia.js

51 0
catatsumuri/vue-starter-kit-i18n

A fork of the official Laravel + Vue starter kit with built-in internationalizat...

0 0
catatsumuri/react-starter-kit-i18n

A fork of the official Laravel + React starter kit with built-in internationaliz...

0 0

Version History

Version Released PHP Laravel License
v0.1.0 ^8.3 ^11.0|^12.0|^13.0 MIT