Package Data | |
---|---|
Maintainer Username: | 24aitor |
Maintainer Contact: | contact@aitorriba.com (Aitor Riba) |
Package Create Date: | 2016-11-28 |
Package Last Update: | 2017-12-21 |
Home Page: | https://aitorriba.com |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-23 03:10:09 |
Package Statistics | |
---|---|
Total Downloads: | 3,318 |
Monthly Downloads: | 2 |
Daily Downloads: | 0 |
Total Stars: | 22 |
Total Watchers: | 2 |
Total Forks: | 5 |
Total Open Issues: | 0 |
Localizer is a laravel package to change easily locale on laravel projects.
It's so simple to use, once it's installed, your App locale will change only by passing routes into localizer middleare.
Top features:
Running the command below:
composer require aitor24/localizer
Register the localizer service provider on config/app.php
.
Aitor24\Localizer\LocalizerServiceProvider::class,
Remind to add alias to use Localizer functions comfortably.
'Localizer' => Aitor24\Localizer\Facades\LocalizerFacade::class,
It will publish config file.
Running the command below:
php artisan vendor:publish --tag=localizer_config
Also you can publish your languages to modify or add.
php artisan vendor:publish --tag=localizer_languages
Publish migrations:
php artisan vendor:publish --tag=localizer_migrations
Running the command below:
php artisan migrate
Default values can be modified also on config/localizer.php
.
All routes in which you want to set language should be under the localizer's middleware to set at each request de App locale.
Route::group(['middleware' => 'localizer'], function () {
// Here your routes
});
Tip: /lang prefix will be changed on config
Following there are a little code snippet of a view to select and set languages:
@foreach (Localizer::allowedLanguages() as $code => $value)
<a href="{{ Localizer::setRouteHome($code) }}">{{ $value }}</a>
@endforeach
Returns an array with [$code => $language] for all allowed languages of config.
Get an array like [$code => $language] from an array of only $codes.
Get an array like [$language => $code] from an array of only $langs.
Used for modals or dropdowns
Returns the url to set up language and return back.
Also if you prefer to use directly route() function you can use it as following code:
{{ route('localizer::setLocale', ['locale' => $code]) }}
Used for language selection views
Returns the url to set language and return '/' url('/')
Also if you prefer to use directly route() function you can use it as following code:
{{ route('localizer::setLocaleHome', ['locale' => $code]) }}
Returns the language name of $code if specified or the current language setted if not.
Tip: Use App::getLocale() to get the current locale