2021-05-08 00:38:02 +01:00
|
|
|
import { Margin } from "../elements/Margin";
|
2021-05-16 09:47:53 +01:00
|
|
|
import { Page } from "../types/Page";
|
2021-05-07 22:23:52 +01:00
|
|
|
import { makeElement } from "../htmlUtils";
|
2021-05-12 15:32:21 +01:00
|
|
|
import { reloadNavBar } from "../elements/NavBar";
|
2021-05-12 16:01:04 +01:00
|
|
|
import i18next from "i18next";
|
2021-05-12 15:25:25 +01:00
|
|
|
|
|
|
|
// @ts-ignore
|
2021-05-03 15:13:30 +01:00
|
|
|
import translations from "../translations/index.mjs";
|
2021-04-19 20:17:07 +01:00
|
|
|
|
2021-05-08 01:54:38 +01:00
|
|
|
const languageIDs = Object.getOwnPropertyNames(translations);
|
2021-04-19 20:17:07 +01:00
|
|
|
|
|
|
|
export class SetLanguagePage extends Page {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
}
|
2021-05-12 17:37:09 +01:00
|
|
|
async render(): Promise<void> {
|
2021-05-08 01:54:38 +01:00
|
|
|
const setLanguageForm = makeElement({
|
2021-04-19 20:17:07 +01:00
|
|
|
tag: "form",
|
|
|
|
id: "setLanguageForm",
|
|
|
|
children: [
|
2021-05-12 16:01:04 +01:00
|
|
|
Margin(
|
|
|
|
makeElement({
|
|
|
|
tag: "select",
|
|
|
|
class: ["uk-select", "uk-form-width-large"],
|
|
|
|
attributes: {
|
|
|
|
name: "language",
|
|
|
|
},
|
|
|
|
children: languageIDs.map(function (languageID) {
|
|
|
|
return makeElement({
|
|
|
|
tag: "option",
|
|
|
|
text: i18next.getFixedT(languageID, null)("language_name"),
|
|
|
|
attributes: { value: languageID },
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
}),
|
2021-04-19 20:17:07 +01:00
|
|
|
),
|
|
|
|
makeElement({
|
|
|
|
tag: "p",
|
|
|
|
id: "errorText",
|
2021-05-12 16:01:04 +01:00
|
|
|
class: "uk-text-danger",
|
2021-04-19 20:17:07 +01:00
|
|
|
}),
|
|
|
|
makeElement({
|
|
|
|
tag: "button",
|
|
|
|
class: ["uk-button", "uk-button-primary"],
|
|
|
|
text: i18next.t("set_language_btn"),
|
|
|
|
attributes: {
|
|
|
|
type: "submit",
|
2021-05-12 16:01:04 +01:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
],
|
2021-05-08 01:54:38 +01:00
|
|
|
}) as HTMLFormElement;
|
2021-05-15 10:54:39 +01:00
|
|
|
await this.router.setPageContent(setLanguageForm);
|
|
|
|
setLanguageForm.addEventListener("submit", async (e) => {
|
2021-04-19 20:17:07 +01:00
|
|
|
e.preventDefault();
|
2021-05-08 01:54:38 +01:00
|
|
|
const formData = new FormData(setLanguageForm);
|
2021-05-12 18:26:32 +01:00
|
|
|
|
2021-05-08 01:54:38 +01:00
|
|
|
const language = formData.get("language") as string;
|
2021-05-15 10:54:39 +01:00
|
|
|
this.state.language = language;
|
2021-05-12 18:26:32 +01:00
|
|
|
|
|
|
|
const t = await i18next.changeLanguage(language);
|
2021-05-15 10:54:39 +01:00
|
|
|
this.state.pageDirection = t("language_direction");
|
|
|
|
reloadNavBar(this.router);
|
|
|
|
await this.router.changePage("HOME");
|
2021-04-19 20:17:07 +01:00
|
|
|
});
|
|
|
|
}
|
2021-05-08 01:54:38 +01:00
|
|
|
get name(): string {
|
2021-04-19 20:17:07 +01:00
|
|
|
return i18next.t("set_language_title");
|
|
|
|
}
|
|
|
|
}
|