Skip to main content

Module format

Module format 

Source
Expand description

Locale-aware numbers and dates, for Rust code and for catalogues.

In a catalogue, numbers go through Fluent’s NUMBER function (or are placed as they are) and are written with the locale’s separators; plurals select on them by the locale’s rules. Dates go through DATETIME, which takes an ISO date (2026-10-12), date and time (2026-10-12T14:05) or a number of seconds since 1970 (UTC):

files = { $count ->
    [one] { $count } file
   *[other] { $count } files
}
size = { NUMBER($mib, maximumFractionDigits: 1) } MiB
saved = Saved on { DATETIME($when, dateStyle: "long") }

dateStyle is short, medium (the default), long or full; timeStyle is short or medium. Month and weekday names are known for English and French; other languages get numeric dates (2026-10-12).

use egui_pop_i18n::format::{self, DateStyle};

assert_eq!(format::number("fr", 1234.5, Some(1)), "1\u{202f}234,5");
assert_eq!(format::number("en", 1234.5, Some(1)), "1,234.5");
let d = format::Date::parse("2026-10-12").unwrap();
assert_eq!(format::date("fr", &d, DateStyle::Long), "12 octobre 2026");
assert_eq!(format::date("en", &d, DateStyle::Medium), "Oct 12, 2026");

Structs§

Date
A calendar date, with an optional time of day.
Separators
How a locale writes numbers.

Enums§

DateStyle
How long a date is written.

Functions§

date
A date written for a locale.
fluent_number
A Fluent number from Rust, for arguments.
number
A number written for a locale: at most max_fraction digits after the separator (3 when None), trailing zeros dropped, grouped by thousands.
number_with
A number written for a locale with Fluent’s options (minimumFractionDigits, maximumFractionDigits, minimumIntegerDigits, useGrouping, style: "percent").
quantity
A number already written followed by its unit, with the locale’s space between them (the number alone when unit is empty).
separators
The separators of a locale (English’s for a language not known).
time
A time of day written for a locale; seconds for the medium style.