Core Services
Estimated reading time: 5 minutesThis document introduces the three core services of maplebirchFramework: EventEmitter event bus, Logger logging service, and LanguageManager internationalization service.
EventEmitter Event Bus
EventEmitter (accessible via maplebirch.tracer) provides a publish/subscribe event mechanism and is the foundation for inter-module communication within the framework. For full API reference, see EventEmitter.
API
Convenience Methods
MaplebirchCore proxies the event bus methods, which can be called directly on maplebirch:
Built-in Events
on vs once vs after
on— Executes every time the event firesonce— Executes once then auto-removesafter— Executes after alloncallbacks complete, then removes
Custom Events
Besides built-in events, you can register arbitrary custom events:
Logger Logging Service
Logger (accessible via maplebirch.logger) provides a tiered logging system.
Log Levels
Default level is INFO. Set to DEBUG to see all debug logs.
Usage
Creating Module Logs
Use createlog() to create log functions with a prefix:
IDB Configuration
Log level is read from the IndexedDB settings.DEBUG key. If DEBUG is true, log level is automatically set to DEBUG.
LanguageManager Internationalization
LanguageManager (accessible via maplebirch.lang) provides multi-language translation support. For full API reference and configuration options, see LanguageManager.
Supported Languages
EN— EnglishCN— Chinese
Translation API
t() Method
key— Translation keyspace— Iftrueand current language is EN, append space to result
Lookup order: Memory cache → Current language → EN fallback → First available translation → [key]
auto() Method
Reverse translation: Finds translation key by text content, then returns translation for current language.
Lookup order: Cache → Full search in memory translation table → IndexedDB async lookup
Translation File Format
Supports JSON and YAML formats:
Switching Language
Switching language will:
- Update
LanguageManager.language - Clear translation cache
- Trigger
:languageevent
Data Persistence
Translation data is stored in IndexedDB:
language-translations— Translation key-value pairs (indexed by mod and language)language-metadata— File hash (for incremental update detection)language-text_index— Text reverse index (forauto()lookup)
Translation files compute SHA-256 hash on import; import is skipped if file unchanged.
