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

+44 -43
View File
@@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"html/template"
"net/http"
"slices"
@@ -238,10 +237,12 @@ func (p *AccountPages) RegisterAdminMirror(mux *http.ServeMux, d MirrorDeps) {
d := adminMirrorData{CSRF: csrfFor(r), Inline: true, HasRegistry: true}
p.openRepo(r, &d, repo)
if d.RegistryErr != "" {
http.Error(w, "The registry: "+d.RegistryErr, http.StatusBadGateway)
// Read by the page's own script, which shows it beneath the
// row, so it is in the page's language.
http.Error(w, langOf(r).T("explore.registry_err", d.RegistryErr), http.StatusBadGateway)
return
}
render(w, "mirror_repo", d)
render(w, r, "mirror_repo", d)
}))
mux.HandleFunc("POST /admin/mirror/fetch", p.mirrorAction(m,
@@ -249,9 +250,10 @@ func (p *AccountPages) RegisterAdminMirror(mux *http.ServeMux, d MirrorDeps) {
// One form posts one source or fifteen. A sharded model is one
// decision, not one per shard, and the mirror fetches each file
// independently anyway.
l := langOf(r)
sources, files := r.Form["source"], r.Form["file"]
if len(sources) == 0 || strings.TrimSpace(sources[0]) == "" {
return "", errors.New("a source URL is required")
return "", errors.New(l.T("mirror.err.source_required"))
}
model := strings.TrimSpace(r.FormValue("model"))
version := strings.TrimSpace(r.FormValue("version"))
@@ -261,7 +263,7 @@ func (p *AccountPages) RegisterAdminMirror(mux *http.ServeMux, d MirrorDeps) {
// of download and a replica failing on every node.
if r.FormValue("force") == "" {
if v := p.checkSource(ctx, strings.TrimSpace(sources[0])); !v.Servable {
return "", fmt.Errorf("not fetched: %s. Tick \"fetch anyway\" to take it regardless", v.Reason)
return "", errors.New(l.T("mirror.err.not_fetched", v.Reason))
}
}
@@ -278,25 +280,25 @@ func (p *AccountPages) RegisterAdminMirror(mux *http.ServeMux, d MirrorDeps) {
if _, err := m.Fetch(ctx, req); err != nil {
// Reported with what already went, so a set that fails on
// its fourth shard does not read as though nothing started.
return "", fmt.Errorf("%d of %d started, then %s: %w",
started, len(sources), mirror.LastPathElement(src), err)
return "", errors.New(l.T("mirror.err.partly_started",
started, len(sources), mirror.LastPathElement(src), l.Err(err)))
}
started++
}
// Named as started, not as done. The mirror answered 202 and the
// bytes are still moving; a message saying "added" would invite
// somebody to point the catalog at a partial file.
return fmt.Sprintf("started downloading %s/%s (%s)",
model, version, plural(started, "file", "files")), nil
return l.T("mirror.msg.started", model, version, l.N("mirror.files", int64(started))), nil
}))
if d.Catalog != nil {
// How a model runs, changed where the file it runs is seen.
mux.HandleFunc("POST /admin/mirror/mode", p.mirrorAction(m,
func(ctx context.Context, admin store.User, r *http.Request) (string, error) {
l := langOf(r)
name, mode := r.FormValue("model"), r.FormValue("mode")
if name == "" || (mode != modeAlways && mode != modeOnDemand && mode != modeStopped) {
return "", errors.New("choose a model and how it should run")
return "", errors.New(l.T("mirror.err.choose_mode"))
}
replicas, _ := strconv.Atoi(r.FormValue("replicas"))
sc := scalingFor(mode, replicas, 0)
@@ -305,11 +307,11 @@ func (p *AccountPages) RegisterAdminMirror(mux *http.ServeMux, d MirrorDeps) {
}
switch mode {
case modeOnDemand:
return name + " now loads when asked for and stops after 15 minutes unused", nil
return l.T("mirror.msg.ondemand", name), nil
case modeStopped:
return name + " is stopped; its replicas are being taken down", nil
return l.T("mirror.msg.stopped", name), nil
}
return name + " now runs all the time", nil
return l.T("mirror.msg.always", name), nil
}))
mux.HandleFunc("POST /admin/mirror/replicas", p.mirrorAction(m, p.setModel))
@@ -317,7 +319,8 @@ func (p *AccountPages) RegisterAdminMirror(mux *http.ServeMux, d MirrorDeps) {
mux.HandleFunc("POST /admin/mirror/serve", p.mirrorAction(m,
func(ctx context.Context, admin store.User, r *http.Request) (string, error) {
model, err := buildModel(r.FormValue)
l := langOf(r)
model, err := buildModel(l, r.FormValue)
if err != nil {
return "", err
}
@@ -326,9 +329,7 @@ func (p *AccountPages) RegisterAdminMirror(mux *http.ServeMux, d MirrorDeps) {
// speed with nothing saying why.
if model.Profiles[0].CPUOnly() && r.FormValue("cpu_ok") == "" {
if n := freeGPUs(p.fleet); n > 0 {
return "", fmt.Errorf("this fleet has %s free and %s was set to run on the CPU; "+
"choose a GPU placement, or tick \"run on the CPU anyway\"",
plural(n, "GPU", "GPUs"), model.Name)
return "", errors.New(l.N("serve.err.cpu_with_free_gpus", int64(n), model.Name))
}
}
// The same check `llmgw ctl model add` makes. This page builds
@@ -345,9 +346,8 @@ func (p *AccountPages) RegisterAdminMirror(mux *http.ServeMux, d MirrorDeps) {
}
// Placed on the next pass, not now: saying it is serving would
// be wrong for however long the weights take to reach a node.
return fmt.Sprintf(
"%s added to the catalog, %s: %s; it is placed on the next pass",
model.Name, plural(model.Scaling.Min, "replica", "replicas"), describeServe(model)), nil
return l.T("serve.msg.added", model.Name,
l.N("serve.replicas_n", int64(model.Scaling.Min)), describeServe(l, model)), nil
}))
}
@@ -358,8 +358,8 @@ func (p *AccountPages) RegisterAdminMirror(mux *http.ServeMux, d MirrorDeps) {
if err != nil {
return "", err
}
return "removed " + model + "/" + ver +
" (" + plural(len(removed), "file", "files") + ")", nil
l := langOf(r)
return l.T("mirror.msg.removed", model, ver, l.N("mirror.files", int64(len(removed)))), nil
}))
}
@@ -386,10 +386,10 @@ func (p *AccountPages) mirrorAction(m MirrorAdmin,
p.log.Warn("a mirror action was refused",
"admin", admin.Email, "mirror", m.Addr(), "err", err)
if wantJSON {
writeJSONStatus(w, http.StatusUnprocessableEntity, map[string]string{"error": err.Error()})
writeJSONStatus(w, http.StatusUnprocessableEntity, map[string]string{"error": langOf(r).Err(err)})
return
}
p.renderMirror(w, r, m, "", err.Error())
p.renderMirror(w, r, m, "", langOf(r).Err(err))
return
}
p.log.Info("the mirror was changed",
@@ -405,6 +405,7 @@ func (p *AccountPages) mirrorAction(m MirrorAdmin,
func (p *AccountPages) renderMirror(w http.ResponseWriter, r *http.Request,
m MirrorAdmin, msg, errMsg string,
) {
l := langOf(r)
d := adminMirrorData{
Nav: navFrom(r, "mirror"),
Addr: m.Addr(),
@@ -430,10 +431,10 @@ func (p *AccountPages) renderMirror(w http.ResponseWriter, r *http.Request,
p.log.Error("could not read the mirror", "mirror", m.Addr(), "err", err)
d.Unreachable = true
if d.Error == "" {
d.Error = err.Error()
d.Error = l.Err(err)
}
d.Tabs = mirrorTabs(d)
render(w, "admin_mirror", d)
d.Tabs = mirrorTabs(l, d)
render(w, r, "admin_mirror", d)
return
}
@@ -521,7 +522,7 @@ func (p *AccountPages) renderMirror(w http.ResponseWriter, r *http.Request,
for i := range d.Rows {
d.Rows[i].Open = openKey(d.Rows[i].Model, d.Rows[i].Version)
if open != "" && d.Rows[i].Open == open && d.Rows[i].State == mirror.Present {
d.Rows[i].Detail = p.heldDetailFor(r.Context(), d.Rows[i])
d.Rows[i].Detail = p.heldDetailFor(r.Context(), l, d.Rows[i])
d.Rows[i].Detail.addAdapterChoices(d.Rows[i], d.Rows)
}
}
@@ -539,7 +540,7 @@ func (p *AccountPages) renderMirror(w http.ResponseWriter, r *http.Request,
if key != want || d.Rows[i].State != mirror.Present {
continue
}
form := planServe(d.Rows[i].Status,
form := planServe(l, d.Rows[i].Status,
byVersion[d.Rows[i].Model+"/"+d.Rows[i].Version], got.Base, p.fleet, p.catalog, func(src string) gguf.Verdict { return p.checkSource(r.Context(), src) })
d.Rows[i].Serve = &form
break
@@ -572,8 +573,8 @@ func (p *AccountPages) renderMirror(w http.ResponseWriter, r *http.Request,
if d.Fetching > 0 && d.Tab == tabHeld && open == "" {
d.RefreshSec = 5
}
d.Tabs = mirrorTabs(d)
render(w, "admin_mirror", d)
d.Tabs = mirrorTabs(l, d)
render(w, r, "admin_mirror", d)
}
const (
@@ -617,25 +618,25 @@ func mirrorTabFor(r *http.Request, errMsg string) string {
return tabHeld
}
func mirrorTabs(d adminMirrorData) []mirrorTab {
held := mirrorTab{Label: "Held", Href: "/admin/mirror?tab=held", Active: d.Tab == tabHeld}
func mirrorTabs(l *Lang, d adminMirrorData) []mirrorTab {
held := mirrorTab{Label: l.T("mirror.tab.held"), Href: "/admin/mirror?tab=held", Active: d.Tab == tabHeld}
switch {
case d.Unreachable:
held.Count = "unreachable"
held.Count = l.T("mirror.tab.unreachable")
case d.Fetching > 0:
held.Count = fmt.Sprintf("%d · %d downloading", d.Present, d.Fetching)
held.Count = l.T("mirror.tab.downloading", l.Int(int64(d.Present)), l.Int(int64(d.Fetching)))
default:
held.Count = strconv.Itoa(d.Present)
held.Count = l.Int(int64(d.Present))
}
if d.Failed > 0 {
held.Count += fmt.Sprintf(" · %d failed", d.Failed)
held.Count += " · " + l.T("mirror.tab.failed", l.Int(int64(d.Failed)))
}
tabs := []mirrorTab{held}
if d.HasRegistry {
tabs = append(tabs, mirrorTab{Label: "Explore Hugging Face",
tabs = append(tabs, mirrorTab{Label: l.T("mirror.tab.explore"),
Href: "/admin/mirror?tab=explore", Active: d.Tab == tabExplore})
}
return append(tabs, mirrorTab{Label: "Fetch by URL",
return append(tabs, mirrorTab{Label: l.T("mirror.tab.fetch"),
Href: "/admin/mirror?tab=fetch", Active: d.Tab == tabFetch})
}
@@ -752,7 +753,7 @@ func (p *AccountPages) explore(r *http.Request, d *adminMirrorData) {
func (p *AccountPages) openRepo(r *http.Request, d *adminMirrorData, repo string) {
got, err := p.registry.Repo(r.Context(), repo)
if err != nil {
d.RegistryErr = err.Error()
d.RegistryErr = langOf(r).Err(err)
return
}
d.Repo = &got
@@ -777,7 +778,7 @@ func (p *AccountPages) openRepo(r *http.Request, d *adminMirrorData, repo string
// the same branch lands somewhere else.
Version: got.ShortRevision(),
}
rs.Verdict = p.verdictFor(got.Architecture, set.Name)
rs.Verdict = p.verdictFor(langOf(r), got.Architecture, set.Name)
for _, f := range set.Files {
rs.Sources = append(rs.Sources,
repoSource{URL: got.DownloadURL("", f.Path), Path: f.Path})
@@ -847,7 +848,7 @@ func defaultModelName(repoID string) string { return hf.ModelName(repoID) }
// verdictFor judges a registry file set by the repository's architecture. A
// vision projector is its own architecture whatever the repository says.
func (p *AccountPages) verdictFor(arch, name string) gguf.Verdict {
func (p *AccountPages) verdictFor(l *Lang, arch, name string) gguf.Verdict {
if strings.Contains(strings.ToLower(name), "mmproj") {
return gguf.LlamaCpp(p.llamaVersion, "clip")
}
@@ -855,7 +856,7 @@ func (p *AccountPages) verdictFor(arch, name string) gguf.Verdict {
// file like them, so the repository's architecture would pass it.
if strings.Contains(strings.ToLower(name), "imatrix") {
return gguf.Verdict{Checked: true,
Reason: "it is an importance matrix for quantising, not a model"}
Reason: l.T("card.imatrix")}
}
if arch == "" || !gguf.IsGGUF(name) {
return gguf.Verdict{Servable: true}