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
localeplugin) to one withLocale::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 (
monthis 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.
sun0is 0 = Sunday … 6 = Saturday and wraps, soweekday_short(start + i, …)walks a week from any start day.