Laravel Language Integration
![Software License][ico-license]
![Coverage Status][ico-scrutinizer]
![Total Downloads][ico-downloads], (*1)
Provides functionality to dynamically change a Laravel current locale. Basically makes laravel multilingial from a users stand point.
, (*2)
Install
Via Composer, (*3)
``` bash
$ composer require danieldoinov/languageintegration, (*4)
This package has integrated geo-location that uses the following package
``Stevebauman\Location``
It should be installed automatically with this one but just in case that it isn't you can install it by running
```php
composer require stevebauman/location
You must add the providers in config/app.php, (*5)
``` php
Stevebauman\Location\LocationServiceProvider::class,
DanielDoinov\LanguageIntegration\LanguageIntegrationServiceProvider::class, (*6)
You can then publish the configuration files.
``` php
php artisan vendor:publish --provider="danieldoinov\LanguageIntegration\LanguageIntegrationProvider"
php artisan vendor:publish --provider="Stevebauman\Location\LocationServiceProvider"
Usage
What the package does is add one route and one middleware that handle the locale change.
out of the box it will give you the following options for changing the locale:, (*7)
```php
http://yourdomain.com/locale/[lang], (*8)
Linking to that url will change the applications locale to the one that you specified. The ```[lang]``` variable must a valid locale code and must be present in the ```config/languages.php``` configuration file. After the change of locale the route will redirect back with any other input present.
You can create links that change the locale dynamically my adding a ```?lang=[lang]``` to any route in you application.
The first time the application starts the middleware will look for a cookie with a preferred locale. If none is found it will geo-locate the user and switch to the configured locale based on country code.
You can configure all of that from ```config/languages.php``` as well as cookie name and route format.
Here is the default full configuration:
```php
'cookie_key' => 'current_locale',
'locale' => [
'en' => 'English',
'de' => 'Deutsche',
'es' => 'Español',
'ru' => 'Русский'
],
'country_code_to_locale' => [
'US' => 'en',
'GB' => 'en',
'CA' => 'en',
'UM' => 'en',
//spanish
'ES' => 'es',
//german
'DE' => 'de',
//Russion
'RU' => 'ru',
],
'route' => '/locale/{lang}',
'route_name' => 'setLocale'
Hope you like it and helps!, (*9)
Credits
License
The MIT License (MIT). Please see License File for more information., (*10)