This package adds a Language Switcher dropdown for projects using Backpack for Laravel.
Try it right now, in our online demo.
- In your Laravel project, install this package:
composer require backpack/language-switcher
# optional: publish the config file
php artisan vendor:publish --provider="Backpack\LanguageSwitcher\LanguageSwitcherServiceProvider" --tag="config"
- Add the middleware to backpack config
config/backpack/base.php
:
'middleware_class' => [
...
\Backpack\LanguageSwitcher\Http\Middleware\LanguageSwitcherMiddleware::class,
],
Optionally, you may add the middleware to the web
, api
or other middleware groups where you may want to use the language switcher, in app/Http/Kernel.php
.
- Add the dropdown view to
topbar_right_content.blade.php
or wherever you need it:
@include('backpack.language-switcher::language-switcher')
- In order to add the available languages of your app, you'll need to enable them in the backpack crud config file
config/backpack/crud.php
'locales' => [
'en' => 'English',
'pt' => 'Portuguese',
'ro' => 'Romanian',
...
There you can set the array of locales
your app uses. Keep in mind the default locale of your app should remain in config.app.locale
and config.app.fallback_locale
.
Yes!
You can do it by sending special arguments to the component:
@include('backpack.language-switcher::LanguageSwitcher', [
'flags' => true, // true by default, change it to hide flags
'main_label' => false, // false by default, it may also be a string, for instance "Language"
])
Yes!
If you wish to use the language switcher on other parts of your app, you can do it by adding the middleware in app/Http/Kernel.php
.
You can, for instance, enable this for the whole web
middleware group, or the api
.
protected $middlewareGroups = [
'web' => [
...
\Backpack\LanguageSwitcher\Http\Middleware\LanguageSwitcherMiddleware::class,
],
Yes!
You can do it by publishing the config file php artisan vendor:publish --provider="Backpack\LanguageSwitcher\LanguageSwitcherServiceProvider" --tag="config"
.
There you can totally disable the package route and register your own, or change some behavior related with display urls.
Please take caution to protect the endpoint with throttling or any other security measure if you overwrite the routes. The default package route uses: 'throttle:60,1'
This package uses outhebox/blade-flags
to get the flags representing languages/locales.
If you find any issue with any with it, like a missing or wrong flag, you can report directly to the maintainer.
If you discover any security related issues, please email cristian.tabacitu@backpackforlaravel.com instead of using the issue tracker.
This project was released under MIT License, so you can install it on top of any Backpack & Laravel project. Please see the license file for more information.