Orchestrates internationalization (i18n) for the desktop client. Resolves language preferences based on system settings and user configurations, translates main-process interface texts (such as tray options and pet speech/status labels), and serves localized translation bundles to renderer windows via IPC.
- Decoupled Catalog: Isolates pure, dependency-free locale definition mapping and interpolation helpers (
catalog.ts) from Electron main-process infrastructure (index.ts). This ensures translations can be resolved in standalone environments (e.g., node testing). - Graceful Fallback: Maps BCP-47 locale strings to supported locales (defaulting to English for missing files/keys) so that unresolved templates degrade cleanly to English matches instead of failing.
- Lazy Runtime Loading: Electron modules are loaded dynamically at runtime to prevent side-effects during startup or automated main-process unit testing.
- Initialization: During startup,
main.tssets up settings configuration, which callssetLocaleFromPreference()mapping"system"against OS locale fetched fromapp.getLocale(). - Translation: Callsites query
t(key, vars)which delegates lookup totranslate(), interpolating brace tokens ({name}) dynamically. - Renderer Hydration: Main-process listeners in
windows.tshandle theopenpets:get-i18nIPC hook, callinggetActiveMessages()to return the resolved dictionary to the Control Center React UI.
- Submodules: Compiles locale labels from
locales/codemap.mdand speech reaction pools fromreactions/codemap.md. - Desktop Main: Utilized by
windows.ts,tray.ts, andpet-window.tsto localize interactive UI elements. - App State: Coordinates with
app-state.tsto fetch and update the user's BCP-47 active lang choice.