Download the PHP package lykegenes/laravel-locale-switcher without Composer
On this page you can find all versions of the php package lykegenes/laravel-locale-switcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lykegenes/laravel-locale-switcher
More information about lykegenes/laravel-locale-switcher
Files in lykegenes/laravel-locale-switcher
Package laravel-locale-switcher
Short Description A Laravel locale switcher Middleware
License MIT
Homepage https://github.com/patricksamson/laravel-locale-switcher
Informations about the package laravel-locale-switcher
Laravel Locale Switcher
A Simple Laravel middleware to easily load and switch the user's locale.
Version Compatibility
Laravel | Laravel Locale Switcher |
---|---|
5.x | 1.5.x |
6.x | 6.x |
7.x | 7.x |
8.x | 8.x |
9.x | 9.x |
Install
Via Composer
Then, add this to your Service Providers (It should be done automa) :
and add this Alias [Optional]
Finally, you will need to register this Middleware either in your Kernel.php
or directly in your routes.
This way, you can control which routes will have automatic locale detection (Web pages) or not (your API).
Make sure this middleware is placed after any Session or Cookie related middlewares from the framework.
Optionally, you can publish and edit the configuration file :
Usage
To change the locale, simply add "locale" to the route parameters. It works for all your routes. Some examples :
This will store the locale in the user's session, and set it as the current locale everytime the user requests a page.
You can build the routes with the included helpers. The URLs will be generated using the current locale.
To build a URL to the same page, but with a different locale, use the switch_locale()
helper.
You can easily generate a dropdown using the laravelcollective/html package :
Credits
- Patrick Samson
- All Contributors
License
The MIT License (MIT). Please see License File for more information.