Enhancement #4257 implemented
This commit is contained in:
parent
225d01c1c6
commit
4b3be2b2ca
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Admin\Http\Middleware;
|
||||
|
||||
use Webkul\Core\Repositories\LocaleRepository;
|
||||
use Closure;
|
||||
|
||||
class Locale
|
||||
{
|
||||
/**
|
||||
* @var LocaleRepository
|
||||
*/
|
||||
protected $locale;
|
||||
|
||||
/**
|
||||
* @param \Webkul\Core\Repositories\LocaleRepository $locale
|
||||
*/
|
||||
public function __construct(LocaleRepository $locale)
|
||||
{
|
||||
$this->locale = $locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
$locale = request()->get('admin_locale');
|
||||
|
||||
if ($locale) {
|
||||
if ($this->locale->findOneByField('code', $locale)) {
|
||||
app()->setLocale($locale);
|
||||
|
||||
session()->put('admin_locale', $locale);
|
||||
}
|
||||
} else {
|
||||
if ($locale = session()->get('admin_locale')) {
|
||||
app()->setLocale($locale);
|
||||
} else {
|
||||
app()->setLocale(app()->getLocale());
|
||||
}
|
||||
}
|
||||
|
||||
unset($request['admin_locale']);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
Route::group(['middleware' => ['web']], function () {
|
||||
Route::group(['middleware' => ['web', 'admin_locale']], function () {
|
||||
Route::prefix(config('app.admin_url'))->group(function () {
|
||||
|
||||
Route::get('/', 'Webkul\Admin\Http\Controllers\Controller@redirectToLogin');
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
namespace Webkul\Admin\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Routing\Router;
|
||||
use Webkul\Admin\Http\Middleware\Locale;
|
||||
use Webkul\Core\Tree;
|
||||
|
||||
class AdminServiceProvider extends ServiceProvider
|
||||
|
|
@ -12,7 +14,7 @@ class AdminServiceProvider extends ServiceProvider
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
public function boot(Router $router)
|
||||
{
|
||||
$this->loadRoutesFrom(__DIR__ . '/../Http/routes.php');
|
||||
|
||||
|
|
@ -29,6 +31,8 @@ class AdminServiceProvider extends ServiceProvider
|
|||
|
||||
$this->registerACL();
|
||||
|
||||
$router->aliasMiddleware('admin_locale', Locale::class);
|
||||
|
||||
$this->app->register(EventServiceProvider::class);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,42 @@
|
|||
<span class="avatar">
|
||||
</span>
|
||||
|
||||
<?php $locale = request()->get('locale') ?: app()->getLocale();?>
|
||||
|
||||
<div class="profile-info">
|
||||
<div class="dropdown-toggle">
|
||||
<div style="display: inline-block; vertical-align: middle;">
|
||||
<span class="name">
|
||||
{{ __('admin::app.datagrid.locale') }}
|
||||
</span>
|
||||
|
||||
@foreach (core()->getAllLocales() as $localeModel)
|
||||
@if ($localeModel->code == $locale)
|
||||
<span class="role">
|
||||
{{ $localeModel->name }}
|
||||
</span>
|
||||
@endif
|
||||
@endforeach
|
||||
|
||||
</div>
|
||||
<i class="icon arrow-down-icon active"></i>
|
||||
</div>
|
||||
|
||||
<div class="dropdown-list bottom-right">
|
||||
<div class="control-group">
|
||||
<select class="control" id="locale-switcher" onChange="window.location.href = this.value" style="margin-left: 30px;">
|
||||
@foreach (core()->getAllLocales() as $localeModel)
|
||||
|
||||
<option value="{{ '?admin_locale=' . $localeModel->code }}" {{ ($localeModel->code) == $locale ? 'selected' : '' }}>
|
||||
{{ $localeModel->name }}
|
||||
</option>
|
||||
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="profile-info">
|
||||
<div class="dropdown-toggle">
|
||||
<div style="display: inline-block; vertical-align: middle;">
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
Route::group(['middleware' => ['web']], function () {
|
||||
Route::group(['middleware' => ['web', 'admin_locale']], function () {
|
||||
Route::prefix(config('app.admin_url') . '/velocity')->group(function () {
|
||||
Route::group(['middleware' => ['admin']], function () {
|
||||
Route::namespace('Webkul\Velocity\Http\Controllers\Admin')->group(function () {
|
||||
|
|
|
|||
Loading…
Reference in New Issue