Skip to content

API Variable Locale

github-actions[bot] edited this page Nov 30, 2026 · 5 revisions

Variable: Locale

const Locale: object;

Defined in: src/engine/localisation/Locale.ts:249

Localised text and formatting (ADR 0356 §6). Locale.t("menu.start") is the message in the current language, the key itself (with one warning) when no language of its chain has it; Locale.setLanguage("fr") switches every text.

Type Declaration

direction

Get Signature

get direction(): "ltr" | "rtl";

The current language's text direction.

Returns

"ltr" | "rtl"

epoch

Get Signature

get epoch(): number;

Rises whenever resolved text can change: a language switch, a table edit in the editor, hot reload.

Returns

number

language

Get Signature

get language(): string;

The current text language.

Returns

string

languages

Get Signature

get languages(): readonly LocaleLanguage[];

The shipped languages, in project.json's order.

Returns

readonly LocaleLanguage[]

pendingLanguage

Get Signature

get pendingLanguage(): string | null;

The language a switch in progress is loading, else null.

Returns

string | null

debug()

debug(): LocaleDebug;

The current and pending language and the keys that fell back or were missing lately (the profiler, tests).

Returns

LocaleDebug

format()

format(message, args?): string;

An ICU message written at runtime (mod data, a server's text), formatted in the current language.

Parameters

message

string

args?

Readonly<Record<string, MessageArg>>

Returns

string

formatDate()

formatDate(value, options?): string;

Parameters

value

number | Date

options?

DateTimeFormatOptions

Returns

string

formatList()

formatList(items, options?): string;

Parameters

items

readonly string[]

options?

ListFormatOptions

Returns

string

formatNumber()

formatNumber(value, options?): string;

Parameters

value

number | bigint

options?

NumberFormatOptions

Returns

string

formatRelativeTime()

formatRelativeTime(
   value, 
   unit, 
   options?
): string;

Parameters

value

number

unit

RelativeTimeFormatUnit

options?

RelativeTimeFormatOptions

Returns

string

has()

has(key): boolean;

True when a language of the current chain has a message for key.

Parameters

key

string

Returns

boolean

onChange()

onChange(fn): () => void;

Call fn after every language change; returns the unsubscribe function.

Parameters

fn

(e) => void

Returns

() => void

setLanguage()

setLanguage(code): Promise<void>;

Switch to a shipped language: its strings and fonts load first, then language, epoch and the onChange listeners change together, and the choice is remembered for the next start (when the project remembers it). An unknown or unshipped code rejects with one warning and changes nothing; a later switch supersedes this one (which then resolves without switching).

Parameters

code

string

Returns

Promise<void>

t()

t(key, args?): string;

The message of key in the current language, with args; the key itself (warned once) when it is missing.

Parameters

key

string

args?

Readonly<Record<string, MessageArg>>

Returns

string

text()

text(key, args?): LocalText;

key and args as a LocalText, which resolves in whatever language is current when it is read.

Parameters

key

string

args?

Readonly<Record<string, MessageArg>>

Returns

LocalText

Clone this wiki locally