代碼: 選擇全部
resources/lang/jp
resources/lang/tw
代碼: 選擇全部
Route::get('welcome/{locale}', function ($locale) {
App::setLocale($locale);
Session::put('locale', App::getLocale());
return redirect('/');
});
app/Http/Middleware/Locale.php
代碼: 選擇全部
namespace App\Http\Middleware;
use App;
use Closure;
use Config;
use Session;
class Locale
{
public function handle($request, Closure $next)
{
$language = Session::get('locale', Config::get('app.locale'));
//dd($language);
App::setLocale($language);
return $next($request);
}
}
代碼: 選擇全部
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\App\Http\Middleware\Locale::class,
],
代碼: 選擇全部
@lang('messages.Language')