A helper for localizing API routes. Easily add a locale option to all your API routes.
$ composer require berthott/laravel-locale-middleware
- 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.
- 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
.
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']
.
Tested with Laravel 10.x.
See License File. Copyright © 2023 Jan Bladt.