2017 © Pedro Peláez
 

library laravel-locale-switcher

A Laravel locale switcher Middleware

image

lykegenes/laravel-locale-switcher

A Laravel locale switcher Middleware

  • Monday, May 28, 2018
  • by Lykegenes
  • Repository
  • 1 Watchers
  • 3 Stars
  • 650 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 9 Versions
  • 6 % Grown

The README.md

Laravel Locale Switcher

Latest Version on Packagist Software License ![Build Status][ico-github-action] Total Downloads, (*1)

A Simple Laravel middleware to easily load and switch the user's locale., (*2)

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, (*3)

``` bash composer require lykegenes/laravel-locale-switcher, (*4)


Then, add this to your Service Providers (It should be done automa) : ``` php Lykegenes\LocaleSwitcher\ServiceProvider::class,

and add this Alias [Optional] ``` php 'LocaleSwitcher' => Lykegenes\LocaleSwitcher\Facades\LocaleSwitcher::class,, (*5)


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. ``` php \Lykegenes\LocaleSwitcher\Middleware\SwitchLocaleMiddleware::class,

Optionally, you can publish and edit the configuration file : ``` bash php artisan vendor:publish --provider="Lykegenes\LocaleSwitcher\ServiceProvider" --tag=config, (*6)


## Usage To change the locale, simply add **"locale"** to the route parameters. It works for all your routes. Some examples :

http://my-app.com/?locale=en http://my-app.com/some/sub/route?locale=fr http://my-app.com/some/sub/route?locale=es&otherParam=value, (*7)

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.
```php
$url = action_localized('SomeController@someFunction', ['your' => 'parameters']);
$url = route_localized('someNamedRoute', ['your' => 'parameters']);

To build a URL to the same page, but with a different locale, use the switch_locale() helper., (*8)

$url = switch_locale('fr'); // URL of the French version of the current page.

You can easily generate a dropdown using the laravelcollective/html package :, (*9)

HTML::ul(LocaleSwitcher::getEnabledLocales());

Credits

License

The MIT License (MIT). Please see License File for more information., (*10)

The Versions

10/01 2016
14/09 2015

1.1.1

1.1.1.0 https://github.com/Lykegenes/laravel-locale-switcher

A Laravel locale switcher Middleware

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware locale switcher

08/08 2015

1.1

1.1.0.0 https://github.com/Lykegenes/laravel-locale-switcher

A Laravel locale switcher Middleware

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware locale switcher

13/07 2015

1.0.1

1.0.1.0 https://github.com/Lykegenes/laravel-locale-switcher

A Laravel locale switcher Middleware

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware locale switcher

13/07 2015

1.0.0

1.0.0.0 https://github.com/Lykegenes/laravel-locale-switcher

A Laravel locale switcher Middleware

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware locale switcher

13/07 2015

0.9.0

0.9.0.0 https://github.com/Lykegenes/laravel-locale-switcher

A Laravel locale switcher Middleware

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel middleware locale switcher