elsayed85 / nova-language-switch
A Laravel Nova package to switch language in your application
dev-master
2023-01-14 10:52 UTC
Requires
- php: ^7.3|^8.0
This package is not auto-updated.
Last update: 2024-11-17 17:27:53 UTC
README
This Nova tool lets you:
- Add a Language switcher to the header of the nova application.
- Handle Switch language and put the current locale to Laravel cache to remember language from multiple browsers.
- Switch the direction of the application based on the RTL-supported application written in config.
Requirements
-
php: >=8.0
-
laravel/nova: ^4.0
Note: This package dose't work with nova 3
Features
- Add multiple languages from the config.
- Remember set local based on cache no need to save in the database table
- Auto inject to the header of the application
- Just 4 steps to setup
Screenshot
Installation
You can install the nova tool in to a Laravel app that uses Nova via composer:
composer require badinansoft/nova-language-switch
Next up, you must register the tool with Nova. This is typically done in the tools
method of the NovaServiceProvider
.
// in app/Providers/NovaServiceProvider.php // ... public function tools() { return [ // ... new \Badinansoft\LanguageSwitch\LanguageSwitch(), ]; }
Next up, must you publish the config file with for add your languages:
php artisan vendor:publish --provider="Badinansoft\LanguageSwitch\ToolServiceProvider" --tag="config"
This is the contents of the published config file:
<?php return [ /** * List of languages that your application supports * array <string, string> */ 'supported-languages' => [ 'en' => 'English', 'ar' => 'Arabic', //here you can add new lanaguage or remove language that you need by 'local'=>'Label' ], /** * Languages That need RTL support * string * */ 'rtl-languages' => [ 'ar' //here put that language that need support RTL just put local of the language like this example for arabic ], ];
Finally you should register middleware This is typically done in the $middlewareGroups
property of the Http/Kernel
in web group.
/** * The application's route middleware groups. * @var array<string, array<int, class-string|string>> */ protected $middlewareGroups = [ 'web' => [ //... \Badinansoft\LanguageSwitch\Http\Middleware\LanguageSwitch::class ], //... ];
Credits
License
The MIT License (MIT). Please see License File for more information.