i18n conventions (vi / en)¶
Owner: A7 (wording). A6 adds keys when building screens; A7 owns the text. Enforced by the vitest
suite in frontend/src/lib/i18n.test.ts (runs with pnpm test, see §8).
1. Where copy lives (single source of truth)¶
frontend/src/i18n/
├── vi/translation.json # Vietnamese — primary language, default for new users
└── en/translation.json # English — secondary, also the runtime fallback
- These two files are the only copy the app loads (
frontend/src/lib/i18n.ts, i18next default namespacetranslation). There are no other namespace files; do not add any without wiring them intoi18n.tsand the test. (An earlier draft split copy into 15 namespace files —common.json,errors.json, … — that were never loaded; their Vietnamese wording was merged intotranslation.jsonand the files were deleted on 2026-11-15.) - Runtime: i18next 24 + react-i18next,
keySeparator ".",fallbackLng "en",supportedLngs ["vi","en"],interpolation.escapeValue false(React escapes). Call sites uset("run.status.running"). - Locale choice: stored preference (
prefs.lang), elsenavigator.language(en*→ en, otherwise vi).<html lang>follows the active language. - Encoding: UTF-8 without BOM, NFC. Use typographic characters:
…(not...),“ ”,›for menu paths,·as a separator,—for clauses. - Error copy, laid out per contract code, is generated into
error-catalogue.md(§8).
2. Key naming¶
- Every segment is snake_case (contract-derived segments keep the contract spelling, e.g.
schema_form.error.exclusiveMaximum); group by screen or concept first, element second:run.pause_help,datasets.tab.episodes,wizard.step.params. - Leaf conventions:
title,description(page subtitle),<x>_help(helper text),empty/empty_help(empty state),<verb>(button),<verb>_confirm(confirmation question). - Never encode the language or the widget type in the key.
- Reserved suffixes
_zero _one _two _few _many _otherare plural forms (§4). - Keys are stable: renaming a key is a breaking change for A6. Change the text, not the key.
3. Keys derived from the contract¶
The UI never shows server title/detail/message strings (English, for logs). It maps machine
codes to keys. Rule for turning a contract value into a key segment: camelCase → snake_case, then
every run of characters outside [a-z0-9] → _ (datasets:write → datasets_write).
Contract source (api/openapi.yaml) |
Key |
|---|---|
ErrorCode (Problem.code) |
errors.<code> — one sentence: what happened + what to do next. src/lib/errors.ts interpolates Problem.params and retry_after_s; unknown codes fall back to errors.unknown_error |
FieldError.code |
field_errors.<code> (fallback errors.<Problem.code>) |
RunStatus / RunErrorCode / RunWarningEvent.code |
run.status.<s> / run.error.<code> / run.warning.<code> |
ValidationIssue.code |
validation.issue.<code> (interpolates episode, feature, path) |
ValidationStepId / ValidationStep.status |
validation.step.<id> / validation.step_status.<s> |
ValidationSummary.result / ValidationSeverity |
validation.result.<r> / validation.severity.<s> |
DatasetVersionStatus / DatasetSource |
dataset.status.<s> / datasets.source_kind.<s> |
ModelStatus / OnnxStatus |
model.status.<s> / model.onnx.<s> |
JobStatus |
job.status.<s> |
WorkspaceRole |
role.<r> |
OnnxSupport / PolicyType |
policy.onnx.<v> / policy.summary.<type> |
PreflightCheck.id |
preflight.check.<id>; row text preflight.code.<code> → errors.<code> → run.warning.<code> |
Notification.kind |
notifications.kind.<kind> (kind keeps its dot, e.g. run.failed) |
ResourceEstimate.source |
wizard.estimate_source.<s> |
PatScope |
tokens.scope.<snake> |
NotificationChannelKind |
account.channel_kind.<k> |
AuditEvent.outcome |
admin.outcome_value.<o> |
The test iterates these enums from api/openapi.yaml, so a contract bump that adds a value
fails CI until copy exists.
4. Interpolation and plurals¶
- Syntax
{{name}}. vi and en must use exactly the same placeholders per key (tested); keep any markup tags identical too. - Never interpolate server
detailtext. Numbers, sizes and dates are formatted withIntlfor the active locale before interpolation (vi:1.234,5;en:1,234.5). - Plurals follow each language's CLDR categories (
Intl.PluralRules, which i18next ≥ 21 uses): en hasx_one+x_other; vi has onlyx_other(Vietnamese has no plural inflection, and i18next never looks upx_onefor vi). The test derives the expected vi keys from en this way. - Do not build sentences by concatenating keys; a full sentence is one key.
5. Terminology (vi)¶
Domain terms stay in English where Vietnamese robotics users use them in practice; UI chrome is
translated. Canonical list in copy-deck.md §2 (dataset, episode, frame, feature, policy,
checkpoint, batch size, learning rate, loss, metric, log, preset, workspace, token, bundle, GPU,
ONNX, mixed precision, seed; "lượt train" for run, "episode giữ lại" for held-out,
"kiểm chứng" for verified, "kiểm tra" for validation, "tham số" for hyperparameters).
Statuses: run/job/model/upload failure = "Thất bại"; validation verdict = "Không đạt" / "Đạt".
6. Adding or changing copy¶
- A6 adds the key to both
vi/translation.jsonanden/translation.json. - The test fails when < 97 % of vi strings differ from en. Strings made only of product names and
glossary terms kept in English (
SAME_IN_VIin the test: "GPU", "Dataset", "Loss", "Version {{version}}" …) are exempt; extend that list only for genuine glossary terms. - A7 reviews wording against the copy deck. Check the 390 px screenshots (§8): Vietnamese runs ~20–30 % longer — fix overflow by tightening the copy, never by shrinking fonts.
- If the key is an error/issue/warning, regenerate
error-catalogue.md(§8).
7. Things the UI must not do¶
- Show
Problem.detail,ValidationIssue.message,RunErrorEventmessages, or log text as the primary message (only inside a collapsed technical-detail area, withlang="en"). - Hard-code user-facing strings, including
aria-label,alt,titleand toast text. - Use flags for language choice; use the language's own name (
Tiếng Việt,English).
8. Commands¶
# i18n tests (part of the normal frontend suite; Node runs in Docker)
frontend/scripts/node.sh pnpm test
# regenerate docs/ux/error-catalogue.md, and check docs links + catalogue freshness
env -u PYTHONPATH -u AMENT_PREFIX_PATH uv run --no-project --python 3.12 --with pyyaml \
python docs/ux/tools/gen_error_catalogue.py
env -u PYTHONPATH -u AMENT_PREFIX_PATH uv run --no-project --python 3.12 \
--with pytest --with pyyaml pytest -q docs/ux/tools