work on translation system

This commit is contained in:
Sören Oesterwind 2022-04-06 22:17:55 +02:00
parent 3b99939ef3
commit 0b3df97975
9 changed files with 268 additions and 33 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
node_modules
rename.sh
data-persistence.json
log-journal.json

View File

@ -4,6 +4,8 @@ const bodyParser = require("body-parser");
const ws = require('ws');
const helper = require("./helpers.js");
const loggy = require("./logging")
const Eta = require("eta");
loggy.init(true)
loggy.log("Preparing server", "info", "Server");
@ -57,6 +59,9 @@ const dataToBeWritten = {};
currentState = Object.assign({}, currentState, loadedData);
currentState.textColors = currentState.colorSegments
loggy.log("Reading language file", "info", "Language")
const languageProfile = JSON.parse(fs.readFileSync("lang/en_uk.json", "utf8"));
loggy.log("Preparing websocket", "info", "Websocket");
const wsServer = new ws.Server({ noServer: true });
@ -88,7 +93,11 @@ function updatedData() {
loggy.log("Preparing routes", "info", "Server");
app.get("/", function (req, res) {
const data = fs.readFileSync("templates/newAdminPanel.html", "utf8");
res.send(data);
res.send(
Eta.render(data, {
lang: languageProfile
}));
});
app.get("/timer", function (req, res) {
@ -323,10 +332,23 @@ app.use(function(req, res, next) {
app.use(function(err, req, res, next) {
console.error(err.stack);
if(String(err.stack).includes("TypeError: Cannot read properties of undefined")) {
const data = fs.readFileSync("templates/brokenTranslation.html", "utf8");
res.send(data);
}else{
res.status(500).send('Something broke!');
}
});
loggy.log("Starting server", "info", "Server");
const port = 3005
const port = 3006
process.on('SIGINT', function () {
loggy.log("Caught interrupt signal and shutting down gracefully", "info", "Shutdown");

31
lang/de_de.json Normal file
View File

@ -0,0 +1,31 @@
{
"titles": {
"home": "Startseite",
"preview": "Vorschau",
"mode": "Modus",
"messaging": "Nachrichten",
"countdownToTime": "Auf Uhrzeit runterzählen"
},
"sidebar": {
"home": "Startseite",
"settings": "Einstellungen",
"debug": "Debug",
"about": "Über"
},
"hints":
{
"previewHint": "Eine Vorschau der Timeransicht.",
"modeHint": "",
"messagingHint": "Zeigt eine Nachricht auf der Timeransicht an."
},
"placeholders": {
"msgHere": "Message here"
},
"others":
{
"timer": "Timer",
"clock": "Uhr",
"black": "Schwarz",
"test": "Testbild"
}
}

46
lang/en_uk.json Normal file
View File

@ -0,0 +1,46 @@
{
"titles": {
"home": "Homepage",
"preview": "Preview",
"mode": "Mode",
"messaging": "Messaging",
"countdownToTime": "Countdown to time"
},
"sidebar": {
"home": "Home",
"settings": "Settings",
"debug": "Debug",
"about": "About"
},
"hints":
{
"previewHint": "A preview of what is currently visible on the countdown view",
"modeHint": "",
"messagingHint": "Shows a given message on the timer view"
},
"placeholders": {
"msgHere": "Message here"
},
"others":
{
"timer": "Timer",
"clock": "Clock",
"black": "Black",
"test": "Testimage"
},
"labels":
{
"clockOnTimer": "Show clock on Timer:",
"showMillis": "Show Milliseconds on Timer:",
"showProgress": "Show progressbar:",
"progbarColors": "Progressbar Colors",
"time": "Time",
"color": "Color",
"remove": "Remove"
},
"_metadata": {
"lang": "en",
"version": "1.0.0",
"authors": ["TheGreydiamond"]
}
}

View File

@ -1 +1 @@
[{"timestamp":"2022-03-29 20:16:25.083","level":"info","module":"Logging","message":"2022-03-29 20:16:25.083 [info] [Logging] Logging initialized"},{"timestamp":"2022-03-29 20:16:25.084","level":"info","module":"Server","message":"2022-03-29 20:16:25.084 [info] [Server] Preparing server"},{"timestamp":"2022-03-29 20:16:25.085","level":"info","module":"Server","message":"2022-03-29 20:16:25.085 [info] [Server] Preparing static routes"},{"timestamp":"2022-03-29 20:16:25.087","level":"info","module":"Server","message":"2022-03-29 20:16:25.087 [info] [Server] Preparing middlewares"},{"timestamp":"2022-03-29 20:16:25.088","level":"info","module":"Config","message":"2022-03-29 20:16:25.088 [info] [Config] Loading config"},{"timestamp":"2022-03-29 20:16:25.088","level":"info","module":"Websocket","message":"2022-03-29 20:16:25.088 [info] [Websocket] Preparing websocket"},{"timestamp":"2022-03-29 20:16:25.089","level":"info","module":"Server","message":"2022-03-29 20:16:25.089 [info] [Server] Preparing routes"},{"timestamp":"2022-03-29 20:16:25.091","level":"info","module":"Server","message":"2022-03-29 20:16:25.091 [info] [Server] Starting server"},{"timestamp":"2022-03-29 20:16:35.159","level":"info","module":"Shutdown","message":"2022-03-29 20:16:35.159 [info] [Shutdown] Caught interrupt signal and shutting down gracefully"}]
[{"timestamp":"2022-04-06 20:17:16.831","level":"info","module":"Logging","message":"2022-04-06 20:17:16.831 [info] [Logging] Logging initialized"},{"timestamp":"2022-04-06 20:17:16.833","level":"info","module":"Server","message":"2022-04-06 20:17:16.833 [info] [Server] Preparing server"},{"timestamp":"2022-04-06 20:17:16.834","level":"info","module":"Server","message":"2022-04-06 20:17:16.834 [info] [Server] Preparing static routes"},{"timestamp":"2022-04-06 20:17:16.836","level":"info","module":"Server","message":"2022-04-06 20:17:16.836 [info] [Server] Preparing middlewares"},{"timestamp":"2022-04-06 20:17:16.837","level":"info","module":"Config","message":"2022-04-06 20:17:16.837 [info] [Config] Loading config"},{"timestamp":"2022-04-06 20:17:16.838","level":"info","module":"Language","message":"2022-04-06 20:17:16.838 [info] [Language] Reading language file"},{"timestamp":"2022-04-06 20:17:16.838","level":"info","module":"Websocket","message":"2022-04-06 20:17:16.838 [info] [Websocket] Preparing websocket"},{"timestamp":"2022-04-06 20:17:16.839","level":"info","module":"Server","message":"2022-04-06 20:17:16.839 [info] [Server] Preparing routes"},{"timestamp":"2022-04-06 20:17:16.840","level":"info","module":"Server","message":"2022-04-06 20:17:16.840 [info] [Server] Starting server"},{"timestamp":"2022-04-06 20:17:22.971","level":"info","module":"Shutdown","message":"2022-04-06 20:17:22.971 [info] [Shutdown] Caught interrupt signal and shutting down gracefully"}]

17
package-lock.json generated
View File

@ -15,6 +15,7 @@
"bootstrap-icons": "^1.8.1",
"colors": "^1.4.0",
"darkreader": "^4.9.44",
"eta": "^1.12.3",
"express": "^4.17.3",
"flatpickr": "^4.6.11",
"jquery": "^3.6.0",
@ -215,6 +216,17 @@
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
"integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg="
},
"node_modules/eta": {
"version": "1.12.3",
"resolved": "https://registry.npmjs.org/eta/-/eta-1.12.3.tgz",
"integrity": "sha512-qHixwbDLtekO/d51Yr4glcaUJCIjGVJyTzuqV4GPlgZo1YpgOKG+avQynErZIYrfM6JIJdtiG2Kox8tbb+DoGg==",
"engines": {
"node": ">=6.0.0"
},
"funding": {
"url": "https://github.com/eta-dev/eta?sponsor=1"
}
},
"node_modules/etag": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
@ -881,6 +893,11 @@
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
"integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg="
},
"eta": {
"version": "1.12.3",
"resolved": "https://registry.npmjs.org/eta/-/eta-1.12.3.tgz",
"integrity": "sha512-qHixwbDLtekO/d51Yr4glcaUJCIjGVJyTzuqV4GPlgZo1YpgOKG+avQynErZIYrfM6JIJdtiG2Kox8tbb+DoGg=="
},
"etag": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",

View File

@ -15,6 +15,7 @@
"bootstrap-icons": "^1.8.1",
"colors": "^1.4.0",
"darkreader": "^4.9.44",
"eta": "^1.12.3",
"express": "^4.17.3",
"flatpickr": "^4.6.11",
"jquery": "^3.6.0",

View File

@ -0,0 +1,120 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>openCountdown - Admin</title>
<meta name="description" content="openCountdown">
<meta name="author" content="TheGreydiamond">
<link rel="stylesheet" href="/css/bootstrap-icons.css">
<link rel="stylesheet" href="/mdbootstrap/css/style.css">
<script src="/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/mdbootstrap/js/mdb.min.js"></script>
<script type="text/javascript" src="/js/darkreader.js"></script>
<script type="text/javascript" src="/js/cookie.js"></script>
<link href="/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="/css/mainStyle.css" rel="stylesheet">
<link rel="stylesheet" href="/coloris/coloris.min.css" />
<link rel="stylesheet" href="/bootstrap-duration-picker/bootstrap-duration-picker.css" />
<link rel="stylesheet" href="/flatpickr/dist/flatpickr.min.css" />
<script src="/bootstrap-duration-picker/bootstrap-duration-picker-debug.js"></script>
<script src="/coloris/coloris.min.js"></script>
<script type="text/javascript" src="/flatpickr/dist/flatpickr.js"> </script>
<link rel="stylesheet" href="/css/bootstrap-icons.css">
</head>
<body>
<main>
<div class="d-flex flex-column flex-shrink-0 p-3 text-white bg-dark trans" style="width: 250px;"
id="navbarToggleExternalContent">
<a href="/" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-white text-decoration-none">
<svg class="bi me-2" width="40" height="32">
<use xlink:href="#bootstrap" />
</svg>
<span class="fs-4">Sidebar</span>
</a>
<hr>
<ul class="nav nav-pills flex-column mb-auto">
<li class="nav-item">
<a href="#homeP" class="nav-link active" aria-current="page" id="PageIndex">
<i class="bi bi-house-door"></i>
Home
</a>
</li>
</ul>
<hr>
openCountdown <div class="btn-group" role="group" aria-label="Basic radio toggle button group">
<input type="radio" class="btn-check" name="btnradio2" id="Mbtnradio1" autocomplete="off" checked>
<label class="btn btn-outline-primary" for="Mbtnradio1"><svg xmlns="http://www.w3.org/2000/svg"
width="16" height="16" fill="currentColor" class="bi bi-brightness-high-fill"
viewBox="0 0 16 16">
<path
d="M12 8a4 4 0 1 1-8 0 4 4 0 0 1 8 0zM8 0a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 0zm0 13a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 13zm8-5a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2a.5.5 0 0 1 .5.5zM3 8a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2A.5.5 0 0 1 3 8zm10.657-5.657a.5.5 0 0 1 0 .707l-1.414 1.415a.5.5 0 1 1-.707-.708l1.414-1.414a.5.5 0 0 1 .707 0zm-9.193 9.193a.5.5 0 0 1 0 .707L3.05 13.657a.5.5 0 0 1-.707-.707l1.414-1.414a.5.5 0 0 1 .707 0zm9.193 2.121a.5.5 0 0 1-.707 0l-1.414-1.414a.5.5 0 0 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .707zM4.464 4.465a.5.5 0 0 1-.707 0L2.343 3.05a.5.5 0 1 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .708z" />
</svg>
</label>
<input type="radio" class="btn-check" name="btnradio2" id="Mbtnradio2" autocomplete="off">
<label class="btn btn-outline-primary" for="Mbtnradio2">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
class="bi bi-moon-fill" viewBox="0 0 16 16">
<path
d="M6 .278a.768.768 0 0 1 .08.858 7.208 7.208 0 0 0-.878 3.46c0 4.021 3.278 7.277 7.318 7.277.527 0 1.04-.055 1.533-.16a.787.787 0 0 1 .81.316.733.733 0 0 1-.031.893A8.349 8.349 0 0 1 8.344 16C3.734 16 0 12.286 0 7.71 0 4.266 2.114 1.312 5.124.06A.752.752 0 0 1 6 .278z" />
</svg>
</label>
<input type="radio" class="btn-check" name="btnradio2" id="Mbtnradio3" autocomplete="off">
<label class="btn btn-outline-primary" for="Mbtnradio3">
Auto
</label>
</div>
</div>
<pages class="d-flex flex-fill" id="pageCont" class="z-index: 50;">
<page id="homeP" class="pageC flex-fill overflow-auto">
<div class="container" >
<div class="" style=" display: flex;align-items: center;justify-content: center; flex-wrap: wrap; flex-direction: column;">
<h1>Oh no!</h1>
<h1>
<i class="bi bi-translate"></i>
</h1>
<h5>
There is a critical error with the current language template. Please select a diffrent language.
</h5>
</div>
</div>
</page>
</pages>
</main>
<script type="text/javascript" src="js/jsonview.js"></script>
<script type="text/javascript" src="/js/interface.js"> </script>
<script type="text/javascript">
Coloris({
el: '.coloris',
alpha: false,
});
$(function () {
$('[data-toggle="tooltip"]').tooltip({ container: "body" })
})
</script>
</body>
</html>

View File

@ -48,25 +48,25 @@
<li class="nav-item">
<a href="#homeP" class="nav-link active" aria-current="page" id="PageIndex">
<i class="bi bi-house-door"></i>
Home
<%= it.lang.sidebar.home %>
</a>
</li>
<li>
<a href="#settings" class="nav-link text-white" id="PageSettings">
<i class="bi bi-gear"></i>
Settings
<%= it.lang.sidebar.settings %>
</a>
</li>
<li>
<a href="#debug" class="nav-link text-white" id="PageDebug">
<i class="bi bi-bug"></i>
Debug
<%= it.lang.sidebar.debug %>
</a>
</li>
<li>
<a href="#about" class="nav-link text-white" id="PageAbout">
<i class="bi bi-info-circle"></i>
About
<%= it.lang.sidebar.about %>
</a>
</li>
</ul>
@ -109,12 +109,12 @@
<page id="homeP" class="pageC flex-fill overflow-auto">
<h1>Home page</h1>
<h1><%= it.lang.titles.home %></h1>
<div class="container">
<div class="row">
<div class="col">
<h3 class="d-flex">Preview <span class="helperTip" data-placement="right" title="A preview of what is currently visible on the countdown view" data-toggle="tooltip">
<h3 class="d-flex"><%= it.lang.titles.preview %> <span class="helperTip" data-placement="right" title="<%= it.lang.hints.previewHint %>" data-toggle="tooltip">
<i class="bi bi-question-circle-fill"></i>
</span>
<div class="ms-auto">
@ -136,23 +136,23 @@
</iframe>
</div>
<div class="col">
<h3>Mode <span class="helperTip" data-placement="right"
<h3><%= it.lang.titles.mode %> <span class="helperTip" data-placement="right"
title="Select what to show on the countdown view" data-toggle="tooltip">
<i class="bi bi-question-circle-fill"></i>
</span></h3>
<div class="btn-group" role="group" aria-label="Basic radio toggle button group">
<input type="radio" class="btn-check" name="btnradio" id="btnradio1" autocomplete="off"
checked>
<label class="btn btn-outline-primary" for="btnradio1">Timer</label>
<label class="btn btn-outline-primary" for="btnradio1"><%= it.lang.others.timer %></label>
<input type="radio" class="btn-check" name="btnradio" id="btnradio2" autocomplete="off">
<label class="btn btn-outline-primary" for="btnradio2">Clock</label>
<label class="btn btn-outline-primary" for="btnradio2"><%= it.lang.others.clock %></label>
<input type="radio" class="btn-check" name="btnradio" id="btnradio3" autocomplete="off">
<label class="btn btn-outline-primary" for="btnradio3">Black</label>
<label class="btn btn-outline-primary" for="btnradio3"><%= it.lang.others.black %></label>
<input type="radio" class="btn-check" name="btnradio" id="btnradio4" autocomplete="off">
<label class="btn btn-outline-primary" for="btnradio4">Testimage</label>
<label class="btn btn-outline-primary" for="btnradio4"><%= it.lang.others.test %></label>
</div>
<br>
<br>
@ -183,12 +183,12 @@
<br>
<br>
<br>
<h3>Messaging <span class="helperTip" data-placement="right"
title="Shows a given message on the timer view" data-toggle="tooltip">
<h3><%= it.lang.titles.messaging %> <span class="helperTip" data-placement="right"
title="<%= it.lang.hints.messagingHint %>" data-toggle="tooltip">
<i class="bi bi-question-circle-fill"></i>
</span></h3>
<input type="text" id="messageContent" class="form-control" placeholder="Message here"
<input type="text" id="messageContent" class="form-control" placeholder="<%= it.lang.placeholders.msgHere %>"
style="width: 50%;">
<br>
@ -201,7 +201,7 @@
</div>
</div>
<br><br><br>
<h3>Timer</h3>
<h3><%= it.lang.titles.timer %></h3>
<div class="container">
@ -229,15 +229,12 @@
</div>
</div>
<h5>
Countdown to time
<%= it.lang.titles.countdownToTime %>
</h5>
<div class="row justify-content-center flex-nowrap d-flex" >
<input id="datetimetester" class="form-control input-sm" style="width: 20%;">
<button class="btn btn-outline-primary goTimeGoalCountdown ms-2" style="width: 5%;"><i
class="bi bi-check2-circle"></i></button>
</input>
</div>
@ -250,17 +247,17 @@
<page id="settings" class="pageC hidden flex-fill overflow-auto">
<h1>Settings</h1>
<label for="showTime">Show clock on Timer:</label>
<h1><%= it.lang.sidebar.settings %></h1>
<label for="showTime"><%= it.lang.labels.clockOnTimer %></label>
<input type="checkbox" name="showTime" id="showTime"><br>
<label for="showMillis">Show Milliseconds on Timer:</label>
<label for="showMillis"><%= it.lang.labels.showMillis %></label>
<input type="checkbox" name="showMillis" id="showMillis"><br>
<label for="progBarShow">Show progressbar:</label>
<label for="progBarShow"><%= it.lang.labels.showProgress %></label>
<input type="checkbox" name="progBarShow" id="progBarShow"><br>
<details>
<summary>Progressbar Colors</summary>
<summary><%= it.lang.labels.progbarColors %></summary>
<p>
<div id="table" class="table-editable">
<span class="table-add float-right mb-3 mr-2"><a href="#!" class="text-success"><i
@ -268,9 +265,9 @@
<table class="table table-bordered table-responsive-md table-striped text-center" id="colors1">
<thead>
<tr>
<th class="text-center">Time</th>
<th class="text-center">Color</th>
<th class="text-center">Remove</th>
<th class="text-center"><%= it.lang.labels.time %></th>
<th class="text-center"><%= it.lang.labels.color %></th>
<th class="text-center"><%= it.lang.labels.remove %></th>
</tr>
</thead>
</tbody>
@ -291,9 +288,9 @@
<table class="table table-bordered table-responsive-md table-striped text-center" id="colors2">
<thead>
<tr>
<th class="text-center">Time</th>
<th class="text-center">Color</th>
<th class="text-center">Remove</th>
<th class="text-center"><%= it.lang.labels.time %></th>
<th class="text-center"><%= it.lang.labels.color %></th>
<th class="text-center"><%= it.lang.labels.remove %></th>
</tr>
</thead>
</tbody>