Skip to content

Commit 3082a57

Browse files
authored
Merge pull request pterodactyl#1128 from stanjg/feature/user-specific-language
Add support for user specific languages
2 parents c6112b4 + fd49e52 commit 3082a57

File tree

24 files changed

+51
-34
lines changed

24 files changed

+51
-34
lines changed

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ APP_CLEAR_TASKLOG=720
77
APP_DELETE_MINUTES=10
88
APP_ENVIRONMENT_ONLY=true
99
LOG_CHANNEL=daily
10+
APP_LOCALE=en
1011

1112
DB_HOST=127.0.0.1
1213
DB_PORT=3306
@@ -27,4 +28,4 @@ MAIL_FROM=no-reply@example.com
2728

2829
QUEUE_HIGH=high
2930
QUEUE_STANDARD=standard
30-
QUEUE_LOW=low
31+
QUEUE_LOW=low

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,7 @@ misc
2727
.phpstorm.meta.php
2828
.php_cs.cache
2929

30+
coverage.xml
31+
3032
# Vagrant
3133
*.log

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
1212
### Changed
1313
* Egg and server variable values are no longer limited to 191 characters. Turns out some games require a large number of characters in these fields.
1414

15+
### Added
16+
* Users can now select their preferred language in their account settings.
17+
1518
## v0.7.9 (Derelict Dermodactylus)
1619
### Fixed
1720
* Fixes a two-factor authentication bypass present in the password reset process for an account.

app/Http/Controllers/Base/AccountController.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
use Illuminate\Contracts\Session\Session;
99
use Pterodactyl\Http\Controllers\Controller;
1010
use Pterodactyl\Services\Users\UserUpdateService;
11+
use Pterodactyl\Traits\Helpers\AvailableLanguages;
1112
use Pterodactyl\Http\Requests\Base\AccountDataFormRequest;
1213

1314
class AccountController extends Controller
1415
{
16+
use AvailableLanguages;
17+
1518
/**
1619
* @var \Prologue\Alerts\AlertsMessageBag
1720
*/
@@ -48,7 +51,9 @@ public function __construct(AlertsMessageBag $alert, AuthManager $authManager, U
4851
*/
4952
public function index()
5053
{
51-
return view('base.account');
54+
return view('base.account', [
55+
'languages' => $this->getAvailableLanguages(true),
56+
]);
5257
}
5358

5459
/**
@@ -70,7 +75,7 @@ public function update(AccountDataFormRequest $request)
7075
if ($request->input('do_action') === 'email') {
7176
$data = ['email' => $request->input('new_email')];
7277
} elseif ($request->input('do_action') === 'identity') {
73-
$data = $request->only(['name_first', 'name_last', 'username']);
78+
$data = $request->only(['name_first', 'name_last', 'username', 'language']);
7479
} else {
7580
$data = [];
7681
}

app/Http/Middleware/LanguageMiddleware.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Pterodactyl\Http\Middleware;
114

125
use Closure;
136
use Illuminate\Http\Request;
147
use Illuminate\Foundation\Application;
15-
use Illuminate\Contracts\Config\Repository;
168

179
class LanguageMiddleware
1810
{
@@ -21,33 +13,26 @@ class LanguageMiddleware
2113
*/
2214
private $app;
2315

24-
/**
25-
* @var \Illuminate\Contracts\Config\Repository
26-
*/
27-
private $config;
28-
2916
/**
3017
* LanguageMiddleware constructor.
3118
*
32-
* @param \Illuminate\Foundation\Application $app
33-
* @param \Illuminate\Contracts\Config\Repository $config
19+
* @param \Illuminate\Foundation\Application $app
3420
*/
35-
public function __construct(Application $app, Repository $config)
21+
public function __construct(Application $app)
3622
{
3723
$this->app = $app;
38-
$this->config = $config;
3924
}
4025

4126
/**
42-
* Handle an incoming request.
27+
* Handle an incoming request and set the user's preferred language.
4328
*
4429
* @param \Illuminate\Http\Request $request
4530
* @param \Closure $next
4631
* @return mixed
4732
*/
4833
public function handle(Request $request, Closure $next)
4934
{
50-
$this->app->setLocale($this->config->get('app.locale', 'en'));
35+
$this->app->setLocale($request->user()->language ?? config('app.locale', 'en'));
5136

5237
return $next($request);
5338
}

resources/lang/en/base.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
'last_name' => 'Last Name',
7070
'update_identity' => 'Update Identity',
7171
'username_help' => 'Your username must be unique to your account, and may only contain the following characters: :requirements.',
72+
'language' => 'Language',
7273
],
7374
'security' => [
7475
'session_mgmt_disabled' => 'Your host has not enabled the ability to manage account sessions via this interface.',

0 commit comments

Comments
 (0)