Package Data | |
---|---|
Maintainer Username: | aayaresko |
Maintainer Contact: | aayaresko@gmail.com (Andrey Yaresko) |
Package Create Date: | 2016-09-29 |
Package Last Update: | 2016-09-29 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-19 03:19:30 |
Package Statistics | |
---|---|
Total Downloads: | 30 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 2 |
Total Forks: | 2 |
Total Open Issues: | 0 |
Multilingual routes and language switcher for laravel 5
The preferred way to install extension is via composer. Check the composer.json for this extension's requirements and dependencies.
To install, either run
$ php composer.phar require aayaresko/laravel-language "*"
or add
"aayaresko/laravel-language": "*"
to the require section of your composer.json.
After installing the Socialite library, register the aayaresko\language\ServiceProvider in your config/app.php configuration file:
'providers' => [
// Other service providers...
aayaresko\language\ServiceProvider::class,
],
Also, add the Language facade to the aliases array in your app configuration file:
'Language' => aayaresko\language\LanguageFacade::class,
Use Language::getLocale() method to add language prefix to your routes:
Route::group(['prefix' => Language::getLocale()], function () {
Route::get('/home', function () {
return view('frontend.index');
})->name('home');
});
Use Language::renderDropdownList() in your view-file to generate language dropdown list (note a exclamation marks):
{!! Language::renderDropdownList() !!}
This method takes 'locales' array which specified in you app.config file. It assumes that each 'locale' item key is a language 'code' and value is a 'visible_name'. You can control language item label content via Language::renderDropdownList() $label_template value:
{!! Language::renderDropdownList('{visible_name} ({code})') !!}
Label will look like this: 'English (en)' You can add additional items to any 'locale' item value and render that value in Language::renderDropdownList(). For example, if you added 'description' and your app.config looks something like this:
'locales' => [
'en' => [
'visible_name' => 'English',
'description' => 'Some simple text'
],
'ru' => 'Русский',
]
You can render 'description' item:
{!! Language::renderDropdownList('{visible_name} ({code}) {description}') !!}
Label will look like this: 'English (en) Some simple text'
You can customize html of language dropdown list. Simply run php ./artisan vendor:publish --tag=language and edit dropdown.blade.php template in your resources/views/vendor/language directory.