agentscope-ai / agentscope-ai/agentscope-java

[Feature]: Add i18n (Chinese / English) support to `agentscope-service/frontend`

Aberta
#2,843 0 comentários 0 reações 0 responsáveis Ver no GitHub
enhancement
Linguagem predominante
Java
Estrelas
5.6k
Forks
1.3k
Merge médio
4d 12h
PRs com merge (30d)
77

Descrição

## Feature description

The `agentscope-service/frontend` module (React + Vite + TypeScript) currently renders **all UI text in English only**. We request first-class internationalization (i18n) support with at least **Chinese (`zh`) / English (`en`) switching** for the web console.

`agentscope-service/frontend/src` currently contains: `api/`, `app/`, `components/`, `features/`, `lib/`, `pages/`, `main.tsx` — but **no `i18n/` module**. Every user-facing string ships English-only.

## Motivation

- The AgentScope backend and agent framework already serve a large **Chinese-speaking user base**.
- Enterprise / internal deployments require a **Chinese UI** .
- Without an i18n layer, each new feature adds more English-only strings, raising long-term migration cost.

## Proposed design

A lightweight, **dependency-free** i18n layer (no heavy i18n library required) with the following shape:

1. **Dictionary module** `src/i18n/index.tsx`
- Typed dictionaries `en` and `zh` (~806 keys each when last measured, fully paired).
- `type Locale = 'zh' | 'en'`.
2. **Provider** `I18nProvider`
- Reads initial locale from `localStorage` (fallback to `navigator.language`).
- Exposes `locale`, `setLocale`, and `t(key)` / `useT()`.
- Syncs `` via `document.documentElement.lang`.
3. **Hooks**
- `useI18n()` → `{ locale, setLocale, t }`
- `useT()` → `t` function for concise component usage.
4. **Language switcher**
- A **Globe toggle** in `AppShell` (`中` / `En`) that flips `locale` and persists the choice to `localStorage`.

This is a **non-breaking change**: English remains the default/fallback, and missing keys fall back to `en`.

## Current status — a working implementation is available

A **complete implementation already exists in a local fork** and can be contributed upstream as a PR:

- `en` / `zh` dictionaries: 806 keys each, **0 missing keys** (parity verified programmatically).
- `I18nProvider` + `useI18n()` / `useT()` hooks wired into `main.tsx`.
- Globe language switcher present in `AppShell.tsx`.
- ~763 `t()` call sites across 38 files.

**Known gap to close (with or before the PR):** roughly **20 components still contain hardcoded English, user-facing strings that bypass `t()`**, e.g.:

- `components/AgentLayout.tsx` — "Missing agent id.", "Runtime", "Open this agent in Operate…"
- `components/ChannelBindingTable.tsx` — "Channels", "No channels registered.", "stopped"
- `components/WorkspaceFileTree.tsx` — "Files", "Empty workspace.", "refresh"
- `components/ToolCallBlock.tsx` — "Input", "Result", "Running…"
- `features/operate/components/*` — "Plan", "Built-in tools", "MCP servers", "Loading…", "No messages.", …
- `features/operate/components/StatusStrip.tsx` — "Phase", "Model", "Pressure", "healthy"

These must be routed through the dictionary to reach **full coverage**.

## Additional context

- No new runtime dependency is required — the implementation is a small in-house provider (~a single `i18n/index.tsx` plus hook wiring).
- Default-language detection should respect `navigator.language` so Chinese-locale browsers see `zh` by default when no stored preference exists.
- The 30 `zh` entries whose value is still ASCII (e.g. `ID`, `AGENTS.md`, `nacos serverAddr`, API endpoint paths) are **intentionally untranslated** proper nouns / code identifiers and should stay as-is.

**Suggested next step:** open a PR from the existing fork implementation, closing the ~20 hardcoded-string gaps as part of the same change.

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.