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:
Ilker ManapandClaude Opus 5.5 committed 2026-10-05 00:12:53 +02:00
1 parent 30f7f3474a
commit 11231d8c2b
113 files changed
+8091 -1981

No files matched your search

+29 -30
View File
@@ -2,7 +2,6 @@ package web
import (
"context"
"fmt"
"html/template"
"time"
@@ -44,7 +43,7 @@ type placeUse struct {
Spend string
}
func (p *AccountPages) fillOwnUse(ctx context.Context, user store.User, d *profileData) {
func (p *AccountPages) fillOwnUse(ctx context.Context, l *Lang, user store.User, d *profileData) {
su, ok := p.keys.(SelfUsage)
if !ok {
return
@@ -61,16 +60,16 @@ func (p *AccountPages) fillOwnUse(ctx context.Context, user store.User, d *profi
u.Requests += pl.Requests
u.Tokens += pl.Tokens
cost += pl.CostMicros
byPlace[pl.ProjectID] = placeUse{pl.Requests, pl.Tokens, units(pl.CostMicros)}
byPlace[pl.ProjectID] = placeUse{pl.Requests, pl.Tokens, l.Units(pl.CostMicros)}
}
u.Spend = units(cost)
u.Spend = l.Units(cost)
s := Series{Colour: "--accent"}
for _, b := range buckets {
s.Values = append(s.Values, float64(b.Prompt+b.Completion))
s.Labels = append(s.Labels, b.Start.UTC().Format("Jan 2"))
s.Labels = append(s.Labels, l.Format(b.Start.UTC(), "Jan 2"))
}
if u.Requests > 0 {
u.Chart = BarChart(s, "tokens")
u.Chart = l.BarChart(s, l.T("selfuse.chart_unit"))
}
d.Own = u
@@ -79,22 +78,22 @@ func (p *AccountPages) fillOwnUse(ctx context.Context, user store.User, d *profi
if pu, ok := byPlace[c.project]; ok {
c.Use = &pu
}
for _, l := range c.chain {
if l.Budget == nil || l.Scope == store.ScopeKey {
for _, lim := range c.chain {
if lim.Budget == nil || lim.Scope == store.ScopeKey {
continue
}
start := accounting.PeriodStart(l.BudgetPeriod, time.Now())
spent, err := su.SpendOfPool(ctx, l, start)
start := accounting.PeriodStart(lim.BudgetPeriod, time.Now())
spent, err := su.SpendOfPool(ctx, lim, start)
if err != nil {
p.log.Warn("could not read a pool's spend", "scope", l.Scope, "err", err)
p.log.Warn("could not read a pool's spend", "scope", lim.Scope, "err", err)
continue
}
bar := budgetBar{Label: poolLabel(l.Scope), Used: units(spent), Budget: units(*l.Budget),
Period: periodWord(l.BudgetPeriod)}
if *l.Budget > 0 {
bar.Percent = int(min(spent*100 / *l.Budget, 100))
bar.Near = spent*5 >= *l.Budget*4
bar.Over = spent >= *l.Budget
bar := budgetBar{Label: poolLabel(l, lim.Scope), Used: l.Units(spent), Budget: l.Units(*lim.Budget),
Period: periodWord(l, lim.BudgetPeriod)}
if *lim.Budget > 0 {
bar.Percent = int(min(spent*100 / *lim.Budget, 100))
bar.Near = spent*5 >= *lim.Budget*4
bar.Over = spent >= *lim.Budget
}
c.Budgets = append(c.Budgets, bar)
}
@@ -104,34 +103,34 @@ func (p *AccountPages) fillOwnUse(ctx context.Context, user store.User, d *profi
// poolLabel says whose budget a limit is, which is the thing a person needs
// to read a bar right: their own is theirs to spend, a project's is shared
// with everyone in it.
func poolLabel(s store.Scope) string {
func poolLabel(l *Lang, s store.Scope) string {
switch s {
case store.ScopeUser:
return "Your budget, across everything you use"
return l.T("selfuse.pool.user")
case store.ScopeProjectMember:
return "Your budget in this project"
return l.T("selfuse.pool.project_member")
case store.ScopeTeamMember:
return "Your budget in this team"
return l.T("selfuse.pool.team_member")
case store.ScopeOrgMember:
return "Your budget in this organization"
return l.T("selfuse.pool.org_member")
case store.ScopeProject:
return "The project's budget, shared with its members"
return l.T("selfuse.pool.project")
case store.ScopeTeam:
return "The team's budget, shared across its projects"
return l.T("selfuse.pool.team")
case store.ScopeOrg:
return "The organization's budget, shared across it"
return l.T("selfuse.pool.org")
}
return string(s)
}
func periodWord(p store.Period) string {
func periodWord(l *Lang, p store.Period) string {
switch p {
case store.PeriodDay:
return "today"
return l.T("selfuse.period.day")
case store.PeriodMonth:
return "this month"
return l.T("selfuse.period.month")
case store.PeriodNone:
return "in total"
return l.T("selfuse.period.none")
}
return fmt.Sprintf("this %s", p)
return l.T("selfuse.period.other", string(p))
}