name: i18n description: Use when adding or changing user-facing strings in the extension (i18n.t calls or locale JSON) under packages/danmaku-anywhere. Surfaces the extract workflow and footguns so the change does not fail the i18n CI check or ship an untranslated or inconsistent string.
i18n
Workflow for translation changes in packages/danmaku-anywhere. The package AGENTS.md "Gotchas" has the short version; this is the checklist.
The committed locale JSON (src/common/localization/locales/{en,zh}/translation.json) is the source of truth. i18next-cli extract seeds new keys and owns sorting and pruning, but it never overwrites an existing value, so changing copy means editing the JSON directly. CI runs extract --ci (pnpm i18n:check) and fails when the committed JSON does not match what extraction produces (missing key, unsorted, unused key).
Workflow
New string is added via
i18n.twith a literal key and an English default, then registered with extract:i18n.t('infoPanel.state.idle', 'No danmaku mounted')cd packages/danmaku-anywhere && pnpm i18n extractExtract adds the key to
en(from your default) andzh, sorted. Then translate the newzhentry in the JSON.Changing existing English copy means editing
en/translation.jsondirectly. Extract does not pick up a changed default on an already-extracted key, so thei18n.tdefault and the JSON drift unless you edit the JSON.Translating or editing
zhmeans editingzh/translation.jsondirectly (extract preserves existing values, it does not translate).Keys must be static string literals so the extractor finds them: no template strings, computed keys, or runtime concatenation. For per-state or per-enum strings, enumerate them as literal keys in a lookup (see
panelView.ts/entryView.ts, the "Literal i18n keys per state" pattern).Validate with
pnpm i18n:check(the sameextract --ciCI runs). Must be clean before committing.
Footguns
- Extract never overwrites existing values. A changed
enstring or azhtranslation lives in the JSON, not in thei18n.tcall; editing only the source default leaves the JSON (and the UI) unchanged. - No em dashes (U+2014) in any string, including
zh. Use a period, comma, colon, or parentheses. This is a repo-wide rule. - Terminology consistency. Match existing
zhvocabulary. Known glossary: "mount" is 装填 (已装填, 装填弹幕), not 加载 or 挂载. Grep thezhJSON for an existing term before coining a new one. i18n:checkvalidates key sets, not translation quality. It will not catch azhentry left in English or anendefault that drifted from the JSON. That is on you.