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.
How the locale is chosen
The format attributes and the date components all ask one function, getLocale(el), which looks in this order:
data-locale on the element itself (format utilities such as data-format-number, data-format-date and data-format-bytes)
- the nearest ancestor with a
lang attribute (el.closest('[lang]'))
<html lang>
navigator.language
'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:
<html lang="en"> <data value="1234.56" data-format-number>1,234.56</data> <section lang="de"> <data value="1234.56" data-format-number>1.234,56</data> </section> <data value="1234.56" data-format-number data-locale="fr">1 234,56</data></html>
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-date | data-format-date="short" |
ja-JP | 2026/10/21 | 2026/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>).
<html lang="ja-JP-u-ca-japanese"> <time datetime="2026-10-21" data-format-date>令和8年10月21日</time> <time datetime="2026-10-21" data-format-date="short">R8/10/21</time></html>
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.
import { getLocale, usableLocale } from 'vanilla-breeze'; getLocale(); getLocale(el); usableLocale('en_US'); new Intl.DateTimeFormat(getLocale(el), { dateStyle: 'long' }).format(date);