Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ByeCorps ID Legacy
Manage
Activity
Members
Labels
Plan
Wiki
JetBrains YouTrack
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
ByeCorps
ID
ByeCorps ID Legacy
Commits
f61c9774
Commit
f61c9774
authored
Jul 5, 2024
by
Bye
Browse files
Options
Downloads
Patches
Plain Diff
I really dont like this but I will fix it later
parent
ea298203
Branches
Branches containing commit
No related tags found
1 merge request
!4
Draft: Merge rewrite branch into main
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
api.php
+17
-0
17 additions, 0 deletions
api.php
common/strings.php
+49
-0
49 additions, 0 deletions
common/strings.php
index.php
+30
-10
30 additions, 10 deletions
index.php
scripts/langauge_switcher.js
+28
-0
28 additions, 0 deletions
scripts/langauge_switcher.js
strings
+1
-1
1 addition, 1 deletion
strings
with
125 additions
and
11 deletions
api.php
+
17
−
0
View file @
f61c9774
...
...
@@ -8,6 +8,23 @@ $routes = [
exit
();
},
'i11n'
=>
function
()
{
global
$path
;
return
match
(
$path
[
2
])
{
'languages'
=>
[
"response"
=>
[
'success'
=>
true
,
'status_code'
=>
200
],
'body'
=>
[
'current'
=>
$_SESSION
[
'lang'
],
'languages'
=>
LANGAUGES
]
],
default
=>
404
,
};
},
'status'
=>
function
()
{
http_response_code
(
200
);
...
...
This diff is collapsed.
Click to expand it.
common/strings.php
+
49
−
0
View file @
f61c9774
<?php
const
LANGAUGES
=
[
[
"code"
=>
'en'
,
"name"
=>
"English (Traditional)"
,
"flag"
=>
"uk"
],
[
'code'
=>
'en_US'
,
"name"
=>
'English (Simplified)'
,
'flag'
=>
'usa'
],
[
'code'
=>
'en_UWU'
,
'name'
=>
'Cute English'
,
'flag'
=>
'owo'
],
[
'code'
=>
'ga'
,
'name'
=>
'Irish'
,
'flag'
=>
'ie'
],
[
'code'
=>
'nb_NO'
,
'name'
=>
'Norwegian Bokmål'
,
'flag'
=>
'no'
]
];
function
get_string
(
$key
=
"generic.generic"
,
$substitutes
=
[])
{
global
$LANG
;
...
...
@@ -27,6 +55,27 @@ function get_string($key="generic.generic", $substitutes=[]) {
return
$result
;
}
function
get_language_code_based_on_browser_locale
():
string
{
$locale
=
locale_accept_from_http
(
$_SERVER
[
'HTTP_ACCEPT_LANGUAGE'
]);
$locales
=
[
// Converts locale to its respective language.
'en_GB'
=>
'en'
,
'en_IE'
=>
'en'
,
'en'
=>
'en'
,
];
if
(
array_key_exists
(
$locale
,
$locales
))
{
return
$locales
[
$locale
];
}
if
(
str_starts_with
(
"en"
,
$locale
))
{
return
"en"
;
}
return
$locale
;
}
function
patch_lang
(
$lang
=
"en"
):
void
{
...
...
This diff is collapsed.
Click to expand it.
index.php
+
30
−
10
View file @
f61c9774
...
...
@@ -25,11 +25,19 @@ require_once 'common/strings.php';
require_once
'common/account_utils.php'
;
require_once
'common/database.php'
;
// Starts the session
// TODO: write this to use the database to work across more than one server (e.g. don't use PHP sessions)
session_start
();
if
(
empty
(
$_SESSION
))
{
$_SESSION
[
'auth'
]
=
false
;
$_SESSION
[
'id'
]
=
null
;
}
if
(
!
isset
(
$_SESSION
[
'lang'
]))
{
$_SESSION
[
'lang'
]
=
get_language_code_based_on_browser_locale
();
}
$user
=
null
;
if
(
$_SESSION
[
'auth'
])
{
...
...
@@ -61,6 +69,14 @@ if (str_ends_with($path_raw, '/') && $path_raw != '/') {
exit
;
}
// If there's a 'lang' query param, change the language!
if
(
array_key_exists
(
'lang'
,
$query
))
{
$_SESSION
[
'lang'
]
=
$query
[
'lang'
];
}
patch_lang
(
$_SESSION
[
'lang'
]);
$routes
=
[
''
=>
function
()
{
require
'views/home.php'
;
},
'api'
=>
function
()
{
...
...
@@ -85,6 +101,17 @@ $routes = [
}
exit
();
},
'dashboard'
=>
function
()
{
global
$user
;
requires_auth
();
if
(
isset
(
$path
[
2
]))
{
return
404
;
}
require
'views/dashboard.php'
;
return
200
;
},
'profile'
=>
function
()
{
global
$path
,
$user
,
$profile_owner
;
// don't forget this lol
...
...
@@ -101,15 +128,8 @@ $routes = [
require
'views/profile.php'
;
return
200
;
},
'dashboard'
=>
function
()
{
requires_auth
();
if
(
isset
(
$path
[
2
]))
{
return
404
;
}
require
'views/dashboard.php'
;
return
200
;
'settings'
=>
function
()
{
require
'views/settings.php'
;
}
];
...
...
This diff is collapsed.
Click to expand it.
scripts/langauge_switcher.js
0 → 100644
+
28
−
0
View file @
f61c9774
const
select
=
document
.
createElement
(
'
select
'
);
const
script
=
document
.
scripts
[
document
.
scripts
.
length
-
1
];
const
langs_req
=
fetch
(
'
/api/i11n/languages
'
)
.
then
(
async
data
=>
{
return
await
data
.
json
();
})
.
then
(
async
json
=>
{
console
.
log
(
json
)
for
(
const
lang
of
json
.
body
.
languages
)
{
console
.
log
(
lang
)
let
new_opt
=
document
.
createElement
(
'
option
'
);
new_opt
.
value
=
lang
.
code
;
new_opt
.
innerText
=
lang
.
name
;
select
.
appendChild
(
new_opt
);
}
select
.
value
=
json
.
body
.
current
;
script
.
parentElement
.
insertBefore
(
select
,
script
);
})
let
separator
=
(
window
.
location
.
href
.
indexOf
(
"
?
"
)
===-
1
)?
"
?
"
:
"
&
"
;
select
.
onchange
=
function
()
{
window
.
location
.
href
=
window
.
location
.
href
+
separator
+
`lang=
${
select
.
value
}
`
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
strings
@
d9131afc
Compare
919271ad
...
d9131afc
Subproject commit 91
9271adb8e055d09f08898b812f9e641f693543
Subproject commit
d
91
31afc20afc0bb4205990bb34f8c455ae81f8d
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment