diff --git a/internal/dashboard/server.go b/internal/dashboard/server.go index 51dd403..0ef9311 100644 --- a/internal/dashboard/server.go +++ b/internal/dashboard/server.go @@ -11,11 +11,13 @@ import ( "log" "net" "net/http" + "sort" "strings" "sync/atomic" "time" "github.com/fabgoodvibes/owlrun/internal/buildinfo" + "github.com/fabgoodvibes/owlrun/internal/i18n" "github.com/fabgoodvibes/owlrun/internal/cashu" "github.com/fabgoodvibes/owlrun/internal/earnings" ) @@ -300,6 +302,8 @@ func (s *Server) Start() error { mux.HandleFunc("/api/set-context-length", s.handleSetContextLength) mux.HandleFunc("/api/set-free-tier", s.handleSetFreeTier) mux.HandleFunc("/api/set-keep-warm", s.handleSetKeepWarm) + mux.HandleFunc("/api/locale", handleLocale) + mux.HandleFunc("/api/locales", handleLocales) addr := fmt.Sprintf("127.0.0.1:%d", s.port) ln, err := net.Listen("tcp", addr) if err != nil { @@ -850,9 +854,43 @@ func isValidLightningAddress(addr string) bool { return true } +// handleLocale serves the full translation map for a given locale. +// GET /api/locale?lang=ca β†’ JSON map of keyβ†’string. +func handleLocale(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + w.Header().Set("Access-Control-Allow-Origin", "*") + lang := r.URL.Query().Get("lang") + if lang == "" { + lang = "en" + } + json.NewEncoder(w).Encode(i18n.Messages(lang)) +} + +// handleLocales returns the list of available locales with display names. +// GET /api/locales β†’ [{"code":"en","name":"English"}, …] +func handleLocales(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + w.Header().Set("Access-Control-Allow-Origin", "*") + type localeInfo struct { + Code string `json:"code"` + Name string `json:"name"` + } + var out []localeInfo + for _, code := range i18n.Locales() { + msgs := i18n.Messages(code) + name := code + if v, ok := msgs["_lang"]; ok { + name = v + } + out = append(out, localeInfo{Code: code, Name: name}) + } + sort.Slice(out, func(i, j int) bool { return out[i].Code < out[j].Code }) + json.NewEncoder(w).Encode(out) +} + func (s *Server) handleIndex(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html; charset=utf-8") - fmt.Fprint(w, dashboardHTML) + io.WriteString(w, dashboardHTML) //nolint:errcheck } const dashboardHTML = ` @@ -860,7 +898,7 @@ const dashboardHTML = ` -Owlrun Dashboard +Owlrun Dashboard -
+

πŸ¦‰ Owlrun

+
+ +
+
+ No notifications + +
+ +
+
β˜€οΈ
πŸŒ™
-
-
Wallet not configured
-
- -
-
Notifications
-
-
Gateway notifications will appear here.
+
+
+
+
Wallet not configured
+
+
+
-
- - -
-
Wallet
-