Skip to main content

Module format

Module format 

Source
Expand description

Locale-aware number, currency, and date formatting — pure, synchronous, dependency-light.

view() builds the Widget tree synchronously, but device capabilities/plugins are async, so locale formatting can’t be delegated to the platform’s NumberFormatter/Intl at render time — it has to run in the core. This module hand-rolls the conventions for the locales Mobiler apps actually target (Swiss de/fr/it + the common Western locales) instead of pulling in a full ICU data bundle, keeping the wasm web shell small.

use mobiler_core::format::{format_currency, Currency, Locale};
assert_eq!(format_currency(1234.5, Currency::Chf, Locale::DeCh), "CHF 1'234.50");
assert_eq!(format_currency(1234.5, Currency::Eur, Locale::DeDe), "1.234,50 €");

Enums§

Currency
A currency. Placement (symbol leading vs trailing) follows the Locale.
Locale
A formatting locale — drives digit grouping, the decimal mark, currency placement, and the date order + month names. Map a device language tag (e.g. from a locale plugin) to one with Locale::from_tag.
Weekday
A day of the week — the first column of a localized calendar (Locale::week_start).

Functions§

format_currency
Format a monetary amount (always two fraction digits). Symbol placement follows locale: CHF/USD/GBP lead; EUR trails in de-DE/fr-FR/it-IT and leads elsewhere.
format_date
Numeric date in the locale’s conventional order/separator.
format_date_long
Long date with the localized month name (e.g. "5. Januar 2026", "January 5, 2026").
format_int
Format an integer, grouped per locale.
format_number
Format a floating-point number with a fixed number of decimal places, grouped per locale.
month_name
The localized full month name (month is 1–12, clamped).
month_year
A calendar title: the localized month name, capitalized, then the year ("Septembar 2026").
weekday_short
The localized narrow weekday label for a calendar header. sun0 is 0 = Sunday … 6 = Saturday and wraps, so weekday_short(start + i, …) walks a week from any start day.