diff --git a/api.go b/api.go
index ab7b7b7..1c9565a 100644
--- a/api.go
+++ b/api.go
@@ -1237,9 +1237,16 @@ func (app *appContext) Logout(gc *gin.Context) {
// @Router /lang [get]
// @tags Other
func (app *appContext) GetLanguages(gc *gin.Context) {
+ page := gc.Param("page")
resp := langDTO{}
- for key, lang := range app.storage.lang.Form {
- resp[key] = lang["meta"].(map[string]interface{})["name"].(string)
+ if page == "form" {
+ for key, lang := range app.storage.lang.Form {
+ resp[key] = lang["meta"].(map[string]interface{})["name"].(string)
+ }
+ } else if page == "admin" {
+ for key, lang := range app.storage.lang.Admin {
+ resp[key] = lang["meta"].(map[string]interface{})["name"].(string)
+ }
}
if len(resp) == 0 {
respond(500, "Couldn't get languages", gc)
diff --git a/html/admin.html b/html/admin.html
index 2227b52..5f214da 100644
--- a/html/admin.html
+++ b/html/admin.html
@@ -167,6 +167,16 @@
+
+
+
+
+
+
+
diff --git a/main.go b/main.go
index 06ace3d..3428014 100644
--- a/main.go
+++ b/main.go
@@ -577,7 +577,7 @@ func start(asDaemon, firstCall bool) {
router.GET("/accounts", app.AdminPage)
router.GET("/settings", app.AdminPage)
- router.GET("/lang", app.GetLanguages)
+ router.GET("/lang/:page", app.GetLanguages)
router.GET("/token/login", app.getTokenLogin)
router.GET("/token/refresh", app.getTokenRefresh)
router.POST("/newUser", app.NewUser)
diff --git a/ts/admin.ts b/ts/admin.ts
index 5811af3..d47b6c1 100644
--- a/ts/admin.ts
+++ b/ts/admin.ts
@@ -1,5 +1,5 @@
import { toggleTheme, loadTheme } from "./modules/theme.js";
-import { lang, LangFile } from "./modules/lang.js";
+import { lang, LangFile, loadLangSelector } from "./modules/lang.js";
import { Modal } from "./modules/modal.js";
import { Tabs } from "./modules/tabs.js";
import { inviteList, createInvite } from "./modules/invites.js";
@@ -11,9 +11,8 @@ import { _get, _post, notificationBox, whichAnimationEvent, toggleLoader } from
loadTheme();
(document.getElementById('button-theme') as HTMLSpanElement).onclick = toggleTheme;
-var langLoaded = false;
-
window.lang = new lang(window.langFile as LangFile);
+loadLangSelector("admin");
// _get(`/lang/admin/${window.language}.json`, null, (req: XMLHttpRequest) => {
// if (req.readyState == 4 && req.status == 200) {
// langLoaded = true;
diff --git a/ts/form.ts b/ts/form.ts
index d5301bb..b2b2581 100644
--- a/ts/form.ts
+++ b/ts/form.ts
@@ -1,5 +1,6 @@
import { Modal } from "./modules/modal.js";
import { _get, _post, toggleLoader } from "./modules/common.js";
+import { loadLangSelector } from "./modules/lang.js";
interface formWindow extends Window {
validationStrings: pwValStrings;
@@ -22,23 +23,7 @@ interface pwValStrings {
[ type: string ]: pwValString;
}
-_get("/lang", null, (req: XMLHttpRequest) => {
- if (req.readyState == 4) {
- if (req.status != 200) {
- document.getElementById("lang-dropdown").remove();
- return;
- }
- const list = document.getElementById("lang-list") as HTMLDivElement;
- let innerHTML = '';
- for (let code in req.response) {
- innerHTML += `${req.response[code]}`;
- }
- list.innerHTML = innerHTML;
- }
-});
-
-
-
+loadLangSelector("form");
window.modal = new Modal(document.getElementById("modal-success"));
declare var window: formWindow;
diff --git a/ts/modules/lang.ts b/ts/modules/lang.ts
index 288a5c6..5765921 100644
--- a/ts/modules/lang.ts
+++ b/ts/modules/lang.ts
@@ -1,3 +1,5 @@
+import { _get } from "../modules/common.js";
+
interface Meta {
name: string;
}
@@ -45,7 +47,20 @@ export class lang implements Lang {
}
}
-
+export const loadLangSelector = (page: string) => _get("/lang/" + page, null, (req: XMLHttpRequest) => {
+ if (req.readyState == 4) {
+ if (req.status != 200) {
+ document.getElementById("lang-dropdown").remove();
+ return;
+ }
+ const list = document.getElementById("lang-list") as HTMLDivElement;
+ let innerHTML = '';
+ for (let code in req.response) {
+ innerHTML += `${req.response[code]}`;
+ }
+ list.innerHTML = innerHTML;
+ }
+});