|
CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
|
#include <I18n.h>
Public Types | |
| using | LanguageChangedCallback = std::function<void()> |
| Callback invoked whenever the active translation table changes. | |
Public Member Functions | |
| bool | init () |
| Initialize and load persisted language code from NVS. | |
| bool | loadOverlay () |
| Rescan available languages and (re)load the active overlay. | |
| void | registerEnglishTable (const I18nEntry *entries, std::size_t count) |
| Append English entries to the lookup table. | |
| const char * | tr (const char *key) const |
| Look up a translation by key. | |
| const char * | overlayTr (const char *key) const |
| Overlay-only lookup with no English fallback. | |
| const std::string & | getLanguageCode () const |
| Current language code (lower-case ISO-639-1, e.g. "en", "de"). | |
| bool | setLanguageCode (const char *code) |
| Set the active language by code. | |
| const std::vector< OverlayLanguage > & | availableOverlayLanguages () const |
| Languages discovered on the plugins FAT (does not include "en"). | |
| const char * | languageName (const char *code) const |
| Display name (endonym) for a language code, for the picker. | |
| void | setOnLanguageChanged (LanguageChangedCallback cb) |
Static Public Member Functions | |
| static I18n & | instance () |
| Singleton accessor. | |
Static Public Attributes | |
| static constexpr const char * | OVERLAY_DIR = "/plugins/i18n" |
| Directory on the plugins FAT holding the per-language files. | |
| using cdc::ui::I18n::LanguageChangedCallback = std::function<void()> |
Callback invoked whenever the active translation table changes.
Triggered on:
UI code uses this to refresh any cached label pointers - menu items hold const char* into either rodata (English fallback) or the overlay's PSRAM-backed string storage, both of which are invalidated by a language change.
|
inline |
|
inline |
Current language code (lower-case ISO-639-1, e.g. "en", "de").
Definition at line 130 of file I18n.h.
Referenced by cdc::plugin_manager::PluginManager::getLockscreenItems(), and cdc::plugin_manager::Plugin::loadLangOverlay().
| bool cdc::ui::I18n::init | ( | ) |
Initialize and load persisted language code from NVS.
Definition at line 298 of file I18n.cpp.
References LOG_I, and cdc::ui::TAG.
Referenced by cdc::ui::ui_init().
|
static |
Singleton accessor.
Definition at line 287 of file I18n.cpp.
Referenced by cdc::os_ui::SystemSettingsBackup::exportSystemSettings(), cdc::plugin_manager::PluginManager::getLockscreenItems(), host_i18n_tr_core(), cdc::os_ui::SystemSettingsBackup::importSystemSettings(), initPluginSystem(), cdc::plugin_manager::Plugin::loadLangOverlay(), cdc::ui::onLanguageSelect(), cdc::ui::rebuildLanguageMenu(), cdc::mod_2fa::registerStrings(), cdc::mod_fido2::registerStrings(), cdc::mod_gpg::registerStrings(), cdc::mod_password::registerStrings(), cdc::mod_sao::registerStrings(), cdc::mod_vcard::registerStrings(), cdc::ui::tr(), and cdc::ui::ui_init().
| const char * cdc::ui::I18n::languageName | ( | const char * | code | ) | const |
Display name (endonym) for a language code, for the picker.
"en" returns the in-code English name ("English"); any other code returns the core.lang_name read from its lang_<code>.json, falling back to the code itself if unknown.
| code | Language code (e.g. "en", "de"). |
| bool cdc::ui::I18n::loadOverlay | ( | ) |
Rescan available languages and (re)load the active overlay.
Scans OVERLAY_DIR for lang_<code>.json files to populate the picker list, then parses the file for the current language into the active table. A lang_<code>.json is a flat object:
Safe to call when the current language is "en" (just rescans).
Definition at line 536 of file I18n.cpp.
References LOG_I, and cdc::ui::TAG.
Referenced by initPluginSystem().
| const char * cdc::ui::I18n::overlayTr | ( | const char * | key | ) | const |
Overlay-only lookup with no English fallback.
Returns the translation from the currently active overlay language, or nullptr if the key is missing OR the active language is "en". Useful for plugin code that wants to try a namespaced key in the central overlay before falling back to its own English manifest table.
| key | Stable string key. |
| void cdc::ui::I18n::registerEnglishTable | ( | const I18nEntry * | entries, |
| std::size_t | count ) |
Append English entries to the lookup table.
Typically called once per module from its init(). Entries are stored by-pointer (no copy); the caller must keep the array alive for the lifetime of the firmware (rodata is fine).
| entries | Pointer to the first entry. |
| count | Number of entries. |
Definition at line 307 of file I18n.cpp.
Referenced by cdc::mod_2fa::registerStrings(), cdc::mod_fido2::registerStrings(), cdc::mod_gpg::registerStrings(), cdc::mod_password::registerStrings(), cdc::mod_sao::registerStrings(), and cdc::mod_vcard::registerStrings().
| bool cdc::ui::I18n::setLanguageCode | ( | const char * | code | ) |
Set the active language by code.
If the overlay does not contain the requested language, the call still succeeds and persists the choice, but tr() will fall back to English until an overlay covering the language is loaded.
| code | Language code (e.g. "en", "de"). Empty defaults to "en". |
Definition at line 370 of file I18n.cpp.
References LOG_I, and cdc::ui::TAG.
Referenced by cdc::ui::onLanguageSelect().
|
inline |
Definition at line 172 of file I18n.h.
Referenced by cdc::ui::ui_init().
| const char * cdc::ui::I18n::tr | ( | const char * | key | ) | const |
Look up a translation by key.
| key | Stable string key. Must not be null. |
Definition at line 358 of file I18n.cpp.
Referenced by cdc::ui::tr().
|
staticconstexpr |