feat(nofxi): full i18n bilingual support (zh/en)

Agent i18n:
- All command responses bilingual (help, status, positions, balance, trades, analysis, settings, errors)
- Language auto-detected from web UI lang toggle
- Stored per-user in SQLite preferences
- AI chat system prompt switches to Chinese/English based on user lang
- Trade confirmation prompts bilingual

Web UI:
- Sends lang parameter with every API request
- Agent extracts [lang:xx] prefix and persists preference

i18n message catalog: nofxi/internal/agent/i18n.go
This commit is contained in:
shinchan-zhai
2026-03-22 22:32:38 +08:00
parent 7cd6a6f7b3
commit 4996db81d4
4 changed files with 355 additions and 315 deletions

View File

@@ -36,6 +36,7 @@ func NewWebServer(port int, handler MessageHandler, webDir string, logger *slog.
type chatRequest struct {
UserID int64 `json:"user_id"`
Message string `json:"message"`
Lang string `json:"lang"` // "zh" or "en"
}
// chatResponse is the API response body.
@@ -78,7 +79,12 @@ func (w *WebServer) Start(ctx context.Context) error {
req.UserID = 1 // Default user for API access
}
resp, err := w.handler(r.Context(), req.UserID, req.Message)
// Pass language preference via message prefix (agent will extract it)
message := req.Message
if req.Lang != "" {
message = "[lang:" + req.Lang + "] " + message
}
resp, err := w.handler(r.Context(), req.UserID, message)
if err != nil {
writeJSON(rw, http.StatusInternalServerError, chatAPIResponse{Error: err.Error()})
return