feat(api): localize console pages and api error messages
The language comes from the user setting, then the lang cookie, then Accept-Language, falling back to English. Errors keep a stable code and carry a translated message. Closes #42 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
dde7b890b8
commit
70190446ff
12 files changed
+698
-211
No files matched your search
+22
-17
@@ -1,5 +1,8 @@
|
||||
package web
|
||||
|
||||
import "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
|
||||
|
||||
// Me is the signed-in user as the console templates see it.
|
||||
type Me struct {
|
||||
Email string
|
||||
DisplayName string
|
||||
@@ -9,6 +12,7 @@ type Me struct {
|
||||
TOTPMissing bool
|
||||
}
|
||||
|
||||
// Org is one entry of the organization switcher.
|
||||
type Org struct {
|
||||
ID string
|
||||
Name string
|
||||
@@ -31,16 +35,17 @@ templ consoleShell(p Page, me Me) {
|
||||
<span class="text-muted">{ me.Orgs[0].Name }</span>
|
||||
}
|
||||
<nav class="ml-auto flex items-center gap-5">
|
||||
<a href="/settings/security" class="text-muted hover:text-ink">Sicherheit</a>
|
||||
<button data-logout class="text-muted hover:text-ink">Abmelden</button>
|
||||
<a href="/settings/security" class="text-muted hover:text-ink">{ i18n.T(ctx, "console.nav.security") }</a>
|
||||
<button data-logout class="text-muted hover:text-ink">{ i18n.T(ctx, "console.nav.logout") }</button>
|
||||
@languageSwitch(p.Languages)
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
if me.TOTPMissing {
|
||||
<div class="border-b border-degraded/40 bg-degraded/10">
|
||||
<p class="mx-auto max-w-5xl px-6 py-2 text-sm">
|
||||
Deine Organisation verlangt Zwei-Faktor-Anmeldung.
|
||||
<a href="/settings/security" class="underline underline-offset-2">Jetzt einrichten</a>
|
||||
{ i18n.T(ctx, "console.totp_missing") }
|
||||
<a href="/settings/security" class="underline underline-offset-2">{ i18n.T(ctx, "console.totp_missing_action") }</a>
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
@@ -52,35 +57,35 @@ templ consoleShell(p Page, me Me) {
|
||||
|
||||
templ Dashboard(p Page, me Me) {
|
||||
@consoleShell(p, me) {
|
||||
<h1 class="text-lg font-semibold">Monitore</h1>
|
||||
<p class="mt-2 text-sm text-muted">Noch keine Monitore angelegt.</p>
|
||||
<h1 class="text-lg font-semibold">{ i18n.T(ctx, "console.monitors.title") }</h1>
|
||||
<p class="mt-2 text-sm text-muted">{ i18n.T(ctx, "console.monitors.empty") }</p>
|
||||
}
|
||||
}
|
||||
|
||||
templ Security(p Page, me Me) {
|
||||
@consoleShell(p, me) {
|
||||
<h1 class="mb-8 text-lg font-semibold">Sicherheit</h1>
|
||||
<h1 class="mb-8 text-lg font-semibold">{ i18n.T(ctx, "security.title") }</h1>
|
||||
<section class="max-w-md">
|
||||
<h2 class="mb-1 text-xs font-medium uppercase tracking-wider text-muted">Zwei-Faktor (TOTP)</h2>
|
||||
<h2 class="mb-1 text-xs font-medium uppercase tracking-wider text-muted">{ i18n.T(ctx, "security.totp.heading") }</h2>
|
||||
if me.TOTP {
|
||||
<p class="mb-6 text-sm"><span class="text-up">●</span> aktiv</p>
|
||||
<p class="mb-6 text-sm"><span class="text-up">●</span> { i18n.T(ctx, "security.totp.active") }</p>
|
||||
<form data-api="/me/totp/disable" data-next="/settings/security">
|
||||
@formError()
|
||||
@field("Passwort", "password", "password", "current-password", true)
|
||||
@field("Aktueller Code", "code", "text", "one-time-code", true)
|
||||
@submit("Deaktivieren")
|
||||
@field(i18n.T(ctx, "auth.field.password"), "password", "password", "current-password", true)
|
||||
@field(i18n.T(ctx, "security.totp.current_code"), "code", "text", "one-time-code", true)
|
||||
@submit(i18n.T(ctx, "security.totp.disable"))
|
||||
</form>
|
||||
} else {
|
||||
<p class="mb-6 text-sm"><span class="text-unknown">●</span> nicht eingerichtet</p>
|
||||
<p class="mb-6 text-sm"><span class="text-unknown">●</span> { i18n.T(ctx, "security.totp.inactive") }</p>
|
||||
<div data-totp-setup>
|
||||
<button data-totp-start class="border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">Einrichten</button>
|
||||
<button data-totp-start class="border border-ink px-3 py-1.5 text-sm hover:bg-ink hover:text-paper">{ i18n.T(ctx, "security.totp.start") }</button>
|
||||
<div data-totp-panel hidden>
|
||||
<img data-totp-qr alt="QR-Code für die Authenticator-App" class="mb-3 h-48 w-48 border border-rule bg-white p-2"/>
|
||||
<img data-totp-qr alt={ i18n.T(ctx, "security.totp.qr_alt") } class="mb-3 h-48 w-48 border border-rule bg-white p-2"/>
|
||||
<p class="mb-6 break-all font-mono text-xs text-muted" data-totp-secret></p>
|
||||
<form data-api="/me/totp/enable" data-next="/settings/security">
|
||||
@formError()
|
||||
@field("Code aus der App", "code", "text", "one-time-code", true)
|
||||
@submit("Bestätigen")
|
||||
@field(i18n.T(ctx, "security.totp.app_code"), "code", "text", "one-time-code", true)
|
||||
@submit(i18n.T(ctx, "security.totp.confirm"))
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user