Internationalization (i18n)
Internationalization API
The i18n module turns every user-visible string into a StringID, and a per-language table supplies the active-language text. Apps get translated strings with TR(STR_X) and can switch the active language at runtime.
Access
#include <pocketmage.h>
I18n is a static-only class; there is no instance. The Lang and StringID enums are generated from the catalogs in pocketmage_i18n/ into pocketmage_i18n_gen.h (that header drives the tables, not the other way round). StringID ids look like STR_INVALID, STR_TODAY, STR_SETTINGS; Lang has one member per shipped language.
Lookup
static const char* get(StringID id);
#define TR(id) I18n::get(id)
TR(STR_X) returns the active language’s text for the id, pointing into the table storage (do not free it). The canonical reference strings live in the English table.
Indexed blocks make whole tables selectable:
static const char* monthName(int month); // 1..12, else the ERR entry
static const char* dayName(int idx); // 0..6, Sunday-first
static const char* appName(int idx); // home grid label, 0..10
static const char* kbAppName(int idx); // app-switcher badge, 0..11
Language switching
static void setLanguage(Lang lang);
static bool setLanguageByCode(const char* code);
static Lang language();
static int languageCount();
static const char* code(); // active two-letter code ("en")
static const char* code(int idx);
static const char* nativeName(); // active native name ("Français")
static const char* nativeName(int idx);
setLanguageswitches the active table; out-of-range values clamp to English.setLanguageByCode("fr")switches by two-letter code and returns false (leaving the current language untouched) for an unknown code.languageCount()is the number of shipped languages for building a language picker;code(idx)/nativeName(idx)back its rows in catalog order.
The OS persists the choice to NVS (configuration); on setup the app applies it, and the font table is re-applied because displayed text may now use different accents (font).
Command aliases
static String normalizeCommand(const String& raw);
The command parser’s front door. It:
- Folds the input (UTF-8 diacritics to ASCII, lowercased). Curly quotes, dashes, and truncated sequences are dropped.
- Resolves the first word (or the whole line for multi-word aliases such as the easter eggs) against the alias catalog to the canonical English verb.
- Preserves any argument text (filenames, etc.) byte-for-byte.
So both "réglages" and "reglages" resolve to settings, while file arguments keep their exact bytes. Unmatched input returns unchanged.
Adding a language
The string tables are generated (see pocketmage_i18n/README): add a .po catalog and re-run the generator, and the Lang enum, StringID-ordered table, and string block for appName/kbAppName/months/days all follow. Fallback rules: a missing (empty msgstr) id in a non-English table falls back to the English string at generation time, so every StringID always resolves to a non-empty string. An out-of-range language index clamps to English; an out-of-range StringID returns the empty string.
C ABI (pm_*)
External ELF apps call these C wrappers rather than the C++ class above; they are generated from it by gen_app_api.py and declared in pm_sdk_app.h (pulled in via pm_app_api.h). See the function index and the projection model for the general rules.
void pm_i18n_set_language(int a0);
bool pm_i18n_set_language_by_code(const char* a0);
int pm_i18n_language();
int pm_i18n_language_count();
const char* pm_i18n_code();
const char* pm_i18n_code_at(int a0);
const char* pm_i18n_native_name();
const char* pm_i18n_native_name_at(int a0);
const char* pm_i18n_get(int a0);
const char* pm_i18n_month_name(int a0);
const char* pm_i18n_day_name(int a0);
const char* pm_i18n_app_name(int a0);
const char* pm_i18n_kb_app_name(int a0);
const char* pm_i18n_normalize_command(const char* a0);
These project the static I18n methods. Every const char* return points into the rotating string pool; copy it before the next SDK call if it must outlive four further string-returning calls.
pm_i18n_set_language(a0)issetLanguage(lang);a0is apm_langvalue as int, out-of-range clamping to English.pm_i18n_set_language_by_code(a0)issetLanguageByCode(code);a0is a two-letter code. Returns false and leaves the language unchanged for an unknown code.pm_i18n_language()islanguage(). Returns the activepm_langas int.pm_i18n_language_count()islanguageCount().pm_i18n_code()/pm_i18n_code_at(a0)arecode()/code(idx);a0is the catalog index.pm_i18n_native_name()/pm_i18n_native_name_at(a0)arenativeName()/nativeName(idx).pm_i18n_get(a0)isget(id);a0is aStringIDvalue as int (for exampleSTR_INVALID). This is theTR()lookup.pm_i18n_month_name(a0)ismonthName(month);a0is 1…12.pm_i18n_day_name(a0)isdayName(idx);a0is 0…6, Sunday-first.pm_i18n_app_name(a0)isappName(idx);a0is the home-grid index 0…10.pm_i18n_kb_app_name(a0)iskbAppName(idx);a0is the app-switcher index 0…11.pm_i18n_normalize_command(a0)isnormalizeCommand(raw);a0is the raw command line. Returns the canonical English verb with argument bytes preserved.