1.4 KiB
1.4 KiB
Frontend i18n
The web UI is a React + Semi Design single-page app. Translations come from
web/frontend/src/lib/i18n.jsx, backed by the same JSON files the backend ships.
Files
web/static/i18n/zh-CN.json
web/static/i18n/en-US.json
web/static/i18n/ru-RU.json
web/static/i18n/ar-SA.json
web/frontend/src/lib/i18n.jsx
Runtime behavior
- Preference is stored in
localStorage['csai_lang']; otherwise it followsnavigator.language, defaulting tozh-CN. - The provider loads the active language plus
zh-CNanden-USfallbacks; lookups fall backactive → zh-CN → en-US → caller default. - Switching language updates
<html lang>, setsdir="rtl"for Arabic, and swaps Semi'sConfigProviderlocale. - No page reload is required;
useT()re-renders consumers.
Usage
const t = useT();
t('vulnerability.title');
t('common.minutesAgo', { n: 5 }); // {{n}} interpolation
t('chat.unknownKey', null, '中文兜底'); // explicit Chinese fallback
Rules:
- Every visible string goes through
t(...)with a Chinese fallback as the third argument. - Add new keys to
zh-CN.jsonanden-US.jsontogether;ru-RU/ar-SAmay lag and rely on the fallback chain. - Format dates with
formatDateTime/relativeTimefromsrc/lib/format.js. - Keep keys two levels deep (
<domain>.<key>) and stable across releases.