Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Language Switcher Laravel Package

aristonis/laravel-language-switcher

Auto-detect and switch your Laravel app locale using browser headers, session, or custom detectors. Includes middleware for per-request locale setting, session persistence, optional user profile integration, and a Blade component plus controller route for manual language selection.

View on GitHub
Deep Wiki
Context7

Laravel Language Switcher

Total Downloads

Auto-detects user language from browser/session and sets it for the Laravel application. Provides manual selection via a form component.

Features

  • Automatic language detection (browser, session, custom detectors).
  • Session-based persistence.
  • User profile integration for authenticated users.
  • Blade component for language switcher.
  • Configurable supported languages and detectors.

Installation

  1. Install via Composer:

    composer require aristonis/laravel-language-switcher
    
  2. Publish config file:

    php artisan vendor:publish --provider="Aristonis\LaravelLanguageSwitcher\LaravelLanguageSwitcherServiceProvider" --tag="config"
    
  3. Register middleware

  4. Add route in routes/web.php:

    Route::post('/language-switch', [\Aristonis\LaravelLanguageSwitcher\Http\Controllers\LanguageSwitchController::class, 'update'])->name('language-switch.update');
    

Configuration

In config/language-switcher.php:

  • supported_languages: Array of supported locales (e.g., ['en' => 'English', 'ar' => 'Arabic']).
  • detectors: Enabled detectors (e.g., ['browser']).
  • session_key: Session key for locale (default: __lang).

Usage

Middleware

Automatically sets app()->setLocale() on each request.

Language Switcher Component

In Blade views:

<x-laravel-language-switcher-switcher />

Detectors

  • Browser: Detects from Accept-Language header.
  • Custom:
    • Extends: LanguageDetectorInterface
    • add new class on config file with array detectors

Manual Update

POST to /language-switch with locale field.

Publishing Views

php artisan vendor:publish --provider="Aristonis\LaravelLanguageSwitcher\LaravelLanguageSwitcherServiceProvider" --tag="views"

Changelog

Please see CHANGELOG for more information on what has changed recently.

Issues

Report issues at GitHub Issues.

Collaboration

Contributions welcome! Fork the repo, create a feature branch, and submit a pull request. See CONTRIBUTING for details.

Security Vulnerabilities

Email aristonis@outlook.com or report via Issues.

License

The MIT License (MIT). Please see License File for more information.

Support

For support, open an issue.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui