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
@@ -2,7 +2,6 @@ package web
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -39,21 +38,21 @@ type capacityForm struct {
|
||||
LGPUs, LCores, LMem string
|
||||
}
|
||||
|
||||
func (p *AccountPages) capacitySection(ctx context.Context, d *adminQuotasData, editing string) {
|
||||
func (p *AccountPages) capacitySection(ctx context.Context, l *Lang, d *adminQuotasData, editing string) {
|
||||
if p.capacity == nil {
|
||||
return
|
||||
}
|
||||
d.HasCapacity = true
|
||||
views, err := p.capacity.QuotaViews(ctx)
|
||||
if err != nil {
|
||||
d.Error = err.Error()
|
||||
d.Error = l.Err(err)
|
||||
return
|
||||
}
|
||||
for _, v := range views {
|
||||
d.Capacity = append(d.Capacity, capacityRow{QuotaView: v,
|
||||
GPUs: capCell(v.Holds.GPUs, v.Guarantee.GPUs, v.Limit.GPUs),
|
||||
Cores: capCell(v.Holds.CPUCores, v.Guarantee.CPUCores, v.Limit.CPUCores),
|
||||
Memory: capCell(v.Holds.MemoryGB, v.Guarantee.MemoryGB, v.Limit.MemoryGB)})
|
||||
GPUs: l.capCell(v.Holds.GPUs, v.Guarantee.GPUs, v.Limit.GPUs),
|
||||
Cores: l.capCell(v.Holds.CPUCores, v.Guarantee.CPUCores, v.Limit.CPUCores),
|
||||
Memory: l.capCell(v.Holds.MemoryGB, v.Guarantee.MemoryGB, v.Limit.MemoryGB)})
|
||||
if v.Scope == editing {
|
||||
d.CapForm = capacityForm{Scope: v.Scope,
|
||||
GPUs: intStr(v.Guarantee.GPUs), Cores: intStr(v.Guarantee.CPUCores), Memory: intStr(v.Guarantee.MemoryGB),
|
||||
@@ -61,21 +60,25 @@ func (p *AccountPages) capacitySection(ctx context.Context, d *adminQuotasData,
|
||||
}
|
||||
}
|
||||
if d.Scopes, err = p.capacity.Scopes(ctx); err != nil {
|
||||
d.Error = err.Error()
|
||||
d.Error = l.Err(err)
|
||||
}
|
||||
}
|
||||
|
||||
// capCell is a capacity figure in English, for a caller with no request to
|
||||
// take a language from.
|
||||
func capCell(holds int, g, l *int) string { return english.capCell(holds, g, l) }
|
||||
|
||||
// capCell is "6 of 8 (at most 16)": held, guaranteed, limit.
|
||||
func capCell(holds int, g, l *int) string {
|
||||
func (lang *Lang) capCell(holds int, g, l *int) string {
|
||||
if g == nil && l == nil {
|
||||
return ""
|
||||
}
|
||||
out := strconv.Itoa(holds)
|
||||
out := lang.Int(int64(holds))
|
||||
if g != nil {
|
||||
out += " of " + strconv.Itoa(*g)
|
||||
out = lang.T("capacity.cell.of", out, lang.Int(int64(*g)))
|
||||
}
|
||||
if l != nil {
|
||||
out += fmt.Sprintf(" (at most %d)", *l)
|
||||
out = lang.T("capacity.cell.at_most", out, lang.Int(int64(*l)))
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -87,27 +90,30 @@ func intStr(v *int) string {
|
||||
return strconv.Itoa(*v)
|
||||
}
|
||||
|
||||
// applyCapacity sets or clears one scope's capacity quota from the form.
|
||||
// applyCapacity sets or clears one scope's capacity quota from the form, and
|
||||
// says what it did in the request's language. What the admin API refuses is
|
||||
// its own English.
|
||||
func (p *AccountPages) applyCapacity(r *http.Request, admin store.User) (string, error) {
|
||||
l := langOf(r)
|
||||
scope := strings.TrimSpace(r.FormValue("scope"))
|
||||
if scope == "" {
|
||||
return "", fmt.Errorf("choose where the quota applies")
|
||||
return "", quotaRefusal{key: "capacity.err.scope"}
|
||||
}
|
||||
if r.FormValue("clear") != "" {
|
||||
key, err := p.capacity.ClearQuota(r.Context(), scope)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return "capacity quota removed from " + key, nil
|
||||
return l.T("capacity.msg.removed", key), nil
|
||||
}
|
||||
field := func(name, what string) (*int, error) {
|
||||
field := func(name string) (*int, error) {
|
||||
v := strings.TrimSpace(r.FormValue(name))
|
||||
if v == "" {
|
||||
return nil, nil
|
||||
}
|
||||
n, err := strconv.Atoi(v)
|
||||
if err != nil || n < 0 {
|
||||
return nil, fmt.Errorf("%s must be a whole number, or blank for none", what)
|
||||
return nil, quotaRefusal{key: "capacity.err." + name}
|
||||
}
|
||||
return &n, nil
|
||||
}
|
||||
@@ -117,16 +123,15 @@ func (p *AccountPages) applyCapacity(r *http.Request, admin store.User) (string,
|
||||
for _, f := range []struct {
|
||||
dst **int
|
||||
name string
|
||||
what string
|
||||
}{
|
||||
{&req.Guarantee.GPUs, "gpus", "guaranteed GPUs"},
|
||||
{&req.Guarantee.CPUCores, "cores", "guaranteed cores"},
|
||||
{&req.Guarantee.MemoryGB, "memory", "guaranteed memory"},
|
||||
{&req.Limit.GPUs, "limit_gpus", "the GPU limit"},
|
||||
{&req.Limit.CPUCores, "limit_cores", "the core limit"},
|
||||
{&req.Limit.MemoryGB, "limit_memory", "the memory limit"},
|
||||
{&req.Guarantee.GPUs, "gpus"},
|
||||
{&req.Guarantee.CPUCores, "cores"},
|
||||
{&req.Guarantee.MemoryGB, "memory"},
|
||||
{&req.Limit.GPUs, "limit_gpus"},
|
||||
{&req.Limit.CPUCores, "limit_cores"},
|
||||
{&req.Limit.MemoryGB, "limit_memory"},
|
||||
} {
|
||||
if *f.dst, err = field(f.name, f.what); err != nil {
|
||||
if *f.dst, err = field(f.name); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
@@ -134,5 +139,5 @@ func (p *AccountPages) applyCapacity(r *http.Request, admin store.User) (string,
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return "capacity quota set on " + key + "; it takes effect within half a minute", nil
|
||||
return l.T("capacity.msg.set", key), nil
|
||||
}
|
||||
Reference in new issue
Block a user