Skip to content

Commit 01d81bd

Browse files
committed
Getting somewhere on subuser stuff, adds i18n packages
1 parent 2a7fc46 commit 01d81bd

File tree

9 files changed

+215
-12
lines changed

9 files changed

+215
-12
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Pterodactyl\Http\Controllers\Base;
4+
5+
use Illuminate\Http\Request;
6+
use Illuminate\Http\JsonResponse;
7+
use Illuminate\Translation\Translator;
8+
use Pterodactyl\Http\Controllers\Controller;
9+
10+
class LocaleController extends Controller
11+
{
12+
/**
13+
* @var \Illuminate\Translation\Translator
14+
*/
15+
private $translator;
16+
17+
/**
18+
* LocaleController constructor.
19+
*
20+
* @param \Illuminate\Translation\Translator $translator
21+
*/
22+
public function __construct(Translator $translator)
23+
{
24+
$this->translator = $translator;
25+
}
26+
27+
/**
28+
* Returns translation data given a specific locale and namespace.
29+
*
30+
* @param \Illuminate\Http\Request $request
31+
* @param string $locale
32+
* @param string $namespace
33+
* @return \Illuminate\Http\JsonResponse
34+
*/
35+
public function __invoke(Request $request, string $locale, string $namespace)
36+
{
37+
$data = $this->translator->getLoader()->load($locale, str_replace('.', '/', $namespace));
38+
39+
return JsonResponse::create($data, 200, [
40+
'E-Tag' => md5(json_encode($data)),
41+
]);
42+
}
43+
}

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@
1414
"easy-peasy": "^3.0.2",
1515
"events": "^3.0.0",
1616
"formik": "^1.5.7",
17+
"i18next": "^19.0.0",
18+
"i18next-chained-backend": "^2.0.0",
19+
"i18next-localstorage-backend": "^3.0.0",
20+
"i18next-xhr-backend": "^3.2.2",
1721
"jquery": "^3.3.1",
1822
"lodash-es": "^4.17.15",
1923
"path": "^0.12.7",
2024
"query-string": "^6.7.0",
2125
"react": "^16.8.6",
2226
"react-dom": "^16.8.6",
2327
"react-hot-loader": "^4.12.13",
28+
"react-i18next": "^11.2.1",
2429
"react-redux": "^7.1.0",
2530
"react-router-dom": "^5.0.1",
2631
"react-transition-group": "^4.1.0",
Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,46 @@
11
import React from 'react';
22
import { SubuserPermission } from '@/state/server/subusers';
3+
import { useStoreState } from 'easy-peasy';
4+
import { ApplicationStore } from '@/state';
5+
import { useTranslation } from 'react-i18next';
36

47
interface Props {
58
defaultPermissions: SubuserPermission[];
69
}
710

811
export default ({ defaultPermissions }: Props) => {
9-
return null;
12+
const { t } = useTranslation('server.users');
13+
const permissions = useStoreState((state: ApplicationStore) => state.permissions.data);
14+
15+
return (
16+
<div>
17+
{
18+
permissions.map(permission => (
19+
<div className={'flex mb-2'} key={permission}>
20+
<input
21+
id={`permission_${permission}`}
22+
type={'checkbox'}
23+
name={'permissions[]'}
24+
value={permission}
25+
defaultChecked={defaultPermissions.indexOf(permission) >= 0}
26+
/>
27+
<label
28+
htmlFor={`permission_${permission}`}
29+
className={'flex-1 ml-3 text-sm text-neutral-200 cursor-pointer'}
30+
>
31+
{permission}
32+
<p className={'text-xs text-neutral-300'} style={{ textTransform: 'none' }}>
33+
{t(`server.users:permissions.${permission.replace('.', '_')}`)}
34+
</p>
35+
</label>
36+
</div>
37+
))
38+
}
39+
<div className={'mt-4 flex justify-end'}>
40+
<button className={'btn btn-primary btn-sm'}>
41+
Save Changes
42+
</button>
43+
</div>
44+
</div>
45+
);
1046
};

resources/scripts/components/server/users/UsersContainer.tsx

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import classNames from 'classnames';
99
import PermissionEditor from '@/components/server/users/PermissionEditor';
1010
import { Actions, useStoreActions, useStoreState } from 'easy-peasy';
1111
import { ApplicationStore } from '@/state';
12+
import { faArrowLeft } from '@fortawesome/free-solid-svg-icons/faArrowLeft';
1213

1314
export default () => {
1415
const [ loading, setLoading ] = useState(true);
@@ -45,10 +46,12 @@ export default () => {
4546
<div className={'flex my-10'}>
4647
<div className={'w-1/2'}>
4748
<h2 className={'text-neutral-300 mb-4'}>Subusers</h2>
48-
<div className={classNames('border-t-4 grey-box mt-0', {
49-
'border-cyan-400': editSubuser === null,
50-
'border-neutral-400': editSubuser !== null,
51-
})}>
49+
<div
50+
className={classNames('border-t-4 grey-box mt-0', {
51+
'border-cyan-400': editSubuser === null,
52+
'border-neutral-400': editSubuser !== null,
53+
})}
54+
>
5255
{(loading || !permissions.length) ?
5356
<div className={'w-full'}>
5457
<Spinner centered={true}/>
@@ -93,11 +96,21 @@ export default () => {
9396
{editSubuser &&
9497
<CSSTransition timeout={250} classNames={'fade'} appear={true} in={true}>
9598
<div className={'flex-1 ml-6'}>
96-
<h2 className={'text-neutral-300 mb-4'}>Edit {editSubuser.email}</h2>
97-
<div className={'border-t-4 border-cyan-400 grey-box mt-0'}>
98-
<PermissionEditor
99-
defaultPermissions={editSubuser.permissions}
100-
/>
99+
<h2 className={'flex items-center text-neutral-300 mb-4'}>
100+
<span onClick={() => setEditSubuser(null)}>
101+
<FontAwesomeIcon
102+
icon={faArrowLeft}
103+
className={'text-base mr-2 text-neutral-200 hover:text-neutral-100 cursor-pointer'}
104+
/>
105+
</span>
106+
Edit {editSubuser.email}
107+
</h2>
108+
<div className={'border-t-4 border-cyan-400 grey-box mt-0 p-4'}>
109+
<React.Suspense fallback={'Loading...'}>
110+
<PermissionEditor
111+
defaultPermissions={editSubuser.permissions}
112+
/>
113+
</React.Suspense>
101114
</div>
102115
</div>
103116
</CSSTransition>

resources/scripts/i18n.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import i18n from 'i18next';
2+
import { initReactI18next } from 'react-i18next';
3+
import LocalStorageBackend from 'i18next-localstorage-backend';
4+
import XHR from 'i18next-xhr-backend';
5+
import Backend from 'i18next-chained-backend';
6+
7+
i18n
8+
.use(Backend)
9+
.use(initReactI18next)
10+
.init({
11+
debug: process.env.NODE_ENV !== 'production',
12+
lng: 'en',
13+
fallbackLng: 'en',
14+
keySeparator: '.',
15+
backend: {
16+
backends: [
17+
LocalStorageBackend,
18+
XHR,
19+
],
20+
backendOptions: [{
21+
prefix: 'pterodactyl_lng__',
22+
expirationTime: 7 * 24 * 60 * 60 * 1000, // 7 days, in milliseconds
23+
store: window.localStorage,
24+
}, {
25+
loadPath: '/locales/{{lng}}/{{ns}}.json',
26+
}],
27+
},
28+
});
29+
30+
// i18n.loadNamespaces(['validation']);
31+
32+
export default i18n;

resources/scripts/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import * as React from 'react';
2-
import * as ReactDOM from 'react-dom';
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
33
import App from '@/components/App';
4+
import './i18n';
45

56
ReactDOM.render(<App/>, document.getElementById('app'));

resources/styles/components/forms.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,26 @@ a.btn {
219219
cursor: default;
220220
}
221221
}
222+
223+
input[type="checkbox"], input[type="radio"] {
224+
@apply .appearance-none .inline-block .align-middle .select-none .flex-no-shrink .w-4 .h-4 .text-primary-400 .border .border-neutral-300 .rounded-sm;
225+
color-adjust: exact;
226+
background-origin: border-box;
227+
transition: all 75ms linear, box-shadow 25ms linear;
228+
229+
&:checked {
230+
@apply .border-transparent .bg-no-repeat .bg-center;
231+
background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M5.707 7.293a1 1 0 0 0-1.414 1.414l2 2a1 1 0 0 0 1.414 0l4-4a1 1 0 0 0-1.414-1.414L7 8.586 5.707 7.293z'/%3e%3c/svg%3e");
232+
background-color: currentColor;
233+
background-size: 100% 100%;
234+
}
235+
236+
&:focus {
237+
@apply .outline-none .border-primary-300;
238+
box-shadow: 0 0 0 1px rgba(9, 103, 210, 0.25);
239+
}
240+
}
241+
242+
input[type="radio"] {
243+
@apply .rounded-full;
244+
}

routes/base.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
Route::get('/', 'IndexController@index')->name('index')->fallback();
44
Route::get('/account', 'IndexController@index')->name('account');
55

6+
Route::get('/locales/{locale}/{namespace}.json', 'LocaleController')
7+
->where('namespace', '.*');
8+
69
/*
710
|--------------------------------------------------------------------------
811
| Account API Controller Routes

yarn.lock

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,12 @@
747747
dependencies:
748748
regenerator-runtime "^0.13.2"
749749

750+
"@babel/runtime@^7.3.1", "@babel/runtime@^7.5.5":
751+
version "7.7.2"
752+
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.7.2.tgz#111a78002a5c25fc8e3361bedc9529c696b85a6a"
753+
dependencies:
754+
regenerator-runtime "^0.13.2"
755+
750756
"@babel/runtime@^7.4.2":
751757
version "7.5.5"
752758
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.5.5.tgz#74fba56d35efbeca444091c7850ccd494fd2f132"
@@ -4141,6 +4147,12 @@ html-minifier@^3.2.3:
41414147
relateurl "0.2.x"
41424148
uglify-js "3.3.x"
41434149

4150+
html-parse-stringify2@2.0.1:
4151+
version "2.0.1"
4152+
resolved "https://registry.yarnpkg.com/html-parse-stringify2/-/html-parse-stringify2-2.0.1.tgz#dc5670b7292ca158b7bc916c9a6735ac8872834a"
4153+
dependencies:
4154+
void-elements "^2.0.1"
4155+
41444156
html-webpack-plugin@^3.2.0:
41454157
version "3.2.0"
41464158
resolved "https://registry.yarnpkg.com/html-webpack-plugin/-/html-webpack-plugin-3.2.0.tgz#b01abbd723acaaa7b37b6af4492ebda03d9dd37b"
@@ -4224,6 +4236,30 @@ humps@^2.0.1:
42244236
version "2.0.1"
42254237
resolved "https://registry.yarnpkg.com/humps/-/humps-2.0.1.tgz#dd02ea6081bd0568dc5d073184463957ba9ef9aa"
42264238

4239+
i18next-chained-backend@^2.0.0:
4240+
version "2.0.0"
4241+
resolved "https://registry.yarnpkg.com/i18next-chained-backend/-/i18next-chained-backend-2.0.0.tgz#faf2e8b5f081a01e74fbec1fe580c184bc64e25b"
4242+
dependencies:
4243+
"@babel/runtime" "^7.4.5"
4244+
4245+
i18next-localstorage-backend@^3.0.0:
4246+
version "3.0.0"
4247+
resolved "https://registry.yarnpkg.com/i18next-localstorage-backend/-/i18next-localstorage-backend-3.0.0.tgz#19b4e836e9a79e564631b88b8ba1c738375e636f"
4248+
dependencies:
4249+
"@babel/runtime" "^7.4.5"
4250+
4251+
i18next-xhr-backend@^3.2.2:
4252+
version "3.2.2"
4253+
resolved "https://registry.yarnpkg.com/i18next-xhr-backend/-/i18next-xhr-backend-3.2.2.tgz#769124441461b085291f539d91864e3691199178"
4254+
dependencies:
4255+
"@babel/runtime" "^7.5.5"
4256+
4257+
i18next@^19.0.0:
4258+
version "19.0.0"
4259+
resolved "https://registry.yarnpkg.com/i18next/-/i18next-19.0.0.tgz#5418207d7286128e6cfe558e659fa8c60d89794b"
4260+
dependencies:
4261+
"@babel/runtime" "^7.3.1"
4262+
42274263
iconv-lite@0.4.24, iconv-lite@^0.4.24, iconv-lite@~0.4.13:
42284264
version "0.4.24"
42294265
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
@@ -6909,6 +6945,13 @@ react-hot-loader@^4.12.13:
69096945
shallowequal "^1.1.0"
69106946
source-map "^0.7.3"
69116947

6948+
react-i18next@^11.2.1:
6949+
version "11.2.1"
6950+
resolved "https://registry.yarnpkg.com/react-i18next/-/react-i18next-11.2.1.tgz#a56d9f1f52d003eb4fa8f1c7d6752123827160f0"
6951+
dependencies:
6952+
"@babel/runtime" "^7.3.1"
6953+
html-parse-stringify2 "2.0.1"
6954+
69126955
react-is@^16.6.0, react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.6:
69136956
version "16.8.6"
69146957
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.6.tgz#5bbc1e2d29141c9fbdfed456343fe2bc430a6a16"
@@ -8394,6 +8437,10 @@ vm-browserify@^1.0.1:
83948437
version "1.1.0"
83958438
resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-1.1.0.tgz#bd76d6a23323e2ca8ffa12028dc04559c75f9019"
83968439

8440+
void-elements@^2.0.1:
8441+
version "2.0.1"
8442+
resolved "https://registry.yarnpkg.com/void-elements/-/void-elements-2.0.1.tgz#c066afb582bb1cb4128d60ea92392e94d5e9dbec"
8443+
83978444
watchpack@^1.5.0, watchpack@^1.6.0:
83988445
version "1.6.0"
83998446
resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-1.6.0.tgz#4bc12c2ebe8aa277a71f1d3f14d685c7b446cd00"

0 commit comments

Comments
 (0)