From 9a066474352c79c4dabcad0962828f7c93028bd2 Mon Sep 17 00:00:00 2001 From: stanjg Date: Fri, 4 May 2018 12:56:30 +0200 Subject: [PATCH 01/35] Added support for user specific languages --- .env.example | 3 ++- app/Http/Middleware/LanguageMiddleware.php | 7 ++++++- config/pterodactyl.php | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index e6eba87e0..571f93fc2 100644 --- a/.env.example +++ b/.env.example @@ -6,6 +6,7 @@ APP_TIMEZONE=America/New_York APP_CLEAR_TASKLOG=720 APP_DELETE_MINUTES=10 APP_ENVIRONMENT_ONLY=true +LANG_MUST_BE_GLOBAL=false DB_HOST=127.0.0.1 DB_PORT=3306 @@ -26,4 +27,4 @@ MAIL_FROM=no-reply@example.com QUEUE_HIGH=high QUEUE_STANDARD=standard -QUEUE_LOW=low +QUEUE_LOW=low \ No newline at end of file diff --git a/app/Http/Middleware/LanguageMiddleware.php b/app/Http/Middleware/LanguageMiddleware.php index 2e581f58f..f9fa40d04 100644 --- a/app/Http/Middleware/LanguageMiddleware.php +++ b/app/Http/Middleware/LanguageMiddleware.php @@ -13,6 +13,7 @@ use Closure; use Illuminate\Http\Request; use Illuminate\Foundation\Application; use Illuminate\Contracts\Config\Repository; +use Illuminate\Support\Facades\Auth; class LanguageMiddleware { @@ -47,7 +48,11 @@ class LanguageMiddleware */ public function handle(Request $request, Closure $next) { - $this->app->setLocale($this->config->get('app.locale', 'en')); + if (!Auth::check() || $this->config->get('pterodactyl.lang.global')) { + $this->app->setLocale($this->config->get('app.locale', 'en')); + } else { + $this->app->setLocale(Auth::user()->language); + } return $next($request); } diff --git a/config/pterodactyl.php b/config/pterodactyl.php index e06c709ef..f0379533b 100644 --- a/config/pterodactyl.php +++ b/config/pterodactyl.php @@ -161,6 +161,7 @@ return [ */ 'lang' => [ 'in_context' => env('PHRASE_IN_CONTEXT', false), + 'global' => env('LANG_MUST_BE_GLOBAL', false), ], /* From 9ae25538c36ec9b7e1600fa2c489957928e5f49a Mon Sep 17 00:00:00 2001 From: stanjg Date: Fri, 4 May 2018 13:08:41 +0200 Subject: [PATCH 02/35] Made it so users can switch languages themselves --- app/Http/Controllers/Base/AccountController.php | 9 +++++++-- resources/lang/en/base.php | 1 + resources/themes/pterodactyl/base/account.blade.php | 12 ++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Base/AccountController.php b/app/Http/Controllers/Base/AccountController.php index b6a433bb4..0c75e7a17 100644 --- a/app/Http/Controllers/Base/AccountController.php +++ b/app/Http/Controllers/Base/AccountController.php @@ -7,9 +7,12 @@ use Prologue\Alerts\AlertsMessageBag; use Pterodactyl\Http\Controllers\Controller; use Pterodactyl\Services\Users\UserUpdateService; use Pterodactyl\Http\Requests\Base\AccountDataFormRequest; +use Pterodactyl\Traits\Helpers\AvailableLanguages; class AccountController extends Controller { + use AvailableLanguages; + /** * @var \Prologue\Alerts\AlertsMessageBag */ @@ -39,7 +42,9 @@ class AccountController extends Controller */ public function index() { - return view('base.account'); + return view('base.account', [ + 'languages' => $this->getAvailableLanguages(true), + ]); } /** @@ -60,7 +65,7 @@ class AccountController extends Controller } elseif ($request->input('do_action') === 'email') { $data['email'] = $request->input('new_email'); } elseif ($request->input('do_action') === 'identity') { - $data = $request->only(['name_first', 'name_last', 'username']); + $data = $request->only(['name_first', 'name_last', 'username', 'language']); } $this->updateService->setUserLevel(User::USER_LEVEL_USER); diff --git a/resources/lang/en/base.php b/resources/lang/en/base.php index ee3fb1f37..981545f84 100644 --- a/resources/lang/en/base.php +++ b/resources/lang/en/base.php @@ -64,6 +64,7 @@ return [ 'last_name' => 'Last Name', 'update_identitity' => 'Update Identity', 'username_help' => 'Your username must be unique to your account, and may only contain the following characters: :requirements.', + 'language' => 'Language', ], 'security' => [ 'session_mgmt_disabled' => 'Your host has not enabled the ability to manage account sessions via this interface.', diff --git a/resources/themes/pterodactyl/base/account.blade.php b/resources/themes/pterodactyl/base/account.blade.php index 3c202f570..fdecdc820 100644 --- a/resources/themes/pterodactyl/base/account.blade.php +++ b/resources/themes/pterodactyl/base/account.blade.php @@ -90,6 +90,18 @@ +
+
+ +
+ +
+
+