Unicode CLDR (Common Locale Data Repository) formatting for Typst. Provides locale-aware number and date/time formatting.
#import "@preview/cldr:0.1.0": number, date, time, dt- Number formatting: Decimal, percent, scientific, and currency formats
- Date formatting: Short, medium, long, and full date formats
- Time formatting: Short, medium, long, and full time formats
- DateTime formatting: Combined date and time formatting
- 10 locales: English, Chinese, Hindi, Spanish, French, Arabic, Bengali, Portuguese, Russian, Japanese
#import "@preview/cldr:0.1.0": number
// Standard decimal formatting
#number.format(1234.56) // "1,234.56"
#number.format(1234.56, locale: "de") // "1.234,56"
#number.format(1234.56, locale: "fr") // "1 234,56"
// Percent formatting
#number.format(0.15, format: "percent") // "15%"
#number.format(0.857, format: "percent") // "86%"
// Currency formatting
#number.format(99.99, format: "currency", currency: "USD") // "$99.99"
#number.format(99.99, format: "currency", currency: "EUR") // "€99.99"
#number.format(1234.56, format: "currency", currency: "JPY", locale: "ja") // "¥1,235"
// Scientific notation
#number.format(1234567, format: "scientific") // "1.234567E6"
// Control decimal places
#number.format(3.14159, max-fraction-digits: 2) // "3.14"
#number.format(5, min-fraction-digits: 2) // "5.00"#import "@preview/cldr:0.1.0": date
#let today = datetime.today()
// Format types
#date.format(today) // "Dec 19, 2025" (medium)
#date.format(today, format: "short") // "12/19/25"
#date.format(today, format: "long") // "December 19, 2025"
#date.format(today, format: "full") // "Friday, December 19, 2025"
// Different locales
#date.format(today, locale: "fr") // "19 déc. 2025"
#date.format(today, locale: "de") // "19.12.2025"
#date.format(today, locale: "ja") // "2025/12/19"
#date.format(today, locale: "zh") // "2025年12月19日"
// Get month/day names
#date.month-name(12) // "December"
#date.month-name(12, width: "abbreviated") // "Dec"
#date.day-name(0) // "Sunday"#import "@preview/cldr:0.1.0": time
#let now = datetime.today()
// Format types
#time.format(now) // "3:45:30 PM" (medium)
#time.format(now, format: "short") // "3:45 PM"
// Different locales (24-hour vs 12-hour)
#time.format(now, locale: "de") // "15:45:30"
#time.format(now, locale: "fr") // "15:45:30"#import "@preview/cldr:0.1.0": dt
#let now = datetime.today()
// Combined date and time
#dt.format(now) // "Dec 19, 2025, 3:45:30 PM"
#dt.format(now, format: "short") // "12/19/25, 3:45 PM"
#dt.format(now, format: "full") // "Friday, December 19, 2025, 3:45:30 PM"
// Mix date and time formats
#dt.format(now, date-format: "long", time-format: "short") // "December 19, 2025, 3:45 PM"| Code | Language |
|---|---|
en |
English |
zh |
Chinese |
hi |
Hindi |
es |
Spanish |
fr |
French |
ar |
Arabic |
bn |
Bengali |
pt |
Portuguese |
ru |
Russian |
ja |
Japanese |
de |
German |
Format a number with locale-specific formatting.
| Parameter | Type | Default | Description |
|---|---|---|---|
num |
number | required | The number to format |
locale |
string | "en" |
Locale code |
format |
string | "standard" |
Format type: "standard", "percent", "currency", "scientific" |
currency |
string | none | Currency code (required for currency format) |
min-fraction-digits |
int | varies | Minimum decimal places |
max-fraction-digits |
int | varies | Maximum decimal places |
Format a date with locale-specific formatting.
| Parameter | Type | Default | Description |
|---|---|---|---|
dt |
datetime | required | The datetime to format |
locale |
string | "en" |
Locale code |
format |
string | "medium" |
Format type: "short", "medium", "long", "full" |
Format a time with locale-specific formatting.
| Parameter | Type | Default | Description |
|---|---|---|---|
dt |
datetime | required | The datetime to format |
locale |
string | "en" |
Locale code |
format |
string | "medium" |
Format type: "short", "medium", "long", "full" |
Format a combined date and time with locale-specific formatting.
| Parameter | Type | Default | Description |
|---|---|---|---|
dt |
datetime | required | The datetime to format |
locale |
string | "en" |
Locale code |
format |
string | "medium" |
Format type: "short", "medium", "long", "full" |
date-format |
string | none | Override date format |
time-format |
string | none | Override time format |
The locale data is generated from Unicode CLDR JSON files. To regenerate:
cd scripts
python3 generate.pyThis will:
- Download CLDR JSON data (cached in
.cache/) - Parse number and date formatting data
- Generate Typst data files in
data/
Edit scripts/config.py and add locale codes to the LOCALES list, then regenerate.
MIT License - see LICENSE
- Data from Unicode CLDR version 48.0.0
- API inspired by Elixir CLDR