conquest / relay
Share localized, backend-driven messages as text to your Inertia frontend.
Fund package maintenance!
Jdw5
Requires
- php: ^8.2
- illuminate/contracts: ^10.0||^11.0
- inertiajs/inertia-laravel: ^1.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
README
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
Installation
You can install the package via composer:
composer require conquest/relay
You can publish and run the migrations with:
You can publish the config file with:
php artisan vendor:publish --tag="relay-config"
This is the contents of the published config file:
return [ 'share' => true, 'path' => base_path('lang'), 'languages' => [ 'en' => 'English', ], 'excludes' => [ 'validation.php', ], ];
Usage
Inside a controller, you can append translations to your application using the relay()
helper.
relay();
By default, this will share all translations from the lang
or the path
set in the config directory to the frontend. You can customize this behavior by publishing the config file and modifying the excludes
array. This array is cahced for each available language defined in the config('relay.languages')
array. You can select to only pass a subset of translations to the frontend by adding keys using dot notations to reduce the amount of data sent over the wire. This accepts wildcard characters as well.
relay()->keys('messages.*', 'auth.login')
Ensure that the RelaysTranslations
middleware is applied to any Inertia based routes. You can extend this middleware to overwrite the HandlesInertiaRequests
middleware in the Laravel starter packages, as this package itself extends the Inertia middleware.
Testing
composer test
Credits
License
The MIT License (MIT). Please see License File for more information.