Download the PHP package tooinfinity/lingua without Composer
On this page you can find all versions of the php package tooinfinity/lingua. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tooinfinity/lingua
More information about tooinfinity/lingua
Files in tooinfinity/lingua
Package lingua
Short Description Zero-config localization for Laravel 12 with Inertia.js and React
License MIT
Informations about the package lingua
Lingua
⚠️ Under Development: This package is currently under active development and is not ready for production use.
Share Laravel translations with your Inertia.js + React frontend.
Quick Start
1. Install
This installs the Laravel package, publishes the config, and installs the React package (@tooinfinity/lingua-react).
2. Configure Locales
Edit config/lingua.php:
3. Middleware
The middleware is auto-registered to the web group by default. No action needed for most apps.
To disable auto-registration and add manually:
4. Create Translations
5. Use in React
Locale Switching
Translation Groups (Optional)
Load only the translations needed for a specific request by passing group names to the middleware. When no groups are provided, Lingua shares all translations.
You can also load specific groups manually via Lingua::translationsFor(['common', 'validation']).
API Reference
useTranslations() Hook
| Property | Type | Description |
|---|---|---|
__ |
function |
Translation function |
locale |
string |
Current locale |
locales |
string[] |
Supported locales |
direction |
'ltr' \| 'rtl' |
Text direction |
isRtl |
boolean |
Is RTL locale |
Facade
Fallback Locale Behavior
When a translation key is missing in the current locale, Lingua automatically fills it from the default locale. This applies to:
- PHP translation groups loaded via
Lingua::translationGroup()andLingua::translations() - JSON translations loaded via
Lingua::translations()whentranslation_driverisjson
If the current locale already matches the default locale, no fallback merge occurs.
Routes
| Method | URI | Description |
|---|---|---|
| POST | /locale |
Switch locale |
Note: The route prefix can be configured via
config('lingua.routes.prefix').
Translation File Formats
Lingua supports both PHP and JSON translation files. Configure the driver in config/lingua.php:
PHP Translations (Default)
PHP translations are organized in groups (files) under lang/{locale}/:
Shared to React as:
Access in React: __('messages.welcome')
JSON Translations
JSON translations use a flat key-value structure in lang/{locale}.json:
Shared to React as-is (flat structure):
Access in React: __('Welcome!') or __('auth.login')
Tip: JSON translations are ideal for simple apps or when using Laravel's
__()helper with literal string keys.
Advanced
Custom Controller
License
MIT License. See LICENSE.md.