langswitch
This commit is contained in:
parent
ad42e73126
commit
8d91d0e7a8
14 changed files with 792 additions and 76 deletions
13
app/Helpers/utils.php
Normal file
13
app/Helpers/utils.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
/**
|
||||
* Get an associative array with localeCodes as keys and translated URLs of current page as value
|
||||
*/
|
||||
function getLocalizedURLArray()
|
||||
{
|
||||
$localesOrdered = LaravelLocalization::getLocalesOrder();
|
||||
$localizedURLs = array();
|
||||
foreach ($localesOrdered as $localeCode => $properties) {
|
||||
$localizedURLs[$localeCode] = LaravelLocalization::getLocalizedURL($localeCode, null, [], true);
|
||||
}
|
||||
return $localizedURLs;
|
||||
}
|
42
app/Http/Controllers/Frontend/LocalizationController.php
Normal file
42
app/Http/Controllers/Frontend/LocalizationController.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Frontend;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Session;
|
||||
use App;
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class LocalizationController extends Controller
|
||||
{
|
||||
|
||||
// public function index(Request $request,$locale){
|
||||
// //set’s application’s locale
|
||||
// app()->setLocale($locale);
|
||||
|
||||
// //Gets the translated message and displays it
|
||||
// echo trans('lang.msg');
|
||||
// }
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('localization.index');
|
||||
}
|
||||
|
||||
public function setLocale($lang)
|
||||
{
|
||||
//if action is post method:
|
||||
//$lang = Input::get('language');
|
||||
|
||||
|
||||
//Session::put('locale', $lang);
|
||||
Session::put(['locale' => $lang]);
|
||||
// Session::save();
|
||||
|
||||
//return redirect(url(URL::previous()));
|
||||
return Redirect::back();
|
||||
// echo trans('document.msg');
|
||||
}
|
||||
}
|
|
@ -33,7 +33,7 @@ class Kernel extends HttpKernel
|
|||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
//\Opus4\Http\Middleware\Locale::class,
|
||||
\App\Http\Middleware\Locale::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
|
|
33
app/Http/Middleware/Locale.php
Normal file
33
app/Http/Middleware/Locale.php
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Session;
|
||||
use App;
|
||||
use Config;
|
||||
|
||||
class Locale
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
// if(!Session::has('locale'))
|
||||
// {
|
||||
// Session::put('locale', Config::get('app.locale'));
|
||||
// }
|
||||
$language = Session::get('locale', Config::get('app.locale'));
|
||||
// $data = Session::all();
|
||||
// $language =Session::get('locale1');
|
||||
|
||||
|
||||
App::setLocale($language);
|
||||
return $next($request);
|
||||
}
|
||||
}
|
|
@ -1,34 +1,35 @@
|
|||
<?php namespace App\Providers;
|
||||
<?php
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider {
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* This service provider is a great spot to register your various container
|
||||
* bindings with the application. As you can see, we are registering our
|
||||
* "Registrar" implementation here. You can add your own bindings too!
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->bind(
|
||||
'Illuminate\Contracts\Auth\Registrar'
|
||||
// 'App\Services\Registrar'
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* This service provider is a great spot to register your various container
|
||||
* bindings with the application. As you can see, we are registering our
|
||||
* "Registrar" implementation here. You can add your own bindings too!
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->bind(
|
||||
'Illuminate\Contracts\Auth\Registrar'
|
||||
// 'App\Services\Registrar'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,46 +5,46 @@ namespace App\Providers;
|
|||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* This namespace is applied to the controller routes in your routes file.
|
||||
*
|
||||
* In addition, it is set as the URL generator's root namespace.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $namespace = 'App\Http\Controllers';
|
||||
/**
|
||||
* This namespace is applied to the controller routes in your routes file.
|
||||
*
|
||||
* In addition, it is set as the URL generator's root namespace.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $namespace = 'App\Http\Controllers';
|
||||
|
||||
/**
|
||||
* Define your route model bindings, pattern filters, etc.
|
||||
*
|
||||
* @param \Illuminate\Routing\Router $router
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
parent::boot();
|
||||
/**
|
||||
* Define your route model bindings, pattern filters, etc.
|
||||
*
|
||||
* @param \Illuminate\Routing\Router $router
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
//
|
||||
}
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the routes for the application.
|
||||
*
|
||||
* @param \Illuminate\Routing\Router $router
|
||||
* @return void
|
||||
*/
|
||||
public function map()
|
||||
{
|
||||
/**
|
||||
* Define the routes for the application.
|
||||
*
|
||||
* @param \Illuminate\Routing\Router $router
|
||||
* @return void
|
||||
*/
|
||||
public function map()
|
||||
{
|
||||
//Route::group(['namespace' => $this->namespace], function()
|
||||
//{
|
||||
// require app_path('Http/routes.php');
|
||||
//});
|
||||
$this->mapApiRoutes();
|
||||
//});
|
||||
$this->mapApiRoutes();
|
||||
$this->mapWebRoutes();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "web" routes for the application.
|
||||
|
@ -58,9 +58,9 @@ class RouteServiceProvider extends ServiceProvider
|
|||
Route::middleware('web')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/web.php'));
|
||||
}
|
||||
|
||||
/**
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "api" routes for the application.
|
||||
*
|
||||
* These routes are typically stateless.
|
||||
|
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue