backpack / language-switcher
Language Switcher for Backpack
Installs: 12 666
Dependents: 1
Suggesters: 0
Security: 0
Stars: 11
Watchers: 5
Forks: 2
Open Issues: 1
Requires
- backpack/crud: ^6.0
- outhebox/blade-flags: ^1.2
Requires (Dev)
- phpstan/phpstan: ^1.10
README
This package adds a Language Switcher dropdown for projects using Backpack for Laravel.
Preview
Demo
Try it right now, in our online demo.
Installation
- 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
.
Usage
Can I show/hide the main label or flags?
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" ])
Can I use this package outside of the backpack/admin scope?
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, ],
Can I customize the endpoint routes ?
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'
Notes
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.
Security
If you discover any security related issues, please email cristian.tabacitu@backpackforlaravel.com instead of using the issue tracker.
Credits
License
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.