Application localization
Application localization
Read references/specification.md and references/engineering-contract.md, plus bmforge-constants for stable keys. This skill is part of the greenfield baseline, even if only English is initially published. Runtime application localization is distinct from BMForge’s Jekyll documentation translation process.
- Copy
assets/Localizer.pyunchanged to<app>/interface/Localizer.pyandassets/DText.pyinto<app>/constants/DText.py; copyassets/en.jsoninto<app>/locales/en.jsonand replace example keys with the application’s actual user-visible messages before implementing the UI. Preserve the component marker. - Use
DTextStrEnumkeys for all visible UI labels, titles, validation errors, notifications and CLI responses. The English JSON catalogue is the authoritative key list; add other UTF-8 locale JSON files only for real requested translations. Untranslated messages fall back to English; unknown keys and mismatched placeholders are errors. - For browser requests, select a language with
Localizer.select(explicit=..., accept_language=...). An explicit?lang=choice takes precedence; otherwise useAccept-Languagequality and preference order. Match a region/script to its explicit parent only, never a sibling such aszh-TWforzh-CN. Persist a manual choice only if the app’s requirements explicitly call for persistence. - Render a visible language selector when the application has multiple published locales. Retain the selected language while navigating where requested and set the HTML
langattribute from the actual selected catalogue. Use server-rendered Jinja2 autoescaping and pass the request-specificlocaleinto at()/Localizer.text()helper. No process-global language state. - For CLI commands, resolve an explicit CLI locale or environment preference, then use the same catalogue keys. Keep transport method names, JSON field keys, database codes, machine-status values, API error codes, URLs and logs stable; translate only human-facing descriptions.
- Inspect pinned
references/source/minimal-mistakes/for the browser language selector and precedence, andreferences/source/blog/for canonical tags with localized display labels. Do not copy Jekyll/Liquid code, redirects or page translation rules into a Python HTTP app. - Verify English-only startup, explicit override, browser negotiation, default fallback, a translated locale, placeholder consistency, escaping, no sibling-locale selection and no automatic machine translation. Locale selection must never mutate global app state.
No Babel, gettext, frontend framework or machine translation service is approved as a hidden dependency. Ask the user and revise the specification first if a feature requires one (e.g., grammatical plural rules or locale-aware number/date formatting).