howdy/i18n/format

Numbers, money, dates, relative times and lists, written the way a translator’s locale writes them.

let t = i18n.new("de")
format.integer(t, 1_234_567)                    // "1.234.567"
format.decimal(t, 3.14159)                      // "3,142"
format.percent(t, 0.25)                         // "25 %"
format.currency(t, minor: 123_456, code: "EUR") // "1.234,56 €"
format.date(t, date, format.Long)               // "19. Oktober 2026"
format.relative(t, -1, format.Day)              // "gestern"
format.list(t, ["Anna", "Ben", "Cem"])          // "Anna, Ben und Cem"

The patterns come from CLDR. Times are written as given: there is no time zone support yet, so convert to the reader’s zone first, and the zone names some locales put in their longer time formats are left out.

Types

How much detail a date or time shows. In English, Short is 10/19/26, Medium Oct 19, 2026, Long October 19, 2026 and Full Monday, October 19, 2026.

pub type Style {
  Short
  Medium
  Long
  Full
}

Constructors

  • Short
  • Medium
  • Long
  • Full
pub type Unit {
  Second
  Minute
  Hour
  Day
  Week
  Month
  Quarter
  Year
}

Constructors

  • Second
  • Minute
  • Hour
  • Day
  • Week
  • Month
  • Quarter
  • Year

How long a month or weekday name is: January, Jan or J.

pub type Width {
  Wide
  Abbreviated
  Narrow
}

Constructors

  • Wide
  • Abbreviated
  • Narrow

Values

pub fn currency(
  translator: i18n.Translator,
  minor minor: Int,
  code code: String,
) -> String

An amount of money in the currency’s smallest unit, such as cents, so that no amount is ever a float: currency(t, minor: 1999, code: "USD") is $19.99. code is an ISO 4217 code; currencies without a symbol in the locale’s data show their code.

pub fn date(
  translator: i18n.Translator,
  date: calendar.Date,
  style: Style,
) -> String

A date: October 19, 2026 in English at Long.

pub fn date_time(
  translator: i18n.Translator,
  date: calendar.Date,
  time: calendar.TimeOfDay,
  style: Style,
) -> String

A date and a time together, each at style.

pub fn decimal(
  translator: i18n.Translator,
  number: Float,
) -> String

A number with up to three digits after the decimal point, as the locale usually writes them: 3.142.

pub fn first_day_of_week(translator: i18n.Translator) -> Int

The day weeks start on where the locale is used, from 1 for Monday to 7 for Sunday.

pub fn fixed(
  translator: i18n.Translator,
  number: Float,
  digits: Int,
) -> String

A number with exactly digits digits after the decimal point: fixed(t, 2.5, 2) is 2.50.

pub fn integer(
  translator: i18n.Translator,
  number: Int,
) -> String

A whole number with the locale’s digit grouping: 1,234,567.

pub fn list(
  translator: i18n.Translator,
  items: List(String),
) -> String

Items joined as a list of things that all apply: a, b, and c.

pub fn month_day(
  translator: i18n.Translator,
  month: calendar.Month,
  day: Int,
) -> String

A day and month without the year: October 19.

pub fn month_year(
  translator: i18n.Translator,
  year: Int,
  month: calendar.Month,
) -> String

A month and year, as in a calendar’s heading: October 2026.

pub fn months(
  translator: i18n.Translator,
  width: Width,
) -> List(String)

The names of the months, January first. Wide names are as used on their own, as in a heading, which in some languages differs from their form inside a date.

pub fn or_list(
  translator: i18n.Translator,
  items: List(String),
) -> String

Items joined as alternatives: a, b, or c.

pub fn percent(
  translator: i18n.Translator,
  fraction: Float,
) -> String

A fraction as a percentage, so 0.25 is 25%, rounded to a whole percent.

pub fn relative(
  translator: i18n.Translator,
  amount: Int,
  unit: Unit,
) -> String

A time relative to now: relative(t, -3, Day) is 3 days ago, and relative(t, 2, Hour) is in 2 hours. Where the locale has a word for the offset, it is used, so -1 days is yesterday and 0 is today.

pub fn time(
  translator: i18n.Translator,
  time: calendar.TimeOfDay,
  style: Style,
) -> String

A time of day: 3:04 PM in English at Short. Long and Full include seconds.

pub fn weekdays(
  translator: i18n.Translator,
  width: Width,
) -> List(String)

The names of the days of the week, Monday first. Narrow names are the shortest the locale writes for a calendar’s column headings, such as Mo or M.

✨ Search Document