Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

Locale and Formatting

How dates, numbers, currency and file sizes are formatted for the reader, how the locale is chosen, and how to use another calendar.

Formatting values

Write the value in a form a machine can read and let the browser write it for the reader. The format attributes replace the text of a <time> or <data> element using the Intl formatters. The text you write inside the element is what shows before the script runs, and if it never does.

AttributeOnFormats
data-format-date<time>Dates, times and relative times such as 3 days ago
data-format-number<data>Numbers, currency, percentages and compact forms
data-format-bytes<data>File sizes

How the locale is chosen

The format attributes and the date components all ask one function, getLocale(el), which looks in this order:

  1. data-locale on the element itself (format utilities such as data-format-number, data-format-date and data-format-bytes)
  2. the nearest ancestor with a lang attribute (el.closest('[lang]'))
  3. <html lang>
  4. navigator.language
  5. 'en' fallback

So a <section lang="de"> formats its numbers and dates in German even on an English page, and data-locale overrides a single element:

Components that read the nearest lang (<calendar-wc>, <week-view>, <day-view>, <date-picker>) pass it through usableLocale() first. A malformed tag such as the POSIX-style lang="en_US" makes every Intl constructor throw, so those components fall back to en-US rather than failing to render. Write BCP 47 tags with hyphens: en-US, ja-JP.

Other calendars

Locales are passed straight to Intl, so a BCP 47 calendar extension works with no extra configuration. Setting lang="ja-JP-u-ca-japanese" on <html> switches every date utility to the Japanese era calendar (和暦) at once:

<html lang>data-format-datedata-format-date="short"
ja-JP2026/10/212026/10/21
ja-JP-u-ca-japanese令和8年10月21日R8/10/21

The extension is invisible to everything else that reads lang. :lang(ja) still matches, so the CJK typography and ruby rules apply unchanged, and Intl.RelativeTimeFormat and Intl.NumberFormat ignore the calendar and keep working. To use the era calendar for one element only, put the same tag in its data-locale (format utilities) or lang (<date-picker>).

Intl formats era dates but cannot parse them. <date-picker> accepts typed era dates when its locale is Japanese (令和8年10月21日, 令和元年5月1日, R8/10/21) as well as the Gregorian 2026年10月21日 form.

Locale in script

The same functions are exported for your own code, so a custom component formats the way the rest of the page does.

↑