mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2024-12-21 06:19:38 +08:00
add language-chooser for error pages
This commit is contained in:
parent
06aae6a164
commit
f6aadc71f0
@ -4,7 +4,6 @@ namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use App\Exceptions\PrettyPageException;
|
||||
use App\Http\Middleware\Internationalization;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Foundation\Validation\ValidationException;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
@ -49,9 +48,6 @@ class Handler extends ExceptionHandler
|
||||
*/
|
||||
public function render($request, Exception $e)
|
||||
{
|
||||
// call i18n middleware manually since http exceptions won't be sent through it
|
||||
(new Internationalization)->handle($request, function(){});
|
||||
|
||||
if ($e instanceof ModelNotFoundException) {
|
||||
$e = new NotFoundHttpException($e->getMessage(), $e);
|
||||
}
|
||||
|
@ -29,13 +29,10 @@ class Kernel extends HttpKernel
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\Internationalization::class,
|
||||
\App\Http\Middleware\SaveOptionRepository::class,
|
||||
],
|
||||
|
||||
'static' => [
|
||||
\App\Http\Middleware\Internationalization::class,
|
||||
],
|
||||
'static' => [],
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App;
|
||||
use Cookie;
|
||||
use Session;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class Internationalization
|
||||
{
|
||||
public function handle($request, \Closure $next)
|
||||
{
|
||||
// Load from cookie
|
||||
if (Cookie::has('locale')) {
|
||||
session(['locale' => Cookie::get('locale')]);
|
||||
}
|
||||
|
||||
if (Session::has('locale')) {
|
||||
// Set app locale dynamically
|
||||
App::setLocale(session('locale'));
|
||||
} else {
|
||||
App::setLocale($request->getPreferredLanguage());
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
@ -23,6 +23,9 @@ class BootServiceProvider extends ServiceProvider
|
||||
{
|
||||
View::addExtension('tpl', 'blade');
|
||||
|
||||
// set current locale
|
||||
$this->i18n($request);
|
||||
|
||||
// check dotenv
|
||||
if (!file_exists(base_path('.env'))) {
|
||||
throw new PrettyPageException(trans('setup.file.no-dot-env'), -1);
|
||||
@ -67,6 +70,15 @@ class BootServiceProvider extends ServiceProvider
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function i18n($request)
|
||||
{
|
||||
$locale = $request->input('lang') ?: ($request->cookie('locale') ?: $request->getPreferredLanguage());
|
||||
|
||||
app()->setLocale($locale);
|
||||
session()->set('locale', $locale);
|
||||
cookie()->queue('locale', $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @Author: printempw
|
||||
* @Date: 2016-07-28 13:15:18
|
||||
* @Last Modified by: printempw
|
||||
* @Last Modified time: 2016-12-31 17:08:19
|
||||
* @Last Modified time: 2017-01-08 14:59:42
|
||||
*/
|
||||
|
||||
@import "style.scss";
|
||||
@ -29,6 +29,7 @@ h1, h2 {
|
||||
color: #666;
|
||||
font-size: 24px;
|
||||
font-weight: 400;
|
||||
padding: 0px 0px 7px;
|
||||
}
|
||||
|
||||
p {
|
||||
|
@ -3,7 +3,9 @@
|
||||
@section('title', '403 Forbidden')
|
||||
|
||||
@section('content')
|
||||
<h1>403 Forbidden</h1>
|
||||
<h1>403 Forbidden
|
||||
@include('setup.wizard.language')
|
||||
</h1>
|
||||
|
||||
<p>{{ trans('errors.exception.message', ['msg' => $exception->getMessage() ?: trans('errors.http.msg-403')]) }}</p>
|
||||
@endsection
|
||||
|
@ -3,8 +3,9 @@
|
||||
@section('title', '404 Not Found')
|
||||
|
||||
@section('content')
|
||||
|
||||
<h1>404 Not Found</h1>
|
||||
<h1>404 Not Found
|
||||
@include('setup.wizard.language')
|
||||
</h1>
|
||||
|
||||
<p>{{ trans('errors.exception.message', ['msg' => $exception->getMessage() ?: trans('errors.http.msg-404')]) }}</p>
|
||||
@endsection
|
||||
|
@ -3,7 +3,9 @@
|
||||
@section('title', '503 Service Unavailable')
|
||||
|
||||
@section('content')
|
||||
<h1>Be right back.</h1>
|
||||
<h1>Be right back.
|
||||
@include('setup.wizard.language')
|
||||
</h1>
|
||||
|
||||
<p>{{ trans('errors.exception.message', ['msg' => $exception->getMessage() ?: trans('errors.http.msg-503')]) }}</p>
|
||||
@endsection
|
||||
|
@ -3,7 +3,9 @@
|
||||
@section('title', trans('errors.general.title'))
|
||||
|
||||
@section('content')
|
||||
<h1>{{ trans('errors.general.title') }}</h1>
|
||||
<h1>{{ trans('errors.general.title') }}
|
||||
@include('setup.wizard.language')
|
||||
</h1>
|
||||
|
||||
<p>{{ trans('errors.brief.message') }}</p>
|
||||
|
||||
|
@ -3,7 +3,9 @@
|
||||
@section('title', trans('errors.general.title'))
|
||||
|
||||
@section('content')
|
||||
<h1>{{ $level.': '.trans('errors.exception.title') }}</h1>
|
||||
<h1>{{ $level.': '.trans('errors.exception.title') }}
|
||||
@include('setup.wizard.language')
|
||||
</h1>
|
||||
|
||||
<p>{{ trans('errors.exception.message', ['msg' => $message]) }}</p>
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
<meta name="robots" content="noindex,nofollow" />
|
||||
<title>@yield('title') - Blessing Skin Server</title>
|
||||
<link rel="stylesheet" type="text/css" href="{{ assets('css/style.css') }}">
|
||||
<link rel="stylesheet" type="text/css" href="{{ assets('css/install.css') }}">
|
||||
</head>
|
||||
|
||||
<body class="container">
|
||||
@ -13,22 +14,15 @@
|
||||
|
||||
@yield('content')
|
||||
|
||||
<script>
|
||||
function refreshWithLangPrefer() {
|
||||
var e = document.getElementById("language-chooser");
|
||||
var lang = e.options[e.selectedIndex].value;
|
||||
|
||||
window.location = "?lang="+lang;
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
<style type="text/css">
|
||||
html { background: #f1f1f1; margin: 0 20px; font-weight: 400; }
|
||||
body { background: #FFF none repeat scroll 0% 0%; color: #444; font-family: Ubuntu, 'Microsoft Yahei', 'Microsoft Jhenghei', sans-serif; margin: 140px auto 25px; padding: 20px 20px 10px; max-width: 700px; box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.13); }
|
||||
h1, h2 { border-bottom: 1px solid #DEDEDE; clear: both; color: #666; font-size: 24px; }
|
||||
a:active, a:hover { color: #00a0d2; }
|
||||
a { color: #0073aa; }
|
||||
#logo a, p, h1, h2 { font-weight: 400; }
|
||||
#logo, h1, h2 { padding: 0px 0px 7px; }
|
||||
p { padding-bottom: 2px; font-size: 14px; line-height: 1.5; }
|
||||
#logo a { font-family: Minecraft, sans-serif; transition: all .2s ease-in-out; font-size: 50px; color: #666; height: 84px; line-height: 1.3em; margin: -130px auto 25px; padding: 0; outline: 0; text-decoration: none; overflow: hidden; display: block; }
|
||||
#logo a:hover { color: #42a5f5; }
|
||||
#logo { margin: 6px 0 14px; border-bottom: none; text-align: center; }
|
||||
/* Mobile phone */
|
||||
@media (max-width: 48em) { #logo a { font-size: 40px; } }
|
||||
@media (max-width: 35.5em) { #logo a { font-size: 30px; } }
|
||||
</style>
|
||||
</html>
|
||||
|
@ -3,7 +3,9 @@
|
||||
@section('title', trans('errors.general.title'))
|
||||
|
||||
@section('content')
|
||||
<h1>{{ trans('errors.general.title') }}</h1>
|
||||
<h1>{{ trans('errors.general.title') }}
|
||||
@include('setup.wizard.language')
|
||||
</h1>
|
||||
|
||||
<p>{{ trans('errors.exception.code', ['code' => $code]) }}</p>
|
||||
<p>{!! trans('errors.exception.message', ['msg' => $message]) !!}</p>
|
||||
|
Loading…
Reference in New Issue
Block a user