Package Data | |
---|---|
Maintainer Username: | skooch |
Maintainer Contact: | skooch@gmail.com (Eric Scuccimarra) |
Package Create Date: | 2017-01-23 |
Package Last Update: | 2018-08-10 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-14 15:06:53 |
Package Statistics | |
---|---|
Total Downloads: | 33 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
A package to enable localization for Laravel on either a subdomain basis or from the session.
Via Composer
$ composer require escuccim/translate
Register the service provider in /config/app.php 'providers' array:
Escuccim\Translate\TranslateServiceProvider::class,
Register the middleware in /app/Http/Kernel.php in the 'web' array of the $middlewareGroups array:
'web' => [
...
\Escuccim\Translate\Http\Middleware\SetLanguage::class,
],
Make sure that the middleware is after the StartSession middleware if you wish to use session based translation.
Publish the config file with
php artisan vendor:publish
This will place the config file in /config/translate.php.
The config files has the following keys:
I also include a route: /setlang/{lang} Which sets a session variable to {lang} which will override the subdomain if it is set.
Lastly I include a function to output a Bootstrap drop-down menu which will use the data in the languages key of the config to generate links to set the language in session. This can be accessed with \Escuccim\Translate\TranslateClass::dropDown().
The middleware will first check if subdomain based translation is on, if so it will set the application locale to whatever is specified for the subdomain in the config file. Then if a session variable called 'locale' exists it will override the locale to correspond to the session. This allows you to default to a locale based on subdomain, but then have the user override this if they wish.
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING and CONDUCT for details.
If you discover any security related issues, please email skooch@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.