Download the PHP package umbalaconmeogia/laravel-language-switcher without Composer
On this page you can find all versions of the php package umbalaconmeogia/laravel-language-switcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download umbalaconmeogia/laravel-language-switcher
More information about umbalaconmeogia/laravel-language-switcher
Files in umbalaconmeogia/laravel-language-switcher
Package laravel-language-switcher
Short Description A simple CSS framework independent Laravel package for language switching
License MIT
Informations about the package laravel-language-switcher
Laravel Language Switcher
A simple, CSS framework independent Laravel package for language switching.
Features
- ✅ Simple & Lightweight - No external dependencies
- ✅ CSS Framework Independent - Works with any CSS framework
- ✅ Pure Blade - No JavaScript required
- ✅ Easy to Customize - Simple CSS classes
- ✅ Session-based - Remembers language preference
Installation
Configuration
Quick Setup
Publish all assets and configuration:
Selective Publishing
Publish only specific assets:
Usage
1. Add routes to your routes/web.php:
2. Add the middleware to your application (optional but recommended):
In your bootstrap/app.php:
3. Include the language switcher in your views:
Using the Blade component (recommended):
Or using the include directive (legacy):
Component Options
The Blade component supports a style attribute for different style variants:
Note: The language switcher uses a simple, clean design with inline CSS for maximum compatibility. The dropdown appears on hover and works without JavaScript.
4. Customize supported languages in config/language-switcher.php:
Advanced Configuration
Language Detection Methods
The package supports multiple language detection methods:
- Session: Uses stored session preference
- URL: Uses URL parameter (e.g.,
?locale=en) - Header: Uses Accept-Language header
- All: Uses all methods in order (session → URL → header)
Middleware Features
- Path Exclusion: Skip language detection for specific paths
- Auto Detection: Automatic language detection from browser
- Session Storage: Store language preference in session
- Fallback Handling: Graceful fallback to default language
Component Configuration
- Style Variants: Default, minimal, compact styles
- Dropdown Position: Configurable dropdown positioning
- Animation: Customizable animation duration
- Flags Support: Optional flag display (future feature)
Security Features
- CSRF Protection: Built-in CSRF protection for language switching
- Rate Limiting: Configurable rate limiting for API endpoints
- Domain Restrictions: Restrict language switching to specific domains
API Support
- RESTful Endpoints: Get current language, supported languages
- JSON Responses: Standardized API responses
- Metadata Inclusion: Optional metadata in API responses
Enhanced Features
Console Commands
The package provides several artisan commands for management:
API Endpoints
When API is enabled, the package provides RESTful endpoints:
Example API responses:
Event System
The package fires events when languages are changed:
Conditional Asset Loading
The package automatically loads CSS assets only when needed:
- Assets are not loaded in console commands
- Assets are not loaded for API requests
- Assets can be disabled via configuration
View Data Sharing
The package automatically shares language data with all views:
Language Enum
The package provides a Language enum class for easy language management:
Middleware
The package includes a SetLocale middleware that automatically sets the application locale based on the user's language preference stored in the session. This middleware:
- Reads the locale from the session (set by the language switcher)
- Validates that the locale is supported
- Falls back to the default language if an unsupported locale is detected
- Sets the application locale using
app()->setLocale()
Manual Middleware Registration
If you prefer to register the middleware manually, you can add it to your app/Http/Kernel.php:
Customization
.language-switcher- Main container.language-switcher-button- Button styling.language-switcher-menu- Dropdown menu.language-switcher-item- Menu items.language-switcher-item.active- Active language
License
The MIT License (MIT). Please see License File for more information.