The portal in English and Turkish: a catalogue per language, a switcher at the foot of every page, landing.language, Turkish numbers and dates
Every template and handler message in internal/web goes through a JSON
catalogue under internal/web/locales/<code>/, with English as the fallback.
The language is the person's choice (a cookie set by /_lang/{code}), else
Accept-Language, else landing.language. Tests refuse a key some language
lacks, a translation with other arguments than English, and template text
left in English.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
30f7f3474a
commit
11231d8c2b
113 files changed
+8091
-1981
No files matched your search
@@ -52,7 +52,7 @@ var guardWindows = map[string]time.Duration{"24h": 24 * time.Hour, "7d": 7 * 24
|
||||
func (p *AccountPages) RegisterAdminGuard(mux *http.ServeMux, s GuardAdminSource, library guard.Config) {
|
||||
p.hasGuard = true
|
||||
mux.HandleFunc("GET /admin/guard", p.adminOnly(func(w http.ResponseWriter, r *http.Request, admin store.User) {
|
||||
ctx := r.Context()
|
||||
ctx, l := r.Context(), langOf(r)
|
||||
d := guardPageData{Nav: p.navFor(r, admin, "guard"), Version: p.version, Window: r.URL.Query().Get("window"),
|
||||
Windows: []string{"24h", "7d", "30d"}, Default: library.Default}
|
||||
since, ok := guardWindows[d.Window]
|
||||
@@ -64,7 +64,7 @@ func (p *AccountPages) RegisterAdminGuard(mux *http.ServeMux, s GuardAdminSource
|
||||
}
|
||||
slices.Sort(d.Policies)
|
||||
|
||||
where := map[string]string{"": "personal"}
|
||||
where := map[string]string{"": l.T("guard.personal")}
|
||||
if projects, err := s.AllProjects(ctx); err == nil {
|
||||
for _, pp := range projects {
|
||||
where[pp.ID] = pp.Path
|
||||
@@ -82,27 +82,62 @@ func (p *AccountPages) RegisterAdminGuard(mux *http.ServeMux, s GuardAdminSource
|
||||
if a.Scope == "project" {
|
||||
who = name(a.ScopeID)
|
||||
}
|
||||
d.Attachments = append(d.Attachments, guardAttachmentRow{Scope: a.Scope, Who: who, Policy: a.Policy})
|
||||
d.Attachments = append(d.Attachments, guardAttachmentRow{Scope: guardScopeWord(l, a.Scope), Who: who, Policy: a.Policy})
|
||||
}
|
||||
}
|
||||
counts, err := s.GuardCounts(ctx, time.Now().Add(-since))
|
||||
if err != nil {
|
||||
d.Error = err.Error()
|
||||
d.Error = l.Err(err)
|
||||
}
|
||||
for _, c := range counts {
|
||||
d.Counts = append(d.Counts, guardCountRow{Where: name(c.ProjectID), Action: c.Action,
|
||||
d.Counts = append(d.Counts, guardCountRow{Where: name(c.ProjectID), Action: guardActionWord(l, c.Action),
|
||||
Policy: c.Policy, Category: c.Category, Count: c.Count})
|
||||
}
|
||||
events, err := s.GuardEvents(ctx, time.Now().Add(-since), 100)
|
||||
if err != nil {
|
||||
d.Error = err.Error()
|
||||
d.Error = l.Err(err)
|
||||
}
|
||||
for _, e := range events {
|
||||
d.Events = append(d.Events, guardEventRow{At: e.At.UTC().Format("2006-01-02 15:04:05"),
|
||||
RequestID: e.RequestID, Where: name(e.ProjectID), Model: e.Model, Action: e.Action,
|
||||
// The day as the reader writes one; the seconds stay, because
|
||||
// events a second apart are what this table tells apart.
|
||||
at := e.At.UTC()
|
||||
d.Events = append(d.Events, guardEventRow{At: l.Date(at) + " " + at.Format("15:04:05"),
|
||||
RequestID: e.RequestID, Where: name(e.ProjectID), Model: e.Model, Action: guardActionWord(l, e.Action),
|
||||
Policy: e.Policy, Category: e.Category, Status: e.Status, Ms: e.GuardMs})
|
||||
}
|
||||
noStore(w)
|
||||
render(w, "admin_guard", d)
|
||||
render(w, r, "admin_guard", d)
|
||||
}))
|
||||
}
|
||||
|
||||
// guardScopeWord names the kind of scope a policy is attached to in the
|
||||
// reader's language. A kind this page does not know is shown as stored.
|
||||
func guardScopeWord(l *Lang, scope string) string {
|
||||
switch scope {
|
||||
case "org":
|
||||
return l.T("guard.scope.org")
|
||||
case "team":
|
||||
return l.T("guard.scope.team")
|
||||
case "project":
|
||||
return l.T("guard.scope.project")
|
||||
case "user":
|
||||
return l.T("guard.scope.user")
|
||||
case "key":
|
||||
return l.T("guard.scope.key")
|
||||
}
|
||||
return scope
|
||||
}
|
||||
|
||||
// guardActionWord is what a policy did, in the reader's language. The stored
|
||||
// value stays the English word the events are recorded and queried by.
|
||||
func guardActionWord(l *Lang, action string) string {
|
||||
switch action {
|
||||
case "flagged":
|
||||
return l.T("guard.action.flagged")
|
||||
case "redacted":
|
||||
return l.T("guard.action.redacted")
|
||||
case "blocked":
|
||||
return l.T("guard.action.blocked")
|
||||
}
|
||||
return action
|
||||
}
|
||||
Reference in new issue
Block a user