Localize.Lua.API (Localize Lua v1.0.0)

Copy Markdown View Source

The Lua.API installed into a Luerl VM under the localize scope.

Every function is callable from Lua as localize.<name>(...) once the module is installed with Localize.Lua.install/1. The functions are thin, total wrappers over Localize: each accepts primitive Lua values plus an optional options table, and always returns a string. On any error — an unknown locale, an unparseable date, a malformed options table — the function falls back to a safe rendering of its input rather than raising, so a template can never crash the host render path.

See Localize.Lua for the installation entry point and worked examples.

Summary

Functions

Formats a number as a currency amount (localize.currency(1234.56, "EUR", {locale = "de"})).

Formats an ISO 8601 date string (localize.date("2025-07-10", {locale = "de", format = "long"})).

Formats an ISO 8601 datetime string (localize.datetime("2025-07-10T14:30:00Z", {locale = "fr"})).

Localized display name of a language (localize.language_name("de", {locale = "en"})"German").

Joins a Lua array into a locale-aware list (localize.list({"a", "b", "c"})"a, b, and c").

Formats a MessageFormat 2 message with bindings, including CLDR plurals.

Formats a number for the active locale (localize.number(1234.5, {locale = "de"})).

Formats a fractional number as a percentage (localize.percent(0.56)"56%").

Formats a relative time (localize.relative(-3, "day")"3 days ago").

Localized display name of a territory (localize.territory_name("AU", {locale = "fr"})).

Formats an ISO 8601 time string (localize.time("14:30:00", {locale = "en"})).

Formats a measurement (localize.unit(42, "kilometer", {format = "short"})"42 km").

Functions

currency(value, currency_code, options \\ [], state)

Formats a number as a currency amount (localize.currency(1234.56, "EUR", {locale = "de"})).

date(iso_string, options \\ [], state)

Formats an ISO 8601 date string (localize.date("2025-07-10", {locale = "de", format = "long"})).

datetime(iso_string, options \\ [], state)

Formats an ISO 8601 datetime string (localize.datetime("2025-07-10T14:30:00Z", {locale = "fr"})).

language_name(code, options \\ [], state)

Localized display name of a language (localize.language_name("de", {locale = "en"})"German").

list(items, options \\ [], state)

Joins a Lua array into a locale-aware list (localize.list({"a", "b", "c"})"a, b, and c").

message(text, bindings \\ [], state)

Formats a MessageFormat 2 message with bindings, including CLDR plurals.

localize.message(
  ".input {$count :integer}\n.match $count\n one {{{$count} item}}\n * {{{$count} items}}",
  {count = 3}
)
-- "3 items"

number(value, options \\ [], state)

Formats a number for the active locale (localize.number(1234.5, {locale = "de"})).

Pass format = "percent" for percentages or currency = "USD" for currency; any option accepted by Number.to_string/2 may appear in the table.

percent(value, options \\ [], state)

Formats a fractional number as a percentage (localize.percent(0.56)"56%").

relative(value, unit, options \\ [], state)

Formats a relative time (localize.relative(-3, "day")"3 days ago").

The unit is one of second, minute, hour, day, week, month, quarter, or year.

territory_name(code, options \\ [], state)

Localized display name of a territory (localize.territory_name("AU", {locale = "fr"})).

time(iso_string, options \\ [], state)

Formats an ISO 8601 time string (localize.time("14:30:00", {locale = "en"})).

unit(value, unit_name, options \\ [], state)

Formats a measurement (localize.unit(42, "kilometer", {format = "short"})"42 km").