naoray / laravel-localizer
Tool to manage multiple language app
Fund package maintenance!
Naoray
Installs: 11
Dependents: 0
Suggesters: 0
Security: 0
Stars: 14
Watchers: 1
Forks: 0
Open Issues: 0
Type:package
Requires
- codezero/laravel-localizer: ^1.4
- illuminate/routing: ^6.0|^7.0|^8.0
- illuminate/support: ^6.0|^7.0|^8.0
Requires (Dev)
- orchestra/testbench: ^4.0|^5.0|^6.0
This package is auto-updated.
Last update: 2021-07-01 00:11:18 UTC
README
Easily detect the language of your user from session
, cookie
, browser locale
or app setting
. Change locale with a get request to localizer::setLocale
and control which language version the user can see via localizer
middleware.
This package is using codezero/laravel-localizer behind the scenes and extends its functionality to include:
- add Route
localizer::setLocale
for changing locales - add Carbon store to get localized timestamps
- add Facade to use
allowedLocales()
method in views
Install
composer require naoray/laravel-localizer
Publish config with php artisan vendor:publish --provider="CodeZero\Localizer\LocalizerServiceProvider" --tag="config"
Usage
Add Supported Locales
Edit supported-locales
array of the localizer
config to include all allowed locales.
'supported-locales' => ['en', 'de']
Add Carbon Store
Add \Naoray\LaravelLocalizer\Stores\CarbonStore::class
to localizerstores
to enable the carbon store and sync current locale with carbon locale.
'stores' => [ CodeZero\Localizer\Stores\SessionStore::class, CodeZero\Localizer\Stores\CookieStore::class, CodeZero\Localizer\Stores\AppStore::class, Naoray\LaravelLocalizer\Stores\CarbonStore::class, ],
Use Localizer in middleware
Add localize
middleware to your web route in the RouteServiceProvider
//... protected function mapWebRoutes() { Route::middleware(['web', 'localize']) ->namespace($this->namespace) ->group(base_path('routes/web.php')); }
Or simply add it as a middleware to your route groups.
Add Change Locale routes in view
Add Localizer
Facade to app
config.
//... 'Localizer' => Naoray\LaravelLocalizer\Facades\LocalizerFacade::class,
In the view you can use allowedLocales()
to get all allowed locales in the view.
@foreach (Localizer::allowedLocales() as $locale) <a href="{{ route('localizer::setLocale', ['locale' => $locale]) }}">{{ strtoupper($locale)}}</a> @endforeach
Extend Functionalities
You can add new stores
and detectors
by implementing the corresponding interface. For more info visit codezero/laravel-localizer
Testing
Run the tests with:
vendor/bin/phpunit
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security-related issues, please email DummyAuthorEmail instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.