From 41f24b9a3a87208f2516020f4e1b673018e5f7e8 Mon Sep 17 00:00:00 2001
From: printempw
Date: Thu, 15 Sep 2016 09:20:02 +0800
Subject: [PATCH] add menu for switching languages
---
app/Http/Controllers/AuthController.php | 52 +++++------
app/Http/Middleware/CheckAuthenticated.php | 16 ++--
app/Http/Middleware/Internationalization.php | 4 +-
config/locales.php | 4 +-
resources/lang/zh-CN/auth.yml | 48 ++++++++--
resources/lang/zh-CN/index.yml | 7 ++
resources/views/admin/master.tpl | 11 +++
resources/views/auth/bind.tpl | 4 +-
resources/views/auth/forgot.tpl | 4 +-
resources/views/auth/login.tpl | 4 +-
resources/views/auth/register.tpl | 4 +-
resources/views/auth/reset.tpl | 4 +-
resources/views/index.tpl | 25 +++--
resources/views/skinlib/master.tpl | 98 +++++++++++---------
resources/views/user/master.tpl | 11 +++
15 files changed, 192 insertions(+), 104 deletions(-)
create mode 100644 resources/lang/zh-CN/index.yml
diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php
index e26fd45f..a1869707 100644
--- a/app/Http/Controllers/AuthController.php
+++ b/app/Http/Controllers/AuthController.php
@@ -32,7 +32,7 @@ class AuthController extends Controller
} elseif ($request->has('username')) {
$auth_type = "username";
} else {
- return json('邮箱或角色名格式错误', 3);
+ return json(trans('auth.validation.identification'), 3);
}
// instantiate user
@@ -42,11 +42,11 @@ class AuthController extends Controller
if (session('login_fails', 0) > 3) {
if (strtolower($request->input('captcha')) != strtolower(session('phrase')))
- return json('验证码填写错误', 1);
+ return json(trans('auth.validation.captcha'), 1);
}
if (!$user->is_registered) {
- return json('用户不存在哦', 2);
+ return json(trans('auth.validation.user'), 2);
} else {
if ($user->checkPasswd($request->input('password'))) {
Session::forget('login_fails');
@@ -61,7 +61,7 @@ class AuthController extends Controller
return json([
'errno' => 0,
- 'msg' => '登录成功,欢迎回来~',
+ 'msg' => trans('auth.login.success'),
'token' => $user->getToken()
]);
} else {
@@ -70,7 +70,7 @@ class AuthController extends Controller
return json([
'errno' => 1,
- 'msg' => '邮箱或密码不对哦~',
+ 'msg' => trans('auth.login.password'),
'login_fails' => session('login_fails')
]);
}
@@ -85,9 +85,9 @@ class AuthController extends Controller
Session::flush();
- return json('登出成功~', 0);
+ return json(trans('auth.logout.success'), 0);
} else {
- return json('并没有有效的 session', 1);
+ return json(trans('auth.logout.failed'), 1);
}
}
@@ -96,14 +96,14 @@ class AuthController extends Controller
if (Option::get('user_can_register') == 1) {
return view('auth.register');
} else {
- throw new PrettyPageException('残念。。本皮肤站已经关闭注册咯 QAQ', 7);
+ throw new PrettyPageException(trans('auth.register.close'), 7);
}
}
public function handleRegister(Request $request)
{
if (strtolower($request->input('captcha')) != strtolower(session('phrase')))
- return json('验证码填写错误', 1);
+ return json(trans('auth.validation.captcha'), 1);
$this->validate($request, [
'email' => 'required|email',
@@ -131,18 +131,18 @@ class AuthController extends Controller
return json([
'errno' => 0,
- 'msg' => '注册成功,正在跳转~',
+ 'msg' => trans('auth.register.success'),
'token' => $user->getToken()
]);
} else {
- return json('你最多只能注册 '.Option::get('regs_per_ip').' 个账户哦', 7);
+ return json(trans('auth.register.max', ['regs' => Option::get('regs_per_ip')]), 7);
}
} else {
- return json('残念。。本皮肤站已经关闭注册咯 QAQ', 7);
+ return json(trans('auth.register.close'), 7);
}
} else {
- return json('这个邮箱已经注册过啦,换一个吧', 5);
+ return json(trans('auth.register.registered'), 5);
}
}
@@ -151,25 +151,25 @@ class AuthController extends Controller
if (config('mail.host') != "") {
return view('auth.forgot');
} else {
- throw new PrettyPageException('本站已关闭重置密码功能', 8);
+ throw new PrettyPageException(trans('auth.forgot.close'), 8);
}
}
public function handleForgot(Request $request)
{
if (strtolower($request->input('captcha')) != strtolower(session('phrase')))
- return json('验证码填写错误', 1);
+ return json(trans('auth.validation.captcha'), 1);
if (config('mail.host') == "")
- return json('本站已关闭重置密码功能', 1);
+ return json(trans('auth.forgot.close'), 1);
if (Session::has('last_mail_time') && (time() - session('last_mail_time')) < 60)
- return json('你邮件发送得太频繁啦,过 60 秒后再点发送吧', 1);
+ return json(trans('auth.forgot.frequent-mail'), 1);
$user = new User(null, ['email' => $request->input('email')]);
if (!$user->is_registered)
- return json('该邮箱尚未注册', 1);
+ return json(trans('auth.forgot.unregistered'), 1);
$uid = $user->uid;
$token = base64_encode($user->getToken().substr(time(), 4, 6).Utils::generateRndString(16));
@@ -181,15 +181,15 @@ class AuthController extends Controller
$site_name = Option::get('site_name');
$m->from(config('mail.username'), $site_name);
- $m->to($request->input('email'))->subject("重置您在 $site_name 上的账户密码");
+ $m->to($request->input('email'))->subject(trans('auth.mail.title', ['sitename' => $site_name]));
});
} catch(\Exception $e) {
- return json('邮件发送失败,详细信息:'.$e->getMessage(), 2);
+ return json(trans('auth.mail.failed', ['msg' => $e->getMessage()]), 2);
}
Session::put('last_mail_time', time());
- return json('邮件已发送,一小时内有效,请注意查收.', 0);
+ return json(trans('auth.mail.success'), 0);
}
public function reset()
@@ -197,24 +197,24 @@ class AuthController extends Controller
if (isset($_GET['uid']) && isset($_GET['token'])) {
$user = new User($_GET['uid']);
if (!$user->is_registered)
- return redirect('auth/forgot')->with('msg', '无效的链接');
+ return redirect('auth/forgot')->with('msg', trans('auth.reset.invalid'));
$token = substr(base64_decode($_GET['token']), 0, -22);
if ($user->getToken() != $token) {
- return redirect('auth/forgot')->with('msg', '无效的链接');
+ return redirect('auth/forgot')->with('msg', trans('auth.reset.invalid'));
}
$timestamp = substr(base64_decode($_GET['token']), strlen($token), 6);
// more than 1 hour
if ((substr(time(), 4, 6) - $timestamp) > 3600) {
- return redirect('auth/forgot')->with('msg', '链接已过期');
+ return redirect('auth/forgot')->with('msg', trans('auth.reset.expired'));
}
return view('auth.reset')->with('user', $user);
} else {
- return redirect('auth/login')->with('msg', '非法访问');
+ return redirect('auth/login')->with('msg', trans('auth.check.anonymous'));
}
}
@@ -229,7 +229,7 @@ class AuthController extends Controller
$user->changePasswd($request->input('password'));
- return json('密码重置成功', 0);
+ return json(trans('auth.reset.success'), 0);
}
diff --git a/app/Http/Middleware/CheckAuthenticated.php b/app/Http/Middleware/CheckAuthenticated.php
index e27cd81a..3e6fb3d1 100644
--- a/app/Http/Middleware/CheckAuthenticated.php
+++ b/app/Http/Middleware/CheckAuthenticated.php
@@ -2,12 +2,12 @@
namespace App\Http\Middleware;
-use App\Models\User;
-use App\Models\UserModel;
-use App\Exceptions\PrettyPageException;
use View;
use Http;
use Session;
+use App\Models\User;
+use App\Models\UserModel;
+use App\Exceptions\PrettyPageException;
class CheckAuthenticated
{
@@ -17,7 +17,7 @@ class CheckAuthenticated
$user = new User(session('uid'));
if (session('token') != $user->getToken())
- return redirect('auth/login')->with('msg', '无效的 token,请重新登录');
+ return redirect('auth/login')->with('msg', trans('auth.check.token'));
if ($user->getPermission() == "-1") {
// delete cookies
@@ -26,7 +26,7 @@ class CheckAuthenticated
Session::flush();
- throw new PrettyPageException('你已经被本站封禁啦,请联系管理员解决', 5);
+ throw new PrettyPageException(trans('auth.check.banned'), 5);
}
// ask for filling email
@@ -41,10 +41,10 @@ class CheckAuthenticated
return $next($request);
} else {
- echo View::make('auth.bind')->with('msg', '该邮箱已被占用');
+ echo View::make('auth.bind')->with('msg', trans('auth.validation.email'));
}
} else {
- echo View::make('auth.bind')->with('msg', '邮箱格式错误');
+ echo View::make('auth.bind')->with('msg', trans('auth.bind.registered'));
}
exit;
}
@@ -57,7 +57,7 @@ class CheckAuthenticated
return $next($request);
} else {
- return redirect('auth/login')->with('msg', '非法访问,请先登录');
+ return redirect('auth/login')->with('msg', trans('auth.check.anonymous'));
}
return $next($request);
diff --git a/app/Http/Middleware/Internationalization.php b/app/Http/Middleware/Internationalization.php
index 4c2ccaa5..6dabee97 100644
--- a/app/Http/Middleware/Internationalization.php
+++ b/app/Http/Middleware/Internationalization.php
@@ -2,9 +2,9 @@
namespace App\Http\Middleware;
-use Illuminate\Support\Arr;
-use Session;
use App;
+use Session;
+use Illuminate\Support\Arr;
class Internationalization
{
diff --git a/config/locales.php b/config/locales.php
index ddb1c517..64c15eff 100644
--- a/config/locales.php
+++ b/config/locales.php
@@ -9,6 +9,6 @@ return [
| Available Languages
|
*/
- 'zh-CN' => 'Chinese Simplified',
- 'en' => 'English'
+ 'zh-CN' => '简体中文',
+ 'en' => 'English'
];
diff --git a/resources/lang/zh-CN/auth.yml b/resources/lang/zh-CN/auth.yml
index 99fc3824..9f4e52e8 100644
--- a/resources/lang/zh-CN/auth.yml
+++ b/resources/lang/zh-CN/auth.yml
@@ -1,34 +1,70 @@
login:
- login: 登录
+ title: 登录
+ button: 登录
message: 登录以管理您的角色及皮肤
keep: 保持登录状态
+ success: 登录成功,欢迎回来~
+
+check:
+ anonymous: 非法访问,请先登录
+ banned: 你已经被本站封禁啦,请联系管理员解决
+ token: 无效的 token,请重新登录
register:
- register: 注册
+ title: 注册
+ button: 注册
message: 欢迎使用 :sitename!
nickname-intro: 昵称可使用汉字,不可包含特殊字符
repeat-pwd: 重复密码
+ close: 残念。。本皮肤站已经关闭注册咯 QAQ
+ success: 注册成功,正在跳转~
+ max: 你最多只能注册 :regs 个账户哦
+ registered: 这个邮箱已经注册过啦,换一个吧
forgot:
- forgot: 重置密码
+ title: 忘记密码
+ button: 发送
message: 我们将会向您发送一封验证邮件
- send: 发送
login-link: 我又想起来了
+ close: 本站已关闭重置密码功能
+ frequent-mail: 你邮件发送得太频繁啦,过 60 秒后再点发送吧
+ unregistered: 该邮箱尚未注册
mail:
+ title: 重置您在 :sitename 上的账户密码
+ success: 邮件已发送,一小时内有效,请注意查收。
+ failed: 邮件发送失败,详细信息::msg
message: 您收到这封邮件,是因为在 :sitename 的用户重置密码功能使用了您的地址。
ignore: 如果您并没有访问过我们的网站,或没有进行上述操作,请忽略这封邮件。 您不需要退订或进行其他进一步的操作。
reset: 重置密码
notice: 本邮件由系统自动发送,就算你回复了我们也不会回复你哦
reset:
- reset: 重置
+ title: 重置密码
+ button: 重置
+ invalid: 无效的链接
+ expired: 链接已过期
message: :username,在这里重置你的密码
+ success: 密码重置成功
bind:
- bind: 绑定
+ title: 绑定邮箱
+ button: 绑定
message: 你需要绑定邮箱地址以继续使用本站
introduction: 邮箱地址仅用于重置密码,我们将不会向您发送任何垃圾邮件
+ registered: 该邮箱已被占用
+
+
+validation:
+ identification: 邮箱或角色名格式错误
+ email: 邮箱格式错误
+ captcha: 验证码填写错误
+ user: 用户不存在哦
+ password: 邮箱或密码不对哦~
+
+logout:
+ success: 登出成功~
+ fail: 并没有有效的 session
nickname: 昵称
email: Email
diff --git a/resources/lang/zh-CN/index.yml b/resources/lang/zh-CN/index.yml
new file mode 100644
index 00000000..98c48f04
--- /dev/null
+++ b/resources/lang/zh-CN/index.yml
@@ -0,0 +1,7 @@
+index: 首页
+skinlib: 皮肤库
+langs: 语言
+user-center: 用户中心
+logout: 登出
+login: 登录
+register: 现在注册
diff --git a/resources/views/admin/master.tpl b/resources/views/admin/master.tpl
index 10f8cfe7..6b7f6adc 100644
--- a/resources/views/admin/master.tpl
+++ b/resources/views/admin/master.tpl
@@ -44,6 +44,17 @@
-
+
diff --git a/resources/views/auth/login.tpl b/resources/views/auth/login.tpl
index b18e9069..567ec1f8 100644
--- a/resources/views/auth/login.tpl
+++ b/resources/views/auth/login.tpl
@@ -1,6 +1,6 @@
@extends('auth.master')
-@section('title', trans('auth.login.login'))
+@section('title', trans('auth.login.title'))
@section('content')
@@ -47,7 +47,7 @@
-
+
diff --git a/resources/views/auth/register.tpl b/resources/views/auth/register.tpl
index a14d0253..cdcb7cc4 100644
--- a/resources/views/auth/register.tpl
+++ b/resources/views/auth/register.tpl
@@ -1,6 +1,6 @@
@extends('auth.master')
-@section('title', trans('auth.register.register'))
+@section('title', trans('auth.register.title'))
@section('content')
@@ -52,7 +52,7 @@
-
+
diff --git a/resources/views/auth/reset.tpl b/resources/views/auth/reset.tpl
index fcabd5e3..35466d90 100644
--- a/resources/views/auth/reset.tpl
+++ b/resources/views/auth/reset.tpl
@@ -1,6 +1,6 @@
@extends('auth.master')
-@section('title', trans('auth.forgot.reset'))
+@section('title', trans('auth.reset.title'))
@section('content')
@@ -31,7 +31,7 @@
-
+
diff --git a/resources/views/index.tpl b/resources/views/index.tpl
index 73a6ae73..076416e8 100644
--- a/resources/views/index.tpl
+++ b/resources/views/index.tpl
@@ -36,8 +36,19 @@
@@ -62,10 +73,10 @@
@@ -73,7 +84,7 @@
@else {{-- Anonymous User --}}
@endif
@@ -92,9 +103,9 @@
@if (is_null($user))
- 现在注册
+ {{ trans('index.register') }}
@else
- 用户中心
+ {{ trans('index.user-center') }}
@endif
diff --git a/resources/views/skinlib/master.tpl b/resources/views/skinlib/master.tpl
index d6e1a0ac..377dbfc1 100644
--- a/resources/views/skinlib/master.tpl
+++ b/resources/views/skinlib/master.tpl
@@ -73,49 +73,61 @@
-
+
diff --git a/resources/views/user/master.tpl b/resources/views/user/master.tpl
index 0b9905cd..b2de4b76 100644
--- a/resources/views/user/master.tpl
+++ b/resources/views/user/master.tpl
@@ -42,6 +42,17 @@