Skip to content

@serenity-is/corelib / localText

Function: localText()

localText(key, defaultText?): string

Defined in: src/base/localtext.ts:58

Retrieves a localized string for a key, falling back gracefully.

Parameters

key

string

Localization key to look up (e.g. "Dialogs.YesButton"). If falsy, an empty string or defaultText is returned.

defaultText?

string

Optional fallback returned when the key is not found. When omitted, the key itself is returned.

Returns

string

The localized value, defaultText if provided, the key itself, or "" for nullish keys.

Example

localText("Dialogs.YesButton"); // "Yes" if registered, otherwise "Dialogs.YesButton"
localText("Missing.Key", "Fallback"); // "Fallback"