Kleidos API Search

In development. It changes without notice.

Topic

Internationalization

The interface's text by name, in English, Spanish, French, German and Italian.

Every text the owner reads is asked for by its name (i18n::StringId), so no screen holds a sentence. i18n::tr() returns it in the language in force, or in English where a translation is empty. The table is in flash; in RAM there is only the language.

Language Code
English en
Español es
Français fr
Deutsch de
Italiano it

Files

file src/i18n/i18n.h
Runtime translation lookup over the compile-time string table.

Enumerations

enum class kleidos::i18n::Lang : uint8_t { Lang::EN, Lang::ES, Lang::FR, Lang::DE, Lang::IT }
Supported UI languages. More about kleidos::i18n::Lang

Functions

voidkleidos::i18n::init ()
Read the chosen language from the device's settings and cache it in RAM. Safe to call once at boot.
boolkleidos::i18n::setLang (Lang l)
Switch the active language and store the choice.
Langkleidos::i18n::getLang ()
Return the currently active language.
const char *kleidos::i18n::tr (StringId id)
Translate a generated StringId to a flash-resident UTF-8 string.
const char *kleidos::i18n::langCode (Lang l)
Return the ISO 639-1 short tag for a language.
const char *kleidos::i18n::langName (Lang l)
Return the localized display name for a language ("English", "Espa\u00f1ol", "Fran\u00e7ais", ...).
constexpr uint8_tkleidos::i18n::langCount ()
Total number of available languages (compile-time constant).
template<typename... Args>
intkleidos::i18n::trFormat (char *buf, size_t size, StringId id, Args... args)
Format an i18n string into buf using snprintf.

Enumeration Type Documentation

Lang #

enum class kleidos::i18n::Lang : uint8_t

Supported UI languages.

Enumerator
EN 

English.

ES 

Spanish.

FR 

French.

DE 

German.

IT 

Italian.

Function Documentation

getLang() #

Lang kleidos::i18n::getLang()

Return the currently active language.

Return values
ValueMeaning
Lang::ENEnglish (default before init runs).
Lang::ESSpanish.
Lang::FRFrench.
Lang::DEGerman.
Lang::ITItalian.
See also
setLang, init

init() #

void kleidos::i18n::init()

Read the chosen language from the device's settings and cache it in RAM. Safe to call once at boot.

In the host tests this is a no-op that leaves the language at Lang::EN.

See also
setLang, getLang

langCode() #

const char * kleidos::i18n::langCode(Lang l)

Return the ISO 639-1 short tag for a language.

Parameters
NameDirectionMeaning
linLanguage to query.
Returns
Two-character ISO 639-1 code such as "en" or "es". Returns "en" for any out-of-range value.

langCount() #

uint8_t kleidos::i18n::langCount()
constexpr

Total number of available languages (compile-time constant).

Returns
Number of supported languages (5: EN, ES, FR, DE, IT).

langName() #

const char * kleidos::i18n::langName(Lang l)

Return the localized display name for a language ("English", "Espa\u00f1ol", "Fran\u00e7ais", ...).

Parameters
NameDirectionMeaning
linLanguage to query.
Returns
Flash-resident localized name string. Returns "English" for any out-of-range value.

setLang() #

bool kleidos::i18n::setLang(Lang l)
nodiscard

Switch the active language and store the choice.

Parameters
NameDirectionMeaning
linTarget language. Values outside [0, ::kLangCount) are ignored silently.
Return values
ValueMeaning
trueThe language is active and stored. Always true in the host tests, which have no storage.
falsel is not a language, and nothing changed; or the interface switched language but the choice was not stored, so the next boot comes back in the old one, which a surface must not report as saved.
See also
init, getLang

tr() #

const char * kleidos::i18n::tr(StringId id)

Translate a generated StringId to a flash-resident UTF-8 string.

Falls back to the English column when id is out of range, the active language is invalid, or the localized string is empty; the caller can therefore render the result unconditionally.

Parameters
NameDirectionMeaning
idinString identifier to look up.
Returns
Flash-resident UTF-8 string; never nullptr (returns "" for unknown ids, which is still safe to render).

trFormat() #

template<typename... Args>
int kleidos::i18n::trFormat(char * buf, size_t size, StringId id, Args... args)

Format an i18n string into buf using snprintf.

The format string is resolved at runtime from the compile-time generated translation table; it is never derived from user input. GCC cannot type-check the variadic arguments against a non-literal format, so -Wformat-nonliteral is suppressed here – in this single, audited location only – which keeps the project-wide warning gate strict (any other non-literal format use still fails the build).

Template Parameters
NameMeaning
ArgsVariadic argument types forwarded to snprintf.
Parameters
NameDirectionMeaning
bufoutDestination buffer.
sizeinCapacity of buf in bytes.
idinString identifier for the format template.
argsinArguments to format into the template.
Returns
Number of bytes that would be written (snprintf semantics); negative on error.