Log inGet started

i18n

Updated November 24, 2026

The player's language, and your world's text in it. i18n.t(key, values) reads a string from the world's catalogs (/zero/source/locales/<tag>/<namespace>.json, the format origozero.ai uses: {{ name }} parameters, _one / _other plural forms), falling back through the locale's chain to English; i18n.text(key) is the same text as a value widgets take, which follows the language on screen; i18n.formatNumber / formatBytes / formatDate / formatAgo / formatMoney write values the way the player's locale does; i18n.pseudo(true) shows every catalog string bracketed so text left in code stands out, and i18n.pseudo("unreadable") draws every catalog string at its length in glyphs nobody reads, to walk a path and see that it needs no reading; i18n.check() runs the catalog checks. i18n.pick({"en", "pt", "es"}) answers which of the languages your content has text for this player reads; i18n.preferred() is the languages their platform says they read (OS, browser or Android settings), most preferred first; i18n.onChange reports every change while they play; i18n.emulate(tags) stands a visitor's language list in to try content under it. i18n.locale() is the locale the engine's own text is in, one of i18n.offered(); i18n.choose(tag) is the player's own choice, kept for their account. The same surface in every VM. The engine picks the locale from one chain: the player's choice, then the language ZeroMind shows them, then the platform's list, then en, each matched against the offered locales (same tag, then the tag truncated, then the same language). i18n.sources() shows every link and which one decided.

require("@builtin::modules.api.engine.i18n") -- i18n (also available as global 'i18n')

The i18n namespace: 87 functions.

globals/i18n/check

i18n.check(root: string?) -> CheckResult

Run the catalog checks origozero.ai runs over every catalog of a root (<root>/locales/<tag>/*.json, en the source): files that do not parse, keys a translation has that English lacks, placeholders or markup that differ from English, plural forms the locale does not use, a translation with no current review record (<namespace>.review.json; the finding prints the record to write), and the rest of the shared checks. A translated locale's terms are held to its glossary, <root>/glossary/<tag>.json ({ "terms": [ { "source": ["coin", "coins"], "target": ["moeda*"] } ], "exceptions": [], "same_as_english": [] }); without one the check warns.

Parameters

  • root string (optional) — The folder holding locales/; the world's /zero/source by default.

Returns CheckResult — { root, errors, warnings }, one line per finding.

local r = i18n.check(); for _, e in r.errors do print(e) end

globals/i18n/choice

i18n.choice() -> string?

The locale the player chose for themselves, or nil when they chose none and the chain decides.

Returns string? — The player's choice.

globals/i18n/choose

i18n.choose(tag: string?) -> ChooseResult

Choose tag as the player's locale, kept on this device for their ZeroMind account (or for the signed-out player), so it wins the chain from now on and on every later boot. nil clears the choice and the chain decides again. A tag no offered locale matches is refused, naming the offered tags.

Parameters

  • tag string (optional) — A tag from i18n.offered(), or nil to clear the choice.

Returns ChooseResult — { ok, locale?, decidedBy?, reason?, offered? }.

local r = i18n.choose("pt-BR")
if not r.ok then log.warn(r.reason) end

globals/i18n/emulate

i18n.emulate(tags: { string }?) -> { ok: boolean, locale: string?, platform: { string }?, reason: string? }

Stand tags in for the platform's preferred languages, the way a visitor whose device or browser reads them would arrive, and negotiate again: i18n.preferred(), i18n.pick, i18n.locale() and i18n.onChange all answer as they would for that visitor. nil reads the platform's own list again. A report the platform makes afterwards (a language change, a desktop window regaining focus) replaces it. The player's own choice (i18n.choose) still comes first in the chain, so clear it with i18n.choose(nil) to see the list decide.

Parameters

  • tags { string } (optional) — BCP 47 tags, most preferred first, or nil for the platform's own list.

Returns { ok: boolean, locale: string?, platform: { string }?, reason: string? } — { ok, locale?, platform?, reason? }: the locale and list now in force.

i18n.emulate({ "pt-BR", "en" })   -- try the world as a Brazilian visitor
i18n.emulate(nil)                  -- back to this machine's own languages

globals/i18n/explain

i18n.explain(key: string, values: { [string]: any }?) -> Explanation

Where the text of key comes from for the caller: the text, the locale and file it was found in, and every file searched in order (locale by locale, layer by layer). The first thing to read when a screen shows a key, English in a translated screen, or another layer's wording.

Parameters

  • key string — <namespace>.<key>.
  • values { [string]: any } (optional) — Parameter values, as i18n.t takes them.

Returns Explanation — { key, found, text, locale?, path?, searched }.

local e = i18n.explain("hud.score"); print(e.found, e.path, e.locale)

globals/i18n/fallback

i18n.fallback() -> { string }

The chosen locale's fallback chain: the locales a string missing from its catalog is looked up in, in order.

Returns { string } — The fallback locales, en last; empty for en itself.

globals/i18n/formatAgo

i18n.formatAgo(amount: number, unit: string?, locale: string?) -> string

How long ago something happened, as the caller's text locale writes it in CLDR's narrow style: seconds before now in the largest unit that fits (45s ago, 3h ago), or with unit (second, minute, hour, day, month, year) that many of that unit (há 5 min.).

Parameters

  • amount number — Seconds before now, or a count of unit.
  • unit string (optional) — The unit amount counts, or nil for seconds in the unit that fits.
  • locale string (optional) — A locale tag, in place of the caller's text locale.

Returns string — The relative time.

globals/i18n/formatBytes

i18n.formatBytes(bytes: number, locale: string?) -> string

A size in decimal units as the caller's text locale or locale writes it: 228 B, 16.2 KB, 1.5 MB (16,2 KB in Brazilian Portuguese).

Parameters

  • bytes number — The size in bytes.
  • locale string (optional) — A locale tag, in place of the caller's text locale.

Returns string — The size.

globals/i18n/formatCompact

i18n.formatCompact(n: number, locale: string?) -> string

A count in the short compact form of the caller's text locale or locale: 1.2K, 1,2 mil. Below a thousand the number is written whole.

Parameters

  • n number — A whole number.
  • locale string (optional) — A locale tag, in place of the caller's text locale.

Returns string — The count.

globals/i18n/formatDate

i18n.formatDate(date: { year: number, month: number, day: number }, style: string?, locale: string?) -> string

A calendar date as the caller's text locale (i18n.textLocale()) or locale writes it. style is long (October 1, 2026, 1 de outubro de 2026; the default), medium (Oct 1, 2026), monthYear (October 2026) or monthDay (Oct 1). Pass the result into a message as text: i18n.t("hud.last_played", { date = i18n.formatDate(d) }).

Parameters

  • date { year: number, month: number, day: number } — { year, month, day } (the shape os.date("*t") returns).
  • style string (optional) — The date style.
  • locale string (optional) — A locale tag, in place of the caller's text locale.

Returns string — The date.

print(i18n.formatDate(os.date("*t")))

globals/i18n/formatMoney

i18n.formatMoney(amountMinor: number, currency: string, locale: string?) -> string

An amount of money as the caller's text locale or locale writes it, given in the currency's minor unit (cents for USD): $12.50, R$ 12,50.

Parameters

  • amountMinor number — The amount in minor units.
  • currency string — An ISO 4217 code such as BRL.
  • locale string (optional) — A locale tag, in place of the caller's text locale.

Returns string — The amount.

globals/i18n/formatNumber

i18n.formatNumber(n: number, locale: string?) -> string

A whole number as the caller's text locale (i18n.textLocale()) or locale writes it: 1,234,567 in English, 1.234.567 in Brazilian Portuguese.

Parameters

  • n number — A whole number.
  • locale string (optional) — A locale tag, in place of the caller's text locale.

Returns string — The number.

globals/i18n/has

i18n.has(key: string) -> boolean

Whether a catalog the caller reads holds key, in the player's locale, its fallback chain or en.

Parameters

  • key string — <namespace>.<key>.

Returns boolean — True when some catalog holds it.

globals/i18n/isText

i18n.isText(value: any?) -> boolean

Whether value is an i18n.text value.

Parameters

  • value any (optional) — Any value.

Returns boolean — True for an i18n.text value.

globals/i18n/locale

i18n.locale() -> string

The locale the engine chose for the player for its own text, a BCP 47 tag such as en or pt-BR. It is always one of i18n.offered(); en, the engine's source language, until a negotiation states another. To choose among your own content's languages, use i18n.pick.

Returns string — The chosen locale.

if i18n.locale() == "pt-BR" then label.text = "Olá" end

globals/i18n/offChange

i18n.offChange(id: number) -> boolean

Remove an i18n.onChange subscriber by its watcher id. Returns true when a live watcher carried that id (false for one already removed, or ended with the component that made it).

Parameters

  • id number — Watcher id returned by i18n.onChange.

Returns boolean

globals/i18n/offered

i18n.offered() -> { Locale }

The locales the engine offers for its own text, sorted by tag. Only an offered locale can be chosen or negotiated. Content picks among its own languages with i18n.pick.

Returns { Locale } — One { tag, name, nativeName, fallback } per offered locale.

globals/i18n/onChange

i18n.onChange(callback: (string, { string }) -> ()) -> number

Run callback each time the player's language changes: the platform's preferred list changes (the player changed their OS, browser or device language while the engine runs, or i18n.emulate stood a list in), the player chooses or clears a choice, the ZeroMind language moves, the offered locales change, the pseudo-locale is switched, or a catalog file this VM read text from is edited. Called as (locale, preferred), after every screen built from i18n.text values redrew, and after the engine renegotiated, so i18n.pick inside it answers for the new state. A change i18n.emulate or i18n.choose makes reaches this VM's subscribers before that call returns; one the platform reports reaches them within a tenth of a second. A subscription made from a component ends with that component. Returns a watcher id for i18n.offChange.

Parameters

  • callback (string, { string }) -> () — Function invoked as (locale: string, preferred: {string}).

Returns number — The watcher id.

local id = i18n.onChange(function(locale, preferred)
log.info(("locale %s, platform %s"):format(locale, table.concat(preferred, ",")))
end)

globals/i18n/pick

i18n.pick(available: { string }) -> string

Which of available, the languages your content has text for, this player reads: the tag the engine's chain picks from the player's own choice, the language ZeroMind shows them and their platform's list, matched by the same rules (same tag, the tag truncated, the same language). The first of available when none of them matches, so list your fallback first. Call it again (or from i18n.onChange) to follow a change while they play.

Parameters

  • available { string } — BCP 47 tags your content has text for, fallback first.

Returns string — One of available, exactly as written there.

local lang = i18n.pick({ "en", "pt", "es" })
label.text = ({ en = "Welcome!", pt = "Bem-vindo!", es = "¡Bienvenido!" })[lang]

globals/i18n/plural

i18n.plural(count: number, locale: string?) -> string

The CLDR plural category count takes in the caller's text locale (i18n.textLocale()), or locale: zero, one, two, few, many or other. A catalog's plural message picks its form this way; use it for a choice that is not text.

Parameters

  • count number — The number.
  • locale string (optional) — A locale tag, in place of the caller's text locale.

Returns string — The category.

globals/i18n/preferred

i18n.preferred() -> { string }

The languages the player's platform says they read, as BCP 47 tags, most preferred first: the OS language list on Linux, Windows and macOS, navigator.languages in a browser, the device (or per-app) language list on Android. Empty when the platform states none.

Returns { string } — The platform's preferred languages.

local first = i18n.preferred()[1]

globals/i18n/pseudo

i18n.pseudo(on: (boolean | "accented" | "unreadable")?) -> boolean

Show a pseudo-locale in every VM, or stop showing one (false). true (or "accented") shows qps: every catalog text renders as accented, bracketed English (⟦Ŝçöŕé⟧), padded by about a third, so text that did not come from a catalog reads as plain English and a label too narrow for a longer language overflows. "unreadable" shows qpu: every catalog text is read in the player's language and drawn at its length, spaces and punctuation kept, each letter and digit a glyph nobody reads, so a path walked under it shows whether a person who cannot read gets through it from pictures, sound and place alone; text that did not come from a catalog stays readable. Screens built from i18n.text values redraw. With no argument it changes nothing.

Parameters

  • on (boolean | "accented" | "unreadable") (optional) — true or "accented", "unreadable", or false; nil reads the current state.

Returns boolean — Whether a pseudo-locale is shown; i18n.pseudoLocale() names which.

i18n.pseudo(true)          -- every English string left on screen is one no catalog holds
i18n.pseudo("unreadable")  -- walk the screen as a person who cannot read
i18n.pseudo(false)

globals/i18n/pseudoLocale

i18n.pseudoLocale() -> ("accented" | "unreadable")?

The pseudo-locale shown, if any: "accented" (qps, set by i18n.pseudo(true)) or "unreadable" (qpu, set by i18n.pseudo("unreadable")).

Returns ("accented" | "unreadable")? — "accented", "unreadable", or nil when none is shown.

if i18n.pseudoLocale() == "unreadable" then print("walking without words") end

globals/i18n/revision

i18n.revision() -> number

A number that moves whenever a catalog text may read differently: the locale changed, the pseudo-locale was switched, or a catalog file this VM read was written. A build that caches text compares it.

Returns number — The revision.

globals/i18n/sources

i18n.sources() -> Sources

Every link of the chain the locale was chosen from: the player's choice, the zeromind language, the platform list, and which link decided (decidedBy: choice, zeromind, platform or default) with the tag it matched; and where a choice is kept (choiceKept: device, or run in an offline engine, which keeps it for that run alone).

Returns Sources — { locale, decidedBy, matched, choice?, zeromind?, platform, signedIn, choiceKept }.

globals/i18n/t

i18n.t(key: string, values: { [string]: any }?) -> string

The text of key in the player's language, from the catalogs: the world's /zero/source/locales/<tag>/<namespace>.json, then (for code of a package) the package's own locales/, then the built-in library's. A key is <namespace>.<key>: hud.score_label is score_label in hud.json. A world's (or an installed package's) catalogs are read in whichever of their languages the player reads (the chain i18n.pick runs), then en; the library's in the engine's locale, its fallback chain, then en. The first layer holding the key gives it. values fills the message's {{ name }} parameters: text as written, whole numbers grouped the way the message's language groups them, an i18n.text value as its text, a function as what it returns when the text renders; count also picks the plural form (items_one / items_other in the file). A key no catalog holds reads as the key, said once in the log. While the pseudo-locale is shown (i18n.pseudo(true)) the text is accented, bracketed English.

Parameters

  • key string — <namespace>.<key>, lowercase words joined by . and _.
  • values { [string]: any } (optional) — Parameter values by name; count picks the plural form.

Returns string — The text, rendered now.

-- /zero/source/locales/en/hud.json: { "score": "Score: {{ points }}", "lives_one": "{{ count }} life", "lives_other": "{{ count }} lives" }
label.text = i18n.t("hud.score", { points = 1250 })   -- "Score: 1,250"; "Pontos: 1.250" in pt-BR
print(i18n.t("hud.lives", { count = 3 }))             -- "3 lives"

globals/i18n/text

i18n.text(key: string, values: { [string]: any }?) -> Text

A value that reads as the text of key (see i18n.t): tostring renders it in the player's language at that moment. Pass it wherever a widget takes text (text, title, header, placeholder, tooltip, a dropdown's options; every edui widget's label), and the screen follows the player's language, the pseudo-locale and edits to the catalog without being built again (ui.refreshLiveText). A value of values may itself be an i18n.text value, or a function called each time the text renders, so a value written in the player's language follows it too: { date = function() return i18n.formatDate(d) end }.

Parameters

  • key string — <namespace>.<key>.
  • values { [string]: any } (optional) — Parameter values by name; count picks the plural form.

Returns Text — The text value.

ui.registerScreen("hud", { type = "label", props = { text = i18n.text("hud.title") } })
edui.button({ label = i18n.text("editor.save"), onClick = save })
i18n.text("hud.last_played", { date = function() return i18n.formatDate(lastPlayed) end })

globals/i18n/textLocale

i18n.textLocale() -> string

The locale the caller's text is shown in: for a world's code, the one of the world's catalog languages the player reads (pt-BR for a Brazilian player of a world with a locales/pt-BR, even while the engine shows its own text in English); for a package's code, its package's; for the engine's own code, i18n.locale(). The formatting helpers write in it by default, so a date or a count reads in the same language as the sentence around it.

Returns string — A locale tag.

local lang = i18n.textLocale()   -- "pt-BR" for a Brazilian player of a world with pt-BR catalogs

globals/i18n/upper

i18n.upper(text: string, locale: string?) -> string

text in capitals by the case rules of the caller's text locale or locale (CONEXÃO, Turkish İ). string.upper changes ASCII letters only.

Parameters

  • text string — The text.
  • locale string (optional) — A locale tag, in place of the caller's text locale.

Returns string — The text in capitals.

modules/i18n/check

check(root: string?): CheckResult

Run the catalog checks origozero.ai runs over every catalog of a root (<root>/locales/<tag>/*.json, en the source): files that do not parse, keys a translation has that English lacks, placeholders or markup that differ from English, plural forms the locale does not use, a translation with no current review record (<namespace>.review.json; the finding prints the record to write), and the rest of the shared checks. A translated locale's terms are held to its glossary, <root>/glossary/<tag>.json ({ "terms": [ { "source": ["coin", "coins"], "target": ["moeda*"] } ], "exceptions": [], "same_as_english": [] }); without one the check warns.

Parameters

  • root string? (optional) — The folder holding locales/; the world's /zero/source by default.
local r = i18n.check(); for _, e in r.errors do print(e) end

modules/i18n/choice

choice(): string?

The locale the player chose for themselves, or nil when they chose none and the chain decides.

modules/i18n/choose

choose(tag: string?): ChooseResult

Choose tag as the player's locale, kept on this device for their ZeroMind account (or for the signed-out player), so it wins the chain from now on and on every later boot. nil clears the choice and the chain decides again. A tag no offered locale matches is refused, naming the offered tags.

Parameters

  • tag string? (optional) — A tag from i18n.offered(), or nil to clear the choice.
local r = i18n.choose("pt-BR")
if not r.ok then log.warn(r.reason) end

modules/i18n/emulate

emulate(tags: { string }?): { ok: boolean, locale: string?, platform: { string }?, reason: string? }

Stand tags in for the platform's preferred languages, the way a visitor whose device or browser reads them would arrive, and negotiate again: i18n.preferred(), i18n.pick, i18n.locale() and i18n.onChange all answer as they would for that visitor. nil reads the platform's own list again. A report the platform makes afterwards (a language change, a desktop window regaining focus) replaces it. The player's own choice (i18n.choose) still comes first in the chain, so clear it with i18n.choose(nil) to see the list decide.

Parameters

  • tags { string }? (optional) — BCP 47 tags, most preferred first, or nil for the platform's own list.
i18n.emulate({ "pt-BR", "en" })   -- try the world as a Brazilian visitor
i18n.emulate(nil)                  -- back to this machine's own languages

modules/i18n/explain

explain(key: string, values: { [string]: any }?): Explanation

Where the text of key comes from for the caller: the text, the locale and file it was found in, and every file searched in order (locale by locale, layer by layer). The first thing to read when a screen shows a key, English in a translated screen, or another layer's wording.

Parameters

  • key string — <namespace>.<key>.
  • values { [string]: any }? (optional) — Parameter values, as i18n.t takes them.
local e = i18n.explain("hud.score"); print(e.found, e.path, e.locale)

modules/i18n/fallback

fallback(): { string }

The chosen locale's fallback chain: the locales a string missing from its catalog is looked up in, in order.

modules/i18n/formatAgo

formatAgo(amount: number, unit: string?, locale: string?): string

How long ago something happened, as the caller's text locale writes it in CLDR's narrow style: seconds before now in the largest unit that fits (45s ago, 3h ago), or with unit (second, minute, hour, day, month, year) that many of that unit (há 5 min.).

Parameters

  • amount number — Seconds before now, or a count of unit.
  • unit string? (optional) — The unit amount counts, or nil for seconds in the unit that fits.
  • locale string? (optional) — A locale tag, in place of the caller's text locale.

modules/i18n/formatBytes

formatBytes(bytes: number, locale: string?): string

A size in decimal units as the caller's text locale or locale writes it: 228 B, 16.2 KB, 1.5 MB (16,2 KB in Brazilian Portuguese).

Parameters

  • bytes number — The size in bytes.
  • locale string? (optional) — A locale tag, in place of the caller's text locale.

modules/i18n/formatCompact

formatCompact(n: number, locale: string?): string

A count in the short compact form of the caller's text locale or locale: 1.2K, 1,2 mil. Below a thousand the number is written whole.

Parameters

  • n number — A whole number.
  • locale string? (optional) — A locale tag, in place of the caller's text locale.

modules/i18n/formatDate

formatDate(date: { year: number, month: number, day: number }, style: string?, locale: string?): string

A calendar date as the caller's text locale (i18n.textLocale()) or locale writes it. style is long (October 1, 2026, 1 de outubro de 2026; the default), medium (Oct 1, 2026), monthYear (October 2026) or monthDay (Oct 1). Pass the result into a message as text: i18n.t("hud.last_played", { date = i18n.formatDate(d) }).

Parameters

  • date { year: number, month: number, day: number } — { year, month, day } (the shape os.date("*t") returns).
  • style string? (optional) — The date style.
  • locale string? (optional) — A locale tag, in place of the caller's text locale.
print(i18n.formatDate(os.date("*t")))

modules/i18n/formatMoney

formatMoney(amountMinor: number, currency: string, locale: string?): string

An amount of money as the caller's text locale or locale writes it, given in the currency's minor unit (cents for USD): $12.50, R$ 12,50.

Parameters

  • amountMinor number — The amount in minor units.
  • currency string — An ISO 4217 code such as BRL.
  • locale string? (optional) — A locale tag, in place of the caller's text locale.

modules/i18n/formatNumber

formatNumber(n: number, locale: string?): string

A whole number as the caller's text locale (i18n.textLocale()) or locale writes it: 1,234,567 in English, 1.234.567 in Brazilian Portuguese.

Parameters

  • n number — A whole number.
  • locale string? (optional) — A locale tag, in place of the caller's text locale.

modules/i18n/has

has(key: string): boolean

Whether a catalog the caller reads holds key, in the player's locale, its fallback chain or en.

Parameters

  • key string — <namespace>.<key>.

modules/i18n/isText

isText(value: any): boolean

Whether value is an i18n.text value.

Parameters

  • value any (optional) — Any value.

modules/i18n/locale

locale(): string

The locale the engine chose for the player for its own text, a BCP 47 tag such as en or pt-BR. It is always one of i18n.offered(); en, the engine's source language, until a negotiation states another. To choose among your own content's languages, use i18n.pick.

if i18n.locale() == "pt-BR" then label.text = "Olá" end

modules/i18n/offChange

offChange(id: number): boolean

Remove an i18n.onChange subscriber by its watcher id. Returns true when a live watcher carried that id (false for one already removed, or ended with the component that made it).

Parameters

  • id number — Watcher id returned by i18n.onChange.

modules/i18n/offered

offered(): { Locale }

The locales the engine offers for its own text, sorted by tag. Only an offered locale can be chosen or negotiated. Content picks among its own languages with i18n.pick.

modules/i18n/onChange

onChange(callback: (string, { string }) -> ()): number

Run callback each time the player's language changes: the platform's preferred list changes (the player changed their OS, browser or device language while the engine runs, or i18n.emulate stood a list in), the player chooses or clears a choice, the ZeroMind language moves, the offered locales change, the pseudo-locale is switched, or a catalog file this VM read text from is edited. Called as (locale, preferred), after every screen built from i18n.text values redrew, and after the engine renegotiated, so i18n.pick inside it answers for the new state. A change i18n.emulate or i18n.choose makes reaches this VM's subscribers before that call returns; one the platform reports reaches them within a tenth of a second. A subscription made from a component ends with that component. Returns a watcher id for i18n.offChange.

Parameters

  • callback (string, { string }) -> () — Function invoked as (locale: string, preferred: {string}).
local id = i18n.onChange(function(locale, preferred)
log.info(("locale %s, platform %s"):format(locale, table.concat(preferred, ",")))
end)

modules/i18n/pick

pick(available: { string }): string

Which of available, the languages your content has text for, this player reads: the tag the engine's chain picks from the player's own choice, the language ZeroMind shows them and their platform's list, matched by the same rules (same tag, the tag truncated, the same language). The first of available when none of them matches, so list your fallback first. Call it again (or from i18n.onChange) to follow a change while they play.

Parameters

  • available { string } — BCP 47 tags your content has text for, fallback first.
local lang = i18n.pick({ "en", "pt", "es" })
label.text = ({ en = "Welcome!", pt = "Bem-vindo!", es = "¡Bienvenido!" })[lang]

modules/i18n/plural

plural(count: number, locale: string?): string

The CLDR plural category count takes in the caller's text locale (i18n.textLocale()), or locale: zero, one, two, few, many or other. A catalog's plural message picks its form this way; use it for a choice that is not text.

Parameters

  • count number — The number.
  • locale string? (optional) — A locale tag, in place of the caller's text locale.

modules/i18n/preferred

preferred(): { string }

The languages the player's platform says they read, as BCP 47 tags, most preferred first: the OS language list on Linux, Windows and macOS, navigator.languages in a browser, the device (or per-app) language list on Android. Empty when the platform states none.

local first = i18n.preferred()[1]

modules/i18n/pseudo

pseudo(on: (boolean | "accented" | "unreadable")?): boolean

Show a pseudo-locale in every VM, or stop showing one (false). true (or "accented") shows qps: every catalog text renders as accented, bracketed English (⟦Ŝçöŕé⟧), padded by about a third, so text that did not come from a catalog reads as plain English and a label too narrow for a longer language overflows. "unreadable" shows qpu: every catalog text is read in the player's language and drawn at its length, spaces and punctuation kept, each letter and digit a glyph nobody reads, so a path walked under it shows whether a person who cannot read gets through it from pictures, sound and place alone; text that did not come from a catalog stays readable. Screens built from i18n.text values redraw. With no argument it changes nothing.

Parameters

  • on (boolean | "accented" | "unreadable")? (optional) — true or "accented", "unreadable", or false; nil reads the current state.
i18n.pseudo(true)          -- every English string left on screen is one no catalog holds
i18n.pseudo("unreadable")  -- walk the screen as a person who cannot read
i18n.pseudo(false)

modules/i18n/pseudoLocale

pseudoLocale(): ("accented" | "unreadable")?

The pseudo-locale shown, if any: "accented" (qps, set by i18n.pseudo(true)) or "unreadable" (qpu, set by i18n.pseudo("unreadable")).

if i18n.pseudoLocale() == "unreadable" then print("walking without words") end

modules/i18n/revision

revision(): number

A number that moves whenever a catalog text may read differently: the locale changed, the pseudo-locale was switched, or a catalog file this VM read was written. A build that caches text compares it.

modules/i18n/sources

sources(): Sources

Every link of the chain the locale was chosen from: the player's choice, the zeromind language, the platform list, and which link decided (decidedBy: choice, zeromind, platform or default) with the tag it matched; and where a choice is kept (choiceKept: device, or run in an offline engine, which keeps it for that run alone).

modules/i18n/t

t(key: string, values: { [string]: any }?): string

The text of key in the player's language, from the catalogs: the world's /zero/source/locales/<tag>/<namespace>.json, then (for code of a package) the package's own locales/, then the built-in library's. A key is <namespace>.<key>: hud.score_label is score_label in hud.json. A world's (or an installed package's) catalogs are read in whichever of their languages the player reads (the chain i18n.pick runs), then en; the library's in the engine's locale, its fallback chain, then en. The first layer holding the key gives it. values fills the message's {{ name }} parameters: text as written, whole numbers grouped the way the message's language groups them, an i18n.text value as its text, a function as what it returns when the text renders; count also picks the plural form (items_one / items_other in the file). A key no catalog holds reads as the key, said once in the log. While the pseudo-locale is shown (i18n.pseudo(true)) the text is accented, bracketed English.

Parameters

  • key string — <namespace>.<key>, lowercase words joined by . and _.
  • values { [string]: any }? (optional) — Parameter values by name; count picks the plural form.
-- /zero/source/locales/en/hud.json: { "score": "Score: {{ points }}", "lives_one": "{{ count }} life", "lives_other": "{{ count }} lives" }
label.text = i18n.t("hud.score", { points = 1250 })   -- "Score: 1,250"; "Pontos: 1.250" in pt-BR
print(i18n.t("hud.lives", { count = 3 }))             -- "3 lives"

modules/i18n/text

text(key: string, values: { [string]: any }?): Text

A value that reads as the text of key (see i18n.t): tostring renders it in the player's language at that moment. Pass it wherever a widget takes text (text, title, header, placeholder, tooltip, a dropdown's options; every edui widget's label), and the screen follows the player's language, the pseudo-locale and edits to the catalog without being built again (ui.refreshLiveText). A value of values may itself be an i18n.text value, or a function called each time the text renders, so a value written in the player's language follows it too: { date = function() return i18n.formatDate(d) end }.

Parameters

  • key string — <namespace>.<key>.
  • values { [string]: any }? (optional) — Parameter values by name; count picks the plural form.
ui.registerScreen("hud", { type = "label", props = { text = i18n.text("hud.title") } })
edui.button({ label = i18n.text("editor.save"), onClick = save })
i18n.text("hud.last_played", { date = function() return i18n.formatDate(lastPlayed) end })

modules/i18n/textLocale

textLocale(): string

The locale the caller's text is shown in: for a world's code, the one of the world's catalog languages the player reads (pt-BR for a Brazilian player of a world with a locales/pt-BR, even while the engine shows its own text in English); for a package's code, its package's; for the engine's own code, i18n.locale(). The formatting helpers write in it by default, so a date or a count reads in the same language as the sentence around it.

local lang = i18n.textLocale()   -- "pt-BR" for a Brazilian player of a world with pt-BR catalogs

modules/i18n/upper

upper(text: string, locale: string?): string

text in capitals by the case rules of the caller's text locale or locale (CONEXÃO, Turkish İ). string.upper changes ASCII letters only.

Parameters

  • text string — The text.
  • locale string? (optional) — A locale tag, in place of the caller's text locale.

typed/builtin//modules/api/engine/i18n/i18n/check

i18n.check(root: string?) -> CheckResult

Run the catalog checks origozero.ai runs over every catalog of a root (<root>/locales/<tag>/*.json, en the source): files that do not parse, keys a translation has that English lacks, placeholders or markup that differ from English, plural forms the locale does not use, a translation with no current review record (<namespace>.review.json; the finding prints the record to write), and the rest of the shared checks. A translated locale's terms are held to its glossary, <root>/glossary/<tag>.json ({ "terms": [ { "source": ["coin", "coins"], "target": ["moeda*"] } ], "exceptions": [], "same_as_english": [] }); without one the check warns.

Parameters

  • root string (optional) — The folder holding locales/; the world's /zero/source by default.

Returns CheckResult — { root, errors, warnings }, one line per finding.

local r = i18n.check(); for _, e in r.errors do print(e) end

typed/builtin//modules/api/engine/i18n/i18n/choice

i18n.choice() -> string?

The locale the player chose for themselves, or nil when they chose none and the chain decides.

Returns string? — The player's choice.

typed/builtin//modules/api/engine/i18n/i18n/choose

i18n.choose(tag: string?) -> ChooseResult

Choose tag as the player's locale, kept on this device for their ZeroMind account (or for the signed-out player), so it wins the chain from now on and on every later boot. nil clears the choice and the chain decides again. A tag no offered locale matches is refused, naming the offered tags.

Parameters

  • tag string (optional) — A tag from i18n.offered(), or nil to clear the choice.

Returns ChooseResult — { ok, locale?, decidedBy?, reason?, offered? }.

local r = i18n.choose("pt-BR")
if not r.ok then log.warn(r.reason) end

typed/builtin//modules/api/engine/i18n/i18n/emulate

i18n.emulate(tags: { string }?) -> { ok: boolean, locale: string?, platform: { string }?, reason: string? }

Stand tags in for the platform's preferred languages, the way a visitor whose device or browser reads them would arrive, and negotiate again: i18n.preferred(), i18n.pick, i18n.locale() and i18n.onChange all answer as they would for that visitor. nil reads the platform's own list again. A report the platform makes afterwards (a language change, a desktop window regaining focus) replaces it. The player's own choice (i18n.choose) still comes first in the chain, so clear it with i18n.choose(nil) to see the list decide.

Parameters

  • tags { string } (optional) — BCP 47 tags, most preferred first, or nil for the platform's own list.

Returns { ok: boolean, locale: string?, platform: { string }?, reason: string? } — { ok, locale?, platform?, reason? }: the locale and list now in force.

i18n.emulate({ "pt-BR", "en" })   -- try the world as a Brazilian visitor
i18n.emulate(nil)                  -- back to this machine's own languages

typed/builtin//modules/api/engine/i18n/i18n/explain

i18n.explain(key: string, values: { [string]: any }?) -> Explanation

Where the text of key comes from for the caller: the text, the locale and file it was found in, and every file searched in order (locale by locale, layer by layer). The first thing to read when a screen shows a key, English in a translated screen, or another layer's wording.

Parameters

  • key string — <namespace>.<key>.
  • values { [string]: any } (optional) — Parameter values, as i18n.t takes them.

Returns Explanation — { key, found, text, locale?, path?, searched }.

local e = i18n.explain("hud.score"); print(e.found, e.path, e.locale)

typed/builtin//modules/api/engine/i18n/i18n/fallback

i18n.fallback() -> { string }

The chosen locale's fallback chain: the locales a string missing from its catalog is looked up in, in order.

Returns { string } — The fallback locales, en last; empty for en itself.

typed/builtin//modules/api/engine/i18n/i18n/formatAgo

i18n.formatAgo(amount: number, unit: string?, locale: string?) -> string

How long ago something happened, as the caller's text locale writes it in CLDR's narrow style: seconds before now in the largest unit that fits (45s ago, 3h ago), or with unit (second, minute, hour, day, month, year) that many of that unit (há 5 min.).

Parameters

  • amount number — Seconds before now, or a count of unit.
  • unit string (optional) — The unit amount counts, or nil for seconds in the unit that fits.
  • locale string (optional) — A locale tag, in place of the caller's text locale.

Returns string — The relative time.

typed/builtin//modules/api/engine/i18n/i18n/formatBytes

i18n.formatBytes(bytes: number, locale: string?) -> string

A size in decimal units as the caller's text locale or locale writes it: 228 B, 16.2 KB, 1.5 MB (16,2 KB in Brazilian Portuguese).

Parameters

  • bytes number — The size in bytes.
  • locale string (optional) — A locale tag, in place of the caller's text locale.

Returns string — The size.

typed/builtin//modules/api/engine/i18n/i18n/formatCompact

i18n.formatCompact(n: number, locale: string?) -> string

A count in the short compact form of the caller's text locale or locale: 1.2K, 1,2 mil. Below a thousand the number is written whole.

Parameters

  • n number — A whole number.
  • locale string (optional) — A locale tag, in place of the caller's text locale.

Returns string — The count.

typed/builtin//modules/api/engine/i18n/i18n/formatDate

i18n.formatDate(date: { year: number, month: number, day: number }, style: string?, locale: string?) -> string

A calendar date as the caller's text locale (i18n.textLocale()) or locale writes it. style is long (October 1, 2026, 1 de outubro de 2026; the default), medium (Oct 1, 2026), monthYear (October 2026) or monthDay (Oct 1). Pass the result into a message as text: i18n.t("hud.last_played", { date = i18n.formatDate(d) }).

Parameters

  • date { year: number, month: number, day: number } — { year, month, day } (the shape os.date("*t") returns).
  • style string (optional) — The date style.
  • locale string (optional) — A locale tag, in place of the caller's text locale.

Returns string — The date.

print(i18n.formatDate(os.date("*t")))

typed/builtin//modules/api/engine/i18n/i18n/formatMoney

i18n.formatMoney(amountMinor: number, currency: string, locale: string?) -> string

An amount of money as the caller's text locale or locale writes it, given in the currency's minor unit (cents for USD): $12.50, R$ 12,50.

Parameters

  • amountMinor number — The amount in minor units.
  • currency string — An ISO 4217 code such as BRL.
  • locale string (optional) — A locale tag, in place of the caller's text locale.

Returns string — The amount.

typed/builtin//modules/api/engine/i18n/i18n/formatNumber

i18n.formatNumber(n: number, locale: string?) -> string

A whole number as the caller's text locale (i18n.textLocale()) or locale writes it: 1,234,567 in English, 1.234.567 in Brazilian Portuguese.

Parameters

  • n number — A whole number.
  • locale string (optional) — A locale tag, in place of the caller's text locale.

Returns string — The number.

typed/builtin//modules/api/engine/i18n/i18n/has

i18n.has(key: string) -> boolean

Whether a catalog the caller reads holds key, in the player's locale, its fallback chain or en.

Parameters

  • key string — <namespace>.<key>.

Returns boolean — True when some catalog holds it.

typed/builtin//modules/api/engine/i18n/i18n/isText

i18n.isText(value: any?) -> boolean

Whether value is an i18n.text value.

Parameters

  • value any (optional) — Any value.

Returns boolean — True for an i18n.text value.

typed/builtin//modules/api/engine/i18n/i18n/locale

i18n.locale() -> string

The locale the engine chose for the player for its own text, a BCP 47 tag such as en or pt-BR. It is always one of i18n.offered(); en, the engine's source language, until a negotiation states another. To choose among your own content's languages, use i18n.pick.

Returns string — The chosen locale.

if i18n.locale() == "pt-BR" then label.text = "Olá" end

typed/builtin//modules/api/engine/i18n/i18n/offChange

i18n.offChange(id: number) -> boolean

Remove an i18n.onChange subscriber by its watcher id. Returns true when a live watcher carried that id (false for one already removed, or ended with the component that made it).

Parameters

  • id number — Watcher id returned by i18n.onChange.

Returns boolean

typed/builtin//modules/api/engine/i18n/i18n/offered

i18n.offered() -> { Locale }

The locales the engine offers for its own text, sorted by tag. Only an offered locale can be chosen or negotiated. Content picks among its own languages with i18n.pick.

Returns { Locale } — One { tag, name, nativeName, fallback } per offered locale.

typed/builtin//modules/api/engine/i18n/i18n/onChange

i18n.onChange(callback: (string, { string }) -> ()) -> number

Run callback each time the player's language changes: the platform's preferred list changes (the player changed their OS, browser or device language while the engine runs, or i18n.emulate stood a list in), the player chooses or clears a choice, the ZeroMind language moves, the offered locales change, the pseudo-locale is switched, or a catalog file this VM read text from is edited. Called as (locale, preferred), after every screen built from i18n.text values redrew, and after the engine renegotiated, so i18n.pick inside it answers for the new state. A change i18n.emulate or i18n.choose makes reaches this VM's subscribers before that call returns; one the platform reports reaches them within a tenth of a second. A subscription made from a component ends with that component. Returns a watcher id for i18n.offChange.

Parameters

  • callback (string, { string }) -> () — Function invoked as (locale: string, preferred: {string}).

Returns number — The watcher id.

local id = i18n.onChange(function(locale, preferred)
log.info(("locale %s, platform %s"):format(locale, table.concat(preferred, ",")))
end)

typed/builtin//modules/api/engine/i18n/i18n/pick

i18n.pick(available: { string }) -> string

Which of available, the languages your content has text for, this player reads: the tag the engine's chain picks from the player's own choice, the language ZeroMind shows them and their platform's list, matched by the same rules (same tag, the tag truncated, the same language). The first of available when none of them matches, so list your fallback first. Call it again (or from i18n.onChange) to follow a change while they play.

Parameters

  • available { string } — BCP 47 tags your content has text for, fallback first.

Returns string — One of available, exactly as written there.

local lang = i18n.pick({ "en", "pt", "es" })
label.text = ({ en = "Welcome!", pt = "Bem-vindo!", es = "¡Bienvenido!" })[lang]

typed/builtin//modules/api/engine/i18n/i18n/plural

i18n.plural(count: number, locale: string?) -> string

The CLDR plural category count takes in the caller's text locale (i18n.textLocale()), or locale: zero, one, two, few, many or other. A catalog's plural message picks its form this way; use it for a choice that is not text.

Parameters

  • count number — The number.
  • locale string (optional) — A locale tag, in place of the caller's text locale.

Returns string — The category.

typed/builtin//modules/api/engine/i18n/i18n/preferred

i18n.preferred() -> { string }

The languages the player's platform says they read, as BCP 47 tags, most preferred first: the OS language list on Linux, Windows and macOS, navigator.languages in a browser, the device (or per-app) language list on Android. Empty when the platform states none.

Returns { string } — The platform's preferred languages.

local first = i18n.preferred()[1]

typed/builtin//modules/api/engine/i18n/i18n/pseudo

i18n.pseudo(on: (boolean | "accented" | "unreadable")?) -> boolean

Show a pseudo-locale in every VM, or stop showing one (false). true (or "accented") shows qps: every catalog text renders as accented, bracketed English (⟦Ŝçöŕé⟧), padded by about a third, so text that did not come from a catalog reads as plain English and a label too narrow for a longer language overflows. "unreadable" shows qpu: every catalog text is read in the player's language and drawn at its length, spaces and punctuation kept, each letter and digit a glyph nobody reads, so a path walked under it shows whether a person who cannot read gets through it from pictures, sound and place alone; text that did not come from a catalog stays readable. Screens built from i18n.text values redraw. With no argument it changes nothing.

Parameters

  • on (boolean | "accented" | "unreadable") (optional) — true or "accented", "unreadable", or false; nil reads the current state.

Returns boolean — Whether a pseudo-locale is shown; i18n.pseudoLocale() names which.

i18n.pseudo(true)          -- every English string left on screen is one no catalog holds
i18n.pseudo("unreadable")  -- walk the screen as a person who cannot read
i18n.pseudo(false)

typed/builtin//modules/api/engine/i18n/i18n/pseudoLocale

i18n.pseudoLocale() -> ("accented" | "unreadable")?

The pseudo-locale shown, if any: "accented" (qps, set by i18n.pseudo(true)) or "unreadable" (qpu, set by i18n.pseudo("unreadable")).

Returns ("accented" | "unreadable")? — "accented", "unreadable", or nil when none is shown.

if i18n.pseudoLocale() == "unreadable" then print("walking without words") end

typed/builtin//modules/api/engine/i18n/i18n/revision

i18n.revision() -> number

A number that moves whenever a catalog text may read differently: the locale changed, the pseudo-locale was switched, or a catalog file this VM read was written. A build that caches text compares it.

Returns number — The revision.

typed/builtin//modules/api/engine/i18n/i18n/sources

i18n.sources() -> Sources

Every link of the chain the locale was chosen from: the player's choice, the zeromind language, the platform list, and which link decided (decidedBy: choice, zeromind, platform or default) with the tag it matched; and where a choice is kept (choiceKept: device, or run in an offline engine, which keeps it for that run alone).

Returns Sources — { locale, decidedBy, matched, choice?, zeromind?, platform, signedIn, choiceKept }.

typed/builtin//modules/api/engine/i18n/i18n/t

i18n.t(key: string, values: { [string]: any }?) -> string

The text of key in the player's language, from the catalogs: the world's /zero/source/locales/<tag>/<namespace>.json, then (for code of a package) the package's own locales/, then the built-in library's. A key is <namespace>.<key>: hud.score_label is score_label in hud.json. A world's (or an installed package's) catalogs are read in whichever of their languages the player reads (the chain i18n.pick runs), then en; the library's in the engine's locale, its fallback chain, then en. The first layer holding the key gives it. values fills the message's {{ name }} parameters: text as written, whole numbers grouped the way the message's language groups them, an i18n.text value as its text, a function as what it returns when the text renders; count also picks the plural form (items_one / items_other in the file). A key no catalog holds reads as the key, said once in the log. While the pseudo-locale is shown (i18n.pseudo(true)) the text is accented, bracketed English.

Parameters

  • key string — <namespace>.<key>, lowercase words joined by . and _.
  • values { [string]: any } (optional) — Parameter values by name; count picks the plural form.

Returns string — The text, rendered now.

-- /zero/source/locales/en/hud.json: { "score": "Score: {{ points }}", "lives_one": "{{ count }} life", "lives_other": "{{ count }} lives" }
label.text = i18n.t("hud.score", { points = 1250 })   -- "Score: 1,250"; "Pontos: 1.250" in pt-BR
print(i18n.t("hud.lives", { count = 3 }))             -- "3 lives"

typed/builtin//modules/api/engine/i18n/i18n/text

i18n.text(key: string, values: { [string]: any }?) -> Text

A value that reads as the text of key (see i18n.t): tostring renders it in the player's language at that moment. Pass it wherever a widget takes text (text, title, header, placeholder, tooltip, a dropdown's options; every edui widget's label), and the screen follows the player's language, the pseudo-locale and edits to the catalog without being built again (ui.refreshLiveText). A value of values may itself be an i18n.text value, or a function called each time the text renders, so a value written in the player's language follows it too: { date = function() return i18n.formatDate(d) end }.

Parameters

  • key string — <namespace>.<key>.
  • values { [string]: any } (optional) — Parameter values by name; count picks the plural form.

Returns Text — The text value.

ui.registerScreen("hud", { type = "label", props = { text = i18n.text("hud.title") } })
edui.button({ label = i18n.text("editor.save"), onClick = save })
i18n.text("hud.last_played", { date = function() return i18n.formatDate(lastPlayed) end })

typed/builtin//modules/api/engine/i18n/i18n/textLocale

i18n.textLocale() -> string

The locale the caller's text is shown in: for a world's code, the one of the world's catalog languages the player reads (pt-BR for a Brazilian player of a world with a locales/pt-BR, even while the engine shows its own text in English); for a package's code, its package's; for the engine's own code, i18n.locale(). The formatting helpers write in it by default, so a date or a count reads in the same language as the sentence around it.

Returns string — A locale tag.

local lang = i18n.textLocale()   -- "pt-BR" for a Brazilian player of a world with pt-BR catalogs

typed/builtin//modules/api/engine/i18n/i18n/upper

i18n.upper(text: string, locale: string?) -> string

text in capitals by the case rules of the caller's text locale or locale (CONEXÃO, Turkish İ). string.upper changes ASCII letters only.

Parameters

  • text string — The text.
  • locale string (optional) — A locale tag, in place of the caller's text locale.

Returns string — The text in capitals.

  • api
  • reference