mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-07-10 22:33:48 +02:00
1.3 KiB
1.3 KiB
Frontend i18n
CyberStrikeAI frontend i18n is static and lightweight. Text is organized in JSON files and applied through data-i18n attributes plus JavaScript helper functions.
Files
web/static/i18n/zh-CN.json
web/static/i18n/en-US.json
web/static/js/i18n.js
Key Principles
- Keep keys stable and semantic.
- Update Chinese and English together.
- Do not hardcode new visible text in JS when it should be localized.
- Preserve default HTML text as fallback before JS initialization.
HTML Usage
<button data-i18n="common.save">保存</button>
For attributes, follow the existing i18n.js conventions.
JavaScript Usage
Use the global translation helper where available:
const label = t('common.save');
When adding dynamic UI, make sure language switching refreshes the text or re-renders the component.
Migration Workflow
- Add or update UI text.
- Add keys to
zh-CN.json. - Add matching keys to
en-US.json. - Replace hardcoded text with
data-i18nort(). - Test both languages and browser console.
Common Pitfalls
- Missing keys only in one language.
- Dynamic text built from hardcoded fragments.
- Button labels too long in English.
- HTML fallback text diverges from JSON text.
- Adding new page text without updating language switch behavior.