lopatin96/laravel-lang-switcher

Laravel lang switcher

1.0.67 2024-12-09 00:22 UTC

README

Publish config

php artisan vendor:publish --tag="laravel-lang-switcher-config"

Add language code and names to the config config/laravel-lang-switcher.php:

'languages' => [
  'en' => 'English',
  'ru' => 'русский',
]

Include lang-switcher anywhere you want, for example in your footer:

@include('laravel-lang-switcher::lang-switcher.index')

// or

@include('laravel-lang-switcher::lang-switcher.index', ['align' => 'right'])

Add LangSwitcher middleware to middleware array in app/Http/Kernel.php:

  protected $middleware = [
        
        \Atin\LaravelLangSwitcher\Http\Middleware\LangSwitcher::class,
    ];

Publish images

php artisan vendor:publish --tag="laravel-lang-switcher-images"

Trait

Add HasLocale trait to User model

use Atin\LaravelLangSwitcher\Traits\HasLocale;

class User extends Authenticatable
{
    use HasLocale, …

Images

Set of images https://flagicons.lipis.dev

Migrations

Run migrations:

php artisan migrate

Publishing

Migrations

php artisan vendor:publish --tag="laravel-lang-switcher-migrations"

Localization

php artisan vendor:publish --tag="laravel-lang-switcher-lang"

Views

php artisan vendor:publish --tag="laravel-lang-switcher-views"

Images

php artisan vendor:publish --tag="laravel-lang-switcher-images"

Config

php artisan vendor:publish --tag="laravel-lang-switcher-config"