berthott / laravel-locale-middleware
Laravel Helper for localizing API routes
3.0.0
2023-02-16 08:45 UTC
Requires (Dev)
- orchestra/testbench: ^8.0
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-03-11 15:17:42 UTC
README
Laravel-Locale-Middleware
A helper for localizing API routes. Easily add a locale option to all your API routes.
Installation
$ composer require berthott/laravel-locale-middleware
Basic Usage
- The package automatically adds a
locale
query parameter to all your API routes. - Setting this
locale
query parameter will result in changing the Laravel locale for this specific request. - In order for localization to work you'll need to provide the corresponding localization files. See Laravel Lang for a convenient way to install these.
Alias / Middleware Groups
- By default the middleware will be added to your
api
Middleware Group. - You may set the
groups
option to an empty array, or an array of your custom Middleware Groups to add the middleware to. - In addition you could add the route directly via it's alias
locale
.
Options
To change the default options use
$ php artisan vendor:publish --provider="berthott\LocaleMiddleware\LocaleMiddlewareServiceProvider" --tag="config"
queryVariableName
: Specifies a custom name for the query parameter. Defaults tolocale
.groups
: An array of middleware groups to add the locale middleware to. Defaults to['api']
.
Compatibility
Tested with Laravel 10.x.
License
See License File. Copyright © 2023 Jan Bladt.