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

+57 -56
View File
@@ -86,7 +86,7 @@ type serveForm struct {
}
// planServe works out what serving this version would mean.
func planServe(st mirror.Status, files []mirror.Status, base string,
func planServe(l *Lang, st mirror.Status, files []mirror.Status, base string,
fleet Source, cat CatalogAdmin, check func(source string) gguf.Verdict,
) serveForm {
var header gguf.Header
@@ -123,14 +123,14 @@ func planServe(st mirror.Status, files []mirror.Status, base string,
switch f.Engine {
case "":
f.Refusal = "nothing here reads " + extOf(st.File) + " files"
f.Refusal = l.T("serve.refuse.no_engine", extOf(st.File))
return f
case "llamacpp":
f.Profile = "cpu"
if check != nil {
v := check(f.Source)
if !v.Servable {
f.Refusal = "llama.cpp on the nodes cannot run this: " + v.Reason
f.Refusal = l.T("serve.refuse.llamacpp", v.Reason)
return f
}
header = v.Header
@@ -139,7 +139,7 @@ func planServe(st mirror.Status, files []mirror.Status, base string,
f.Profile = "gpu"
}
f.GPUs, f.Parallel = 1, defaultParallel
f.Placements, f.FreeGPUs = placementsFor(fleet, f.Engine)
f.Placements, f.FreeGPUs = placementsFor(l, fleet, f.Engine)
for _, pc := range f.Placements {
if pc.Selected {
f.Profile = pc.profile()
@@ -152,15 +152,13 @@ func planServe(st mirror.Status, files []mirror.Status, base string,
// A warning, not a refusal: an engine can be installed this afternoon, and
// a node that reports nothing is an older agent rather than an empty one.
if !runsAnywhere(fleet, f.Engine) {
f.Warning = "no node reports having " + f.Engine + " installed, and " +
extOf(st.File) + " weights need it"
f.Warning = l.T("serve.warn.not_installed", f.Engine, extOf(st.File))
if f.Engine != "llamacpp" && gpus(fleet) == 0 {
f.Warning += ". This fleet has no GPU either; a GGUF build of the " +
"same model runs on the CPU nodes"
f.Warning += ". " + l.T("serve.warn.no_gpu")
}
}
f.CtxPool = defaultCtxPool
f.MinMemoryGB, f.MemoryBasis = memoryFor(st.BytesTotal, st.BytesDone), "weights plus half again plus two"
f.MinMemoryGB, f.MemoryBasis = memoryFor(st.BytesTotal, st.BytesDone), l.T("serve.basis.estimate")
weights := st.BytesTotal
if weights <= 0 {
weights = st.BytesDone
@@ -175,10 +173,10 @@ func planServe(st mirror.Status, files []mirror.Status, base string,
// across the models on the live mirror at the same 16k — a spread the
// flat "half again" could not see.
f.MinMemoryGB = int((b + 1<<30 - 1) >> 30)
f.MemoryBasis = fmt.Sprintf("weights %.1f GB + KV cache %.1f GB for %d tokens (%d layers × %d KV heads) + %.1f GB for the engine",
float64(weights)/(1<<30), float64(int64(defaultCtxPool)*header.KVBytesPerToken())/(1<<30),
defaultCtxPool, header.BlockCount, kvHeads,
float64(int64(1<<30)+weights/20)/(1<<30))
f.MemoryBasis = l.T("serve.basis.shape",
l.Num(float64(weights)/(1<<30), 1), l.Num(float64(int64(defaultCtxPool)*header.KVBytesPerToken())/(1<<30), 1),
l.Int(defaultCtxPool), header.BlockCount, kvHeads,
l.Num(float64(int64(1<<30)+weights/20)/(1<<30), 1))
}
if fleet != nil {
var cpus []int
@@ -190,14 +188,15 @@ func planServe(st mirror.Status, files []mirror.Status, base string,
f.CPUCores = catalog.SuggestCores(cpus)
}
if biggest := biggestNode(fleet); biggest > 0 && f.MinMemoryGB > biggest {
f.Warning = strings.TrimSuffix(f.Warning, ".") +
fmt.Sprintf("%sthe largest node has %d GB and this needs about %d",
sep(f.Warning), biggest, f.MinMemoryGB)
big := l.T("serve.warn.too_big", biggest, f.MinMemoryGB)
if f.Warning != "" {
big = l.T("serve.warn.and", strings.TrimSuffix(f.Warning, "."), big)
}
f.Warning = big
}
if cat != nil && cat.Declared(st.Model) {
f.Already = true
f.Refusal = "a model called " + st.Model +
" is declared in configuration; edit it there rather than adding a second"
f.Refusal = l.T("serve.refuse.declared", st.Model)
}
return f
}
@@ -255,8 +254,9 @@ func gpus(fleet Source) int {
return n
}
// buildModel turns the submitted form into a catalogue entry.
func buildModel(get func(string) string) (catalog.Model, error) {
// buildModel turns the submitted form into a catalogue entry. Its refusals
// are in l, the language of whoever filled the form in.
func buildModel(l *Lang, get func(string) string) (catalog.Model, error) {
m := catalog.Model{
Name: strings.TrimSpace(get("name")),
Description: strings.TrimSpace(get("description")),
@@ -264,7 +264,7 @@ func buildModel(get func(string) string) (catalog.Model, error) {
RoutingProfile: "chat",
}
if m.Name == "" || m.Source == "" {
return m, errors.New("a model needs a name and a source")
return m, errors.New(l.T("serve.err.name_source"))
}
for _, a := range strings.Split(get("aliases"), ",") {
if a = strings.TrimSpace(a); a != "" {
@@ -272,18 +272,18 @@ func buildModel(get func(string) string) (catalog.Model, error) {
}
}
ctxLen, err := positive(get("context_length"), "the context length")
ctxLen, err := positive(l, get("context_length"), "serve.what.context_length")
if err != nil {
return m, err
}
m.ContextLength = ctxLen
if v := strings.TrimSpace(get("max_output")); v != "" {
if m.MaxOutput, err = positive(v, "the output limit"); err != nil {
if m.MaxOutput, err = positive(l, v, "serve.what.max_output"); err != nil {
return m, err
}
}
min, err := positive(get("replicas"), "the replica count")
min, err := positive(l, get("replicas"), "serve.what.replicas")
if err != nil {
return m, err
}
@@ -291,12 +291,12 @@ func buildModel(get func(string) string) (catalog.Model, error) {
engine := strings.TrimSpace(get("engine"))
if engine == "" {
return m, errors.New("which engine should run it?")
return m, errors.New(l.T("serve.err.engine"))
}
p := catalog.Profile{Engine: engine, Weight: 1, Priority: 100}
gpus := 1
if v := strings.TrimSpace(get("gpus")); v != "" {
if gpus, err = positive(v, "the GPUs per replica"); err != nil {
if gpus, err = positive(l, v, "serve.what.gpus"); err != nil {
return m, err
}
gpus = max(gpus, 1)
@@ -316,11 +316,11 @@ func buildModel(get func(string) string) (catalog.Model, error) {
place.GPUs = gpus
case place.Value == "" || place.Value == "cpu":
if engine != "llamacpp" {
return m, fmt.Errorf("%s runs on GPUs; choose a GPU class to place it on", engine)
return m, errors.New(l.T("serve.err.needs_gpu", engine))
}
place.Value = "cpu"
default:
return m, fmt.Errorf("%q is not a placement", place.Value)
return m, errors.New(l.T("serve.err.placement", place.Value))
}
p.Name = place.profile()
if v := strings.TrimSpace(get("profile")); v != "" {
@@ -330,13 +330,13 @@ func buildModel(get func(string) string) (catalog.Model, error) {
// parallel slots, so the number a client may use is smaller and is what
// context_length above says.
if v := strings.TrimSpace(get("ctx_size")); v != "" {
if _, err := positive(v, "the engine's context pool"); err != nil {
if _, err := positive(l, v, "serve.what.ctx_pool"); err != nil {
return m, err
}
p.Args = []string{"--ctx-size", v}
}
if v := strings.TrimSpace(get("parallel")); v != "" && engine == "llamacpp" {
n, err := positive(v, "the parallel requests")
n, err := positive(l, v, "serve.what.parallel")
if err != nil {
return m, err
}
@@ -345,12 +345,12 @@ func buildModel(get func(string) string) (catalog.Model, error) {
}
}
if v := strings.TrimSpace(get("min_memory_gb")); v != "" {
if p.MinMemoryGB, err = positive(v, "the memory requirement"); err != nil {
if p.MinMemoryGB, err = positive(l, v, "serve.what.memory"); err != nil {
return m, err
}
}
if v := strings.TrimSpace(get("cpu_cores")); v != "" {
if p.CPUCores, err = positive(v, "the cores"); err != nil {
if p.CPUCores, err = positive(l, v, "serve.what.cores"); err != nil {
return m, err
}
}
@@ -364,14 +364,22 @@ func buildModel(get func(string) string) (catalog.Model, error) {
return m, nil
}
func positive(v, what string) (int, error) {
// positive reads a whole number from a form field; what is the key naming
// the field, for the refusal.
func positive(l *Lang, v, what string) (int, error) {
n, err := strconv.Atoi(strings.TrimSpace(v))
if err != nil || n < 0 {
return 0, fmt.Errorf("%s must be a whole number", what)
return 0, errors.New(l.T("serve.err.whole_number", l.T(what)))
}
return n, nil
}
func init() {
registerKeys("serve.what.context_length", "serve.what.max_output", "serve.what.replicas",
"serve.what.gpus", "serve.what.ctx_pool", "serve.what.parallel", "serve.what.memory",
"serve.what.cores")
}
// memoryFor estimates the host RAM a model needs, from the size of its weights.
//
// Weights plus half again, plus two. The half covers the KV pool, which grows
@@ -409,14 +417,6 @@ func biggestNode(fleet Source) int {
return most
}
// sep joins a second clause onto a warning that may be empty.
func sep(existing string) string {
if existing == "" {
return ""
}
return ", and "
}
// Run modes a page offers for a model, in the words a person would use.
const (
modeAlways = "always"
@@ -497,7 +497,7 @@ func (c placeChoice) profile() string {
// on a cluster of GPUs, ran at a tenth of their speed, and nothing on the way
// said why — the form had no choice to offer and named the profile "cpu". The
// class selected is the one with the most cards free.
func placementsFor(fleet Source, engine string) ([]placeChoice, int) {
func placementsFor(l *Lang, fleet Source, engine string) ([]placeChoice, int) {
var out []placeChoice
free, best := 0, -1
if fleet != nil {
@@ -506,7 +506,7 @@ func placementsFor(fleet Source, engine string) ([]placeChoice, int) {
free += n
out = append(out, placeChoice{
Value: "gpu:" + c.Class,
Label: fmt.Sprintf("GPU: %s, %d of %d free", c.Class, n, c.Total),
Label: l.T("serve.place.gpu", c.Class, n, c.Total),
})
if best < 0 || n > fleet.Summary().GPUs[best].Free() {
best = len(out) - 1
@@ -517,9 +517,9 @@ func placementsFor(fleet Source, engine string) ([]placeChoice, int) {
out[best].Selected = true
}
if engine == "llamacpp" {
label := "CPU only: no GPU, many times slower"
label := l.T("serve.place.cpu_slower")
if len(out) == 0 {
label = "CPU: this fleet has no GPU"
label = l.T("serve.place.cpu_only")
}
out = append(out, placeChoice{Value: "cpu", Label: label, Selected: best < 0})
}
@@ -539,8 +539,9 @@ func freeGPUs(fleet Source) int {
}
// describeServe says, in one line, what a model will run as: the summary
// shown before it is added and in the message after.
func describeServe(m catalog.Model) string {
// shown before it is added and in the message after. The form's script says
// the same with the same sentences, so the two cannot drift apart in wording.
func describeServe(l *Lang, m catalog.Model) string {
if len(m.Profiles) == 0 {
return ""
}
@@ -549,27 +550,27 @@ func describeServe(m catalog.Model) string {
if engine == "" {
engine = p.Engine
}
where := "on the CPU"
where := l.T("serve.on_cpu", engine)
if p.GPUClass != "" {
n := max(p.GPUsPerNode, p.TP, 1)
where = fmt.Sprintf("on %s %s", plural(n, "GPU", "GPUs"), p.GPUClass)
where = l.T("serve.on_gpu_one", engine, p.GPUClass)
if n > 1 {
where = fmt.Sprintf("on %d %s GPUs of one node", n, p.GPUClass)
where = l.T("serve.on_gpus", engine, n, p.GPUClass)
}
}
parts := []string{engine + " " + where}
parts := []string{where}
if p.MinMemoryGB > 0 {
parts = append(parts, fmt.Sprintf("%d GB of host memory", p.MinMemoryGB))
parts = append(parts, l.T("serve.host_memory", l.Int(int64(p.MinMemoryGB))))
}
if p.GPUClass == "" && p.CPUCores > 0 {
parts = append(parts, plural(p.CPUCores, "core", "cores"))
parts = append(parts, l.N("serve.cores", int64(p.CPUCores)))
}
pool, parallel := argInt(p.Args, "--ctx-size"), argInt(p.Args, "--parallel")
switch {
case pool > 0 && parallel > 0:
parts = append(parts, fmt.Sprintf("context pool %d over %d parallel requests (%d each)", pool, parallel, pool/parallel))
parts = append(parts, l.T("serve.pool_parallel", l.Int(int64(pool)), l.Int(int64(parallel)), l.Int(int64(pool/parallel))))
case pool > 0:
parts = append(parts, fmt.Sprintf("context pool %d", pool))
parts = append(parts, l.T("serve.pool", l.Int(int64(pool))))
}
return strings.Join(parts, ", ")
}