Package Data | |
---|---|
Maintainer Username: | zagovorichev |
Maintainer Contact: | zagovorichev@gmail.com (Alexander Zagovorichev) |
Package Create Date: | 2016-10-11 |
Package Last Update: | 2024-10-25 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-10 15:02:59 |
Package Statistics | |
---|---|
Total Downloads: | 188 |
Monthly Downloads: | 9 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
This package pulls in the framework agnostic Language Manager and provides seamless integration with Laravel 5.
Language manager: you can choose new language and it will be placed as App::setLocale($lang)
Language will be saved in SESSION and/or COOKIE
Also you can use URL
http://www.example.com/article/1?lang=en => http://en.example.com/en/article/1
composer require zagovorichev/laravel-languages
Add to the app.php (by default in /laravel/config/app.php) lines:
'providers' => [
// ...
Zagovorichev\Laravel\Languages\LanguageServiceProvider::class,
]
And new middleware into the Kernel.php (look in /laravel/app/Http/Kernel.php)
protected $middlewareGroups = [
'web' => [
// ...
\Zagovorichev\Laravel\Languages\Http\Middleware\LanguagesMiddleware\LanguagesMiddleware::class,
],
];
Language manager provides working with sessions, cookies, path and domain.
For changing system language send request with input lang. For example: ?lang=es
and in application you will have Spain locale.
All configurations stored in the languages.php file.
For making your own configuration copy file /laravel/vendor/zagovorichev/laravel-languages/config/languages.php
to the folder /laravel/config/.
If you need simple language manager you can use only 'session' and 'cookie' modes. Then you don't need to configure anything more.
For using DomainMapManger in your configuration file you should matched languages and domains
'domainMap' => [
'en' => 'www.example.com',
'es' => 'es.example.com',
'ua' => 'www.example.ua',
],
:warning: Notice: Please, use only DomainMap or Domain modes, otherwise the behaviour will be unpredictable.
Also you can provide regular expression in the configuration file.
'domainRegExp' => [
'reg' => '|^(http://)([a-z]{2})[\.]{0,1}(example\.com.*)$|ui',
'langPart' => 2,
]
And as a result you will have
http://www.example.en/post/234 => http://en.example.com/post/234 => http://es.example.com/post/234
:warning: Notice: Please, use only DomainMap or Domain modes, otherwise the behaviour will be unpredictable.
Similar to domains, you can provide regular expression:
'pathRegExp' => [
'reg' => '|([a-z]{2})(/.*)|ui',
'langPart' => 1, // lang part will be replaced with new lang
],
Each store has its own manager.
This package is licensed under the MIT license