1
0
Fork 0

Add rtl direction support and playground.js

This commit is contained in:
Kitteh 2021-05-07 20:41:40 +01:00
parent 44cefde7b6
commit ea45339a11
11 changed files with 45 additions and 6 deletions

View file

@ -15,6 +15,7 @@ parserOptions:
globals:
pageContent: writable
module: writable
process: writable
rules:

View file

@ -35,6 +35,13 @@ export class PageState extends Page {
localStorage.setItem('token', value);
}
get pageDirection() {
return localStorage.getItem('pageDirection') || "ltr";
}
set pageDirection(value) {
localStorage.setItem('pageDirection', value);
}
get language() {
return localStorage.getItem('language') || "";
}

View file

@ -33,7 +33,7 @@ function ListItem(children) {
});
}
function onLoad() {
async function onLoad() {
document.body.innerHTML = "";
document.body.appendChild(makeElement({
tag: "nav",
@ -103,6 +103,11 @@ function onLoad() {
}));
window.pageContent = document.querySelector("#pageContent");
if (process.env.NODE_ENV == "development") {
await (await import("./playground.js")).playground();
}
renderPage();
setInterval(async () => {
@ -117,7 +122,7 @@ function onLoad() {
}, 5000);
}
document.addEventListener('DOMContentLoaded', function () {
document.addEventListener('DOMContentLoaded', async function () {
i18next.init({
lng: pageState.language,
fallbackLng: 'en',
@ -129,7 +134,7 @@ document.addEventListener('DOMContentLoaded', function () {
return value;
}
}
}).then(function (_) {
onLoad();
}).then(async function (_) {
await onLoad();
});
}, false);

View file

@ -82,6 +82,7 @@ export function changePage(page, shouldSwitch = true) {
}
export function renderPage() {
document.documentElement.dir = pageState.pageDirection;
console.log("Rendering Page: ", pageState.currentPage.name);
document.querySelector("#pageContent").innerHTML = "";
setPageTitle(pageState.currentPage.name);

View file

@ -54,8 +54,9 @@ export class SetLanguagePage extends Page {
let language = formData.get("language");
pageState.language = language;
console.log(pageState.language);
i18next.changeLanguage(language).then((_) => {
i18next.changeLanguage(language).then((t) => {
changePage("HOME", false);
pageState.pageDirection = t("language_direction");
location.reload();
});
});

14
src/playground.js Normal file
View file

@ -0,0 +1,14 @@
import { pageState } from "./globalPageState.js";
import i18next from 'i18next';
// Playground is a way to debug and test things.
// Anything you put in here is gonna be run on page initial load
// before rendering.
// Also it only runs when process.env.NODE_ENV == "development"
// Please empty this function before committing.
export async function playground() {
console.log("Welcome to Playground!");
window.pageState = pageState;
window.i18next = i18next;
}

View file

@ -1,6 +1,8 @@
module.exports = {
// The localised name for the language
"language_name": "Deutsche",
// Internal: The direction of text (ltr or rtl)
"language_direction": "ltr",
// These are the buttons on the top bar.
"home_btn": "Startseite",

View file

@ -1,6 +1,8 @@
module.exports = {
// The localised name for the language
"language_name": "English",
// Internal: The direction of text (ltr or rtl)
"language_direction": "ltr",
// These are the buttons on the top bar.
"home_btn": "Home",

View file

@ -1,6 +1,8 @@
module.exports = {
// The localised name for the language
"language_name": "Français",
// Internal: The direction of text (ltr or rtl)
"language_direction": "ltr",
// These are the buttons on the top bar.
"home_btn": "Accueil",

View file

@ -1,6 +1,8 @@
module.exports = {
// The localised name for the language
"language_name": "Nederlands",
// Internal: The direction of text (ltr or rtl)
"language_direction": "ltr",
// These are the buttons on the top bar.
"home_btn": "Homepagina",

View file

@ -1,6 +1,8 @@
module.exports = {
// The localised name for the language
"language_name": "русский",
// Internal: The direction of text (ltr or rtl)
"language_direction": "ltr",
// These are the buttons on the top bar.
"home_btn": "Главная страница",