Locale-aware formatting presets #44

Open
opened 2026-08-17 13:37:35 +00:00 by rosa · 0 comments
Owner

Problem

Format requires the caller to specify separators, symbol position, and negative style by hand. Formatting 1234.56 EUR for a German reader (1.234,56 €) versus a US reader (€1,234.56) means knowing each locale's conventions. CLDR already encodes them.

Proposal

Locale presets layered on the existing Format struct:

  • A constructor like Format::for_locale(locale) that fills in separators, symbol position, and spacing from CLDR data. Callers can still override fields afterward.
  • Accounting style: negative amounts in parentheses, e.g. ($1,234.56).
  • Compact notation: $1.2K, $3.4M, for dashboards and charts.

Open questions

  • Where the CLDR data comes from: depend on icu (heavy), generate a table at build time from CLDR JSON (like the ISO table), or hand-curate the top N locales. Data size versus coverage is the main trade-off.
  • Whether compact notation belongs in Format or as a separate formatter, since it discards precision.
## Problem `Format` requires the caller to specify separators, symbol position, and negative style by hand. Formatting `1234.56` EUR for a German reader (`1.234,56 €`) versus a US reader (`€1,234.56`) means knowing each locale's conventions. CLDR already encodes them. ## Proposal Locale presets layered on the existing `Format` struct: - A constructor like `Format::for_locale(locale)` that fills in separators, symbol position, and spacing from CLDR data. Callers can still override fields afterward. - Accounting style: negative amounts in parentheses, e.g. `($1,234.56)`. - Compact notation: `$1.2K`, `$3.4M`, for dashboards and charts. ## Open questions - Where the CLDR data comes from: depend on `icu` (heavy), generate a table at build time from CLDR JSON (like the ISO table), or hand-curate the top N locales. Data size versus coverage is the main trade-off. - Whether compact notation belongs in `Format` or as a separate formatter, since it discards precision.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
rosa/lucre#44
No description provided.