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
@@ -1,35 +1,54 @@
|
||||
package web
|
||||
|
||||
import "git.zb-server.de/ZB-Server/uptimesebi/internal/i18n"
|
||||
|
||||
// Page carries what every rendered page needs besides its own content.
|
||||
type Page struct {
|
||||
Title string
|
||||
CSRF string
|
||||
TitleID string
|
||||
CSRF string
|
||||
Languages []string
|
||||
}
|
||||
|
||||
templ Layout(p Page) {
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<html lang={ i18n.Lang(ctx) }>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
if p.CSRF != "" {
|
||||
<meta name="csrf-token" content={ p.CSRF }/>
|
||||
}
|
||||
<title>{ p.Title } · uptimesebi</title>
|
||||
<title>{ i18n.T(ctx, p.TitleID) } · uptimesebi</title>
|
||||
<link rel="stylesheet" href="/static/dist/app.css"/>
|
||||
<script src="/static/dist/axios.min.js" defer></script>
|
||||
<script src="/static/dist/app.js" defer></script>
|
||||
</head>
|
||||
<body class="min-h-screen">
|
||||
<body class="min-h-screen" data-msg-network={ i18n.T(ctx, "app.network_error") }>
|
||||
{ children... }
|
||||
</body>
|
||||
</html>
|
||||
}
|
||||
|
||||
templ authShell(p Page, heading string) {
|
||||
templ languageSwitch(langs []string) {
|
||||
<span class="flex gap-2 font-mono text-xs">
|
||||
for _, l := range langs {
|
||||
if l == i18n.Lang(ctx) {
|
||||
<span class="text-ink" aria-current="true">{ l }</span>
|
||||
} else {
|
||||
<button type="button" data-locale={ l } class="text-muted hover:text-ink" title={ i18n.T(ctx, "lang."+l) }>{ l }</button>
|
||||
}
|
||||
}
|
||||
</span>
|
||||
}
|
||||
|
||||
templ authShell(p Page) {
|
||||
@Layout(p) {
|
||||
<main class="mx-auto mt-[12vh] w-full max-w-sm px-6">
|
||||
<p class="mb-10 font-mono text-xs tracking-wide text-muted">uptimesebi</p>
|
||||
<h1 class="mb-6 text-xl font-semibold">{ heading }</h1>
|
||||
<div class="mb-10 flex items-baseline justify-between">
|
||||
<p class="font-mono text-xs tracking-wide text-muted">uptimesebi</p>
|
||||
@languageSwitch(p.Languages)
|
||||
</div>
|
||||
<h1 class="mb-6 text-xl font-semibold">{ i18n.T(ctx, p.TitleID) }</h1>
|
||||
{ children... }
|
||||
</main>
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user