定制 aristonis/laravel-language-switcher 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

aristonis/laravel-language-switcher

最新稳定版本:1.0

Composer 安装命令:

composer require aristonis/laravel-language-switcher

包简介

auto detected user language and set it for application with manully option for user to slelect language

README 文档

README

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.

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-01