conquest/relay

Share localized, backend-driven messages as text to your Inertia frontend.

Fund package maintenance!
Jdw5

v0.1.0 2024-07-06 14:39 UTC

This package is auto-updated.

Last update: 2024-11-06 15:21:07 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.