bunker/laravel-localization
最新稳定版本:v1.0.0
Composer 安装命令:
composer require bunker/laravel-localization
包简介
this package implements cookie based localization in laravel v10.40.
README 文档
README
this package implements cookie based localization in laravel v10.40.
Installation
Install the package with composer
cd to-your-laravel-project-home-directory
composer require bunker/laravel-localization
next add this in Kernel.php
protected $middlewareGroups = [ 'web' => [ // \Bunker\LaravelLocalization\Middleware\SetLocale::class ],
Documentation
this middleware assumes that you a panel.php file in your project's config directory. in our case, mostly we use this config/panel.php in a scratch project. note that this package only need 'primary_language', 'available_languages'
<?php return [ 'avatar' => "/assets/images/avatar/avatar.jpg", 'avatar_path' => "/assets/images/avatar/", 'date_format' => 'Y-m-d', 'time_format' => 'H:i:s', 'primary_language' => 'en', 'available_languages' => ['en' => 'English', 'bd' => 'Bengali', 'sp' => 'Spanish'], 'registration_default_role' => 'User' ];
add this in your blade file to change language
<ul class="navbar-nav"> @if(count(config('panel.available_languages', [])) > 1) <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" href="#" id="languageDropdown" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> {{ strtoupper(app()->getLocale()) }} </a> <div class="dropdown-menu" aria-labelledby="languageDropdown"> @foreach(config('panel.available_languages') as $langLocale => $langName) <a class="dropdown-item {{ app()->getLocale() == $langLocale ? 'd-none': '' }}" href="{{ url()->current() }}?lang={{ $langLocale }}">{{ $langName }}</a> @endforeach </div> </li> @endif </ul>
now every route which has 'web' middleware attached, will be localized.
API Reference
Change language
GET example.com?lang=en
| Query | Type | Description |
|---|---|---|
lang |
string |
Required. item key from available_languages from panel.php |
Feedback
If you have any feedback, please reach out to us at vwaaala@gmail.com
统计信息
- 总下载量: 34
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GNU
- 更新时间: 2024-02-25