i18n (en/de), simple-ansicht, settings-politur, projekt-löschen
- Sprachsystem: public/i18n.js + public/lang.js (en Default, de), Sprach-Dropdown in Einstellungen → Allgemein; komplette UI zweisprachig (HTML + app.js), Datum/Zahlen locale-abhängig. Server-Fehlermeldungen bleiben deutsch. - Einfache Ansicht: Scroll-Fix, Layout-Umschalter (Kacheln/Kompakt/Liste), Sortierung, Backup-fällig-Pille. - Credits: © Michael Media + Discord (Einstellungen → Über, README). - Settings poliert: Icon-Chip-Überschriften + dezente Unterabschnitte, kompaktere Abstände, General sinnvoll geordnet. - Projekt löschen: Button in Aktionen (Danger Zone) + Endpoint POST /api/projects/:name/delete mit Guards (nur echter Unterordner, nie _Tools/Root, blockiert bei Scan/Backup), doppelte Bestätigung. Backup bleibt unberührt. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
55
public/i18n.js
Normal file
55
public/i18n.js
Normal file
@@ -0,0 +1,55 @@
|
||||
/* Dashboard i18n. Dictionaries live in lang.js (window.LANG = { en: {...}, de: {...} }).
|
||||
Loaded before app.js, so app.js can use the global t(). Default language: English.
|
||||
|
||||
t(key, vars) -> translated string; {name} placeholders filled from vars
|
||||
I18N.apply(root) fills [data-i18n] (text), [data-i18n-html], [data-i18n-title], [data-i18n-placeholder]
|
||||
I18N.set(code) switch language, remember it, re-apply, notify listeners
|
||||
I18N.get() current language code
|
||||
I18N.langs { code: 'Native name' } for the picker
|
||||
I18N.locale() matching BCP-47 locale for Date/number formatting
|
||||
I18N.onChange(fn) run fn(code) after every switch (used to re-render dynamic parts)
|
||||
|
||||
Add a language: add its dictionary in lang.js and a row in LANGS below. */
|
||||
(function () {
|
||||
'use strict';
|
||||
const LANGS = { en: 'English', de: 'Deutsch' };
|
||||
const LOCALE = { en: 'en-US', de: 'de-DE' };
|
||||
const DEFAULT = 'en';
|
||||
const dict = () => (typeof window !== 'undefined' && window.LANG) || {};
|
||||
const saved = (() => { try { return localStorage.getItem('dash.lang'); } catch { return null; } })();
|
||||
let lang = saved && dict()[saved] ? saved : DEFAULT;
|
||||
const listeners = [];
|
||||
|
||||
function t(key, vars) {
|
||||
let s = dict()[lang]?.[key] ?? dict()[DEFAULT]?.[key] ?? key;
|
||||
if (vars) for (const [k, v] of Object.entries(vars)) s = s.split('{' + k + '}').join(String(v));
|
||||
return s;
|
||||
}
|
||||
function apply(root) {
|
||||
root = root || document;
|
||||
for (const el of root.querySelectorAll('[data-i18n]')) el.textContent = t(el.dataset.i18n);
|
||||
for (const el of root.querySelectorAll('[data-i18n-html]')) el.innerHTML = t(el.dataset.i18nHtml);
|
||||
for (const el of root.querySelectorAll('[data-i18n-title]')) el.title = t(el.dataset.i18nTitle);
|
||||
for (const el of root.querySelectorAll('[data-i18n-placeholder]')) el.placeholder = t(el.dataset.i18nPlaceholder);
|
||||
document.documentElement.lang = lang;
|
||||
}
|
||||
function set(code) {
|
||||
if (!dict()[code] || code === lang) return;
|
||||
lang = code;
|
||||
try { localStorage.setItem('dash.lang', code); } catch {}
|
||||
apply();
|
||||
for (const fn of listeners) { try { fn(code); } catch (e) { console.error(e); } }
|
||||
}
|
||||
|
||||
window.I18N = {
|
||||
t, apply, set,
|
||||
get: () => lang,
|
||||
langs: LANGS,
|
||||
locale: () => LOCALE[lang] || 'en-US',
|
||||
onChange: (fn) => listeners.push(fn),
|
||||
};
|
||||
window.t = t;
|
||||
|
||||
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', () => apply());
|
||||
else apply();
|
||||
})();
|
||||
Reference in New Issue
Block a user