Download the PHP package sematico/laravel-inertia-i18n without Composer
On this page you can find all versions of the php package sematico/laravel-inertia-i18n. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sematico/laravel-inertia-i18n
More information about sematico/laravel-inertia-i18n
Files in sematico/laravel-inertia-i18n
Package laravel-inertia-i18n
Short Description Bridge Laravel JSON translations with React apps built on Inertia.js
License MIT
Homepage https://github.com/alessandrotesoro/laravel-inertia-i18n
Informations about the package laravel-inertia-i18n
Laravel Inertia i18n
Share Laravel JSON translations with an Inertia.js React application. The Composer package loads locale files and exposes them as Inertia props; the React package provides translation hooks and component interpolation.
| Package | Install from |
|---|---|
sematico/laravel-inertia-i18n |
Packagist |
@sematico/laravel-inertia-i18n-react |
npm |
[!NOTE] The React package reads an
i18nprop shared by the Laravel service provider. Keep<I18nProvider>inside your Inertia app tree.
Requirements
- PHP 8.2 or newer
- Laravel 11, 12, or 13
inertiajs/inertia-laravel3.x- React 19 and
@inertiajs/react3.x
Installation
Install the backend package:
The service provider registers itself through Laravel package discovery. Publish the configuration file only when you need to change its defaults:
Install the React package:
Backend setup
Create JSON files in Laravel's lang directory. The file name is the locale:
By default, the package shares this payload as page.props.i18n:
For locale switching, add the middleware to the routes that should accept the _locale query parameter:
HandleLocale validates locale names and stores an accepted locale in the session. Set supported_locales in the config file to restrict the accepted list.
React setup
Mount the provider once around the part of the tree that uses translations:
Use t, read the active locale, or request a locale reload:
t() supports Laravel-style plural forms and interpolation:
Use Trans when translated text contains named component tags:
Configuration
The published config/inertia-i18n.php file supports:
| Option | Default | Purpose |
|---|---|---|
auto_share |
true |
Share translations through the service provider |
prop_name |
i18n |
Name of the Inertia prop |
lang_path |
null |
Custom directory containing {locale}.json files |
supported_locales |
null |
Optional allow-list for HandleLocale |
Set auto_share to false when you want to call translationProps() from the SharesTranslations trait in your own Inertia middleware. If prop_name is changed, pass the same value to <I18nProvider propName="translations">.
Public API
I18nProviderreads the configured translation payload from Inertia page props.useTranslation()returnst,locale, andsetLocale.Transsupportsi18nKey,values,count,components, andas.InertiaI18n::translations()loads the current locale and merges missing keys from the Laravel fallback locale.InertiaI18n::toInertiaPayload()returns the locale, fallback locale, and translations.SharesTranslationsexposes the same payload for manual sharing.
Development
The package build writes distributable files to packages/react/dist. The published npm package contains that build output plus the project README and license file.
License
This package is open-sourced software licensed under the MIT license.
All versions of laravel-inertia-i18n with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^11.0||^12.0||^13.0
inertiajs/inertia-laravel Version ^3.0