Files
uptimesebi/internal/web/console.templ
T
Sebastian UnterschützandClaude Opus 5.5 70190446ff 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
2026-11-22 00:07:00 +01:00

96 lines
3.5 KiB
Templ

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
TOTP bool
ActiveOrg string
Orgs []Org
TOTPMissing bool
}
// Org is one entry of the organization switcher.
type Org struct {
ID string
Name string
Slug string
IsOwner bool
}
templ consoleShell(p Page, me Me) {
@Layout(p) {
<header class="border-b border-rule">
<div class="mx-auto flex max-w-5xl items-center gap-6 px-6 py-3 text-sm">
<a href="/" class="font-mono text-xs tracking-wide">uptimesebi</a>
if len(me.Orgs) > 1 {
<select data-switch-org class="border border-rule bg-transparent px-1.5 py-0.5 text-sm">
for _, o := range me.Orgs {
<option value={ o.ID } selected?={ o.ID == me.ActiveOrg }>{ o.Name }</option>
}
</select>
} else if len(me.Orgs) == 1 {
<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">{ 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">
{ 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>
}
<main class="mx-auto max-w-5xl px-6 py-10">
{ children... }
</main>
}
}
templ Dashboard(p Page, me Me) {
@consoleShell(p, me) {
<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">{ i18n.T(ctx, "security.title") }</h1>
<section class="max-w-md">
<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> { i18n.T(ctx, "security.totp.active") }</p>
<form data-api="/me/totp/disable" data-next="/settings/security">
@formError()
@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> { 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">{ i18n.T(ctx, "security.totp.start") }</button>
<div data-totp-panel hidden>
<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(i18n.T(ctx, "security.totp.app_code"), "code", "text", "one-time-code", true)
@submit(i18n.T(ctx, "security.totp.confirm"))
</form>
</div>
</div>
}
</section>
}
}