oh gott was mach ich nur

This commit is contained in:
2025-11-25 03:21:52 +01:00
parent b8471bff3e
commit 888ab3dfa7
21 changed files with 2664 additions and 794 deletions

View File

@@ -4,6 +4,7 @@
// Namespace
window.usbcheck = window.usbcheck || {};
const usbcheck = window.usbcheck;
const cfg = window.usbConfig || {};
@@ -16,14 +17,81 @@
return "https://api.usbcheck.it";
}
// Locale aus Config:
// - bevorzugt fakecheck.locale (aus PHP fakecheck-Block)
// - sonst cfg.lang
const locale =
(cfg.fakecheck && cfg.fakecheck.locale)
|| cfg.lang
|| "en";
// Config bereitstellen
usbcheck.cfg = {
baseUrl: cfg.baseUrl || "",
locale: (cfg.lang || "en").toLowerCase(),
apiBase: cfg.apiBaseUrl || detectApiBaseUrl(),
// wenn fakecheck.baseUrl vorhanden ist → bevorzugen
baseUrl: (cfg.fakecheck && cfg.fakecheck.baseUrl) || cfg.baseUrl || "",
locale: (locale || "en").toLowerCase(),
apiBase: (cfg.fakecheck && cfg.fakecheck.apiBaseUrl) || cfg.apiBaseUrl || detectApiBaseUrl(),
loggedIn: !!cfg.isLoggedIn
};
// -----------------------------------
// i18n JSON laden + Helfer
// -----------------------------------
usbcheck.locale = usbcheck.cfg.locale || "en";
usbcheck.i18n = {};
function loadI18n() {
// Pfad wie bei deinen JSONs: /public/assets/i18n/de.json etc.
const assetsBase = cfg.assetsBase || "/assets";
const url = assetsBase.replace(/\/+$/, "") + "/i18n/" + usbcheck.locale + ".json";
fetch(url)
.then(res => {
if (!res.ok) throw new Error("HTTP " + res.status);
return res.json();
})
.then(data => {
usbcheck.i18n = data || {};
// console.debug("usbcheck i18n loaded:", usbcheck.locale, usbcheck.i18n);
})
.catch(err => {
console.warn("usbcheck i18n konnte nicht geladen werden:", err);
usbcheck.i18n = {};
});
}
// Key-Lookup: "fake_ui.status_ready"
usbcheck.t = function t(key, fallback) {
if (!key) return (fallback != null ? fallback : "");
const parts = String(key).split(".");
let cur = usbcheck.i18n;
for (let i = 0; i < parts.length; i++) {
const p = parts[i];
if (!cur || typeof cur !== "object" || !(p in cur)) {
return (fallback != null ? fallback : key);
}
cur = cur[p];
}
if (cur == null) return (fallback != null ? fallback : key);
return cur;
};
// Format-Variante mit Platzhaltern {name}, {mode}, {size}, ...
usbcheck.tFmt = function tFmt(key, fallback, vars) {
let str = usbcheck.t(key, fallback);
if (!vars) return str;
for (const k in vars) {
if (!Object.prototype.hasOwnProperty.call(vars, k)) continue;
const re = new RegExp("\\{" + k.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&") + "\\}", "g");
str = str.replace(re, vars[k]);
}
return str;
};
// direkt beim Laden JSON holen
loadI18n();
// ---------- Hilfsfunktionen ----------
usbcheck.log = function logLine(message, level = "info") {