Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
Version History
- "Add useIntl"v8.0.01/20/2026
- "Remove getIntlayerAsync from formatters"v6.2.010/14/2025
- "Add vue formatters"v5.8.08/20/2025
- "Add formatters documentation"v5.8.08/18/2025
- "Add list formatter documentation"v5.8.08/20/2025
- "Add additional Intl utilities (DisplayNames, Collator, PluralRules)"v5.8.08/20/2025
- "Add locale utilities (getLocaleName, getLocaleLang, getLocaleFromPath, etc.)"v5.8.08/20/2025
- "Add content handling utilities (getContent, getTranslation, getIntlayer, etc.)"v5.8.08/20/2025
If you have an idea for improving this documentation, please feel free to contribute by submitting a pull request on GitHub.
GitHub link to the documentationCopy doc Markdown to clipboard
Intlayer Formatters
Table of Contents
Overview
Intlayer provides locale-aware formatting utilities built on top of the native Intl APIs. These formatters automatically use the current locale from your application context, eliminating the need to manually pass locale parameters.
For React, Vue, and other frameworks, use the framework-specific hooks/composables that automatically bind to your app's locale context:
Open the table in a modal to view all data content clearly
| Framework | Import |
|---|---|
| React (client) | react-intlayer/format |
| React (server) | react-intlayer/server/format |
| Next.js (client) | next-intlayer/client/format |
| Next.js (server) | next-intlayer/server/format |
| Vue | vue-intlayer/format |
| Preact | preact-intlayer/format |
| Vanilla JS / Node.js | intlayer (requires manual locale passing) |
React Formatters
Quick Start
Available Hooks
All hooks automatically use the locale from IntlayerProvider or IntlayerServerProvider.
Open the table in a modal to view all data content clearly
| Hook | Description | Example Output |
|---|---|---|
useNumber() | Format numbers with grouping | "123,456.789" |
useCurrency() | Format currency values | "€1,234.50" |
usePercentage() | Format percentages | "25%" |
useDate() | Format dates and times | "Aug 2, 2025" |
useRelativeTime() | Format relative time | "in 3 days" |
useUnit() | Format values with units | "5 kilometers" |
useCompact() | Format numbers in compact notation | "1.2K" |
useList() | Format arrays as lists | "apple, banana, and orange" |
useIntl() | Get locale-bound Intl object | Full Intl API access |
Complete Example
useIntl Hook
The useIntl hook provides direct access to a locale-bound Intl object. This is useful when you need the full Intl API (e.g., DisplayNames, Collator, PluralRules) with automatic locale injection.
Vue Formatters
Quick Start
Available Composables
All composables return computed refs that automatically use the locale from the injected IntlayerProvider.
Open the table in a modal to view all data content clearly
| Composable | Description | Example Output |
|---|---|---|
useNumber() | Format numbers with grouping | "123,456.789" |
useCurrency() | Format currency values | "€1,234.50" |
usePercentage() | Format percentages | "25%" |
useDate() | Format dates and times | "Aug 2, 2025" |
useRelativeTime() | Format relative time | "in 3 days" |
useUnit() | Format values with units | "5 kilometers" |
useCompact() | Format numbers in compact notation | "1.2K" |
useList() | Format arrays as lists | "apple, banana, and orange" |
useIntl() | Get locale-bound Intl object | Full Intl API access |
Complete Example
useIntl Composable
The useIntl composable provides direct access to a locale-bound Intl object. This is useful when you need the full Intl API with automatic locale injection.
Vanilla JS / Node.js Formatters
For non-framework contexts, import formatters directly from intlayer. Note that you must pass the locale manually.
Import
Formatter Functions
number(value, options?)
Formats a numeric value using locale-aware grouping and decimals.
- value:
number | string - options:
Intl.NumberFormatOptions & { locale?: LocalesValues }
percentage(value, options?)
Formats a number as a percentage string. Values greater than 1 are normalized (e.g., 25 → 25%, 0.25 → 25%).
- value:
number | string - options:
Intl.NumberFormatOptions & { locale?: LocalesValues }
currency(value, options?)
Formats a value as localized currency. Defaults to USD.
- value:
number | string - options:
Intl.NumberFormatOptions & { locale?: LocalesValues }- Common:
currency,currencyDisplay("symbol" | "code" | "name")
- Common:
date(date, optionsOrPreset?)
Formats a date/time value.
- date:
Date | string | number - optionsOrPreset:
Intl.DateTimeFormatOptions & { locale?: LocalesValues }or preset:"short" | "long" | "dateOnly" | "timeOnly" | "full"
relativeTime(from, to?, options?)
Formats relative time between two instants.
- from:
Date | string | number - to:
Date | string | number(defaults tonew Date()) - options:
{ locale?, unit?, numeric?, style? }
units(value, options?)
Formats a numeric value with a unit.
- value:
number | string - options:
Intl.NumberFormatOptions & { locale?: LocalesValues }- Common:
unit(e.g.,"kilometer","byte"),unitDisplay("short" | "narrow" | "long")
- Common:
compact(value, options?)
Formats a number using compact notation.
- value:
number | string - options:
Intl.NumberFormatOptions & { locale?: LocalesValues }
list(values, options?)
Formats an array into a localized list string.
- values:
(string | number)[] - options:
Intl.ListFormatOptions & { locale?: LocalesValues }- Common:
type("conjunction" | "disjunction" | "unit"),style("long" | "short" | "narrow")
- Common:
Cached Intl
The exported Intl from intlayer is a cached wrapper around the global Intl. It memoizes formatter instances (NumberFormat, DateTimeFormat, etc.) to avoid repeatedly constructing them, improving performance.
Additional Intl Features
Intl.DisplayNames
For localized names of languages, regions, currencies, and scripts:
Intl.Collator
For locale-aware string comparison and sorting:
Intl.PluralRules
For determining plural forms in different locales:
Locale Utilities
getLocaleName(displayLocale, targetLocale?)
Gets the localized name of a locale:
getLocaleLang(locale?)
Extracts the language code from a locale string:
getLocaleFromPath(inputUrl)
Extracts the locale segment from a URL or pathname:
getPathWithoutLocale(inputUrl, locales?)
Removes the locale segment from a URL:
getLocalizedUrl(url, currentLocale, locales?, defaultLocale?, prefixDefault?)
Generates a localized URL:
getHTMLTextDir(locale?)
Returns the text direction for a locale:
Content Handling Utilities
getContent(node, nodeProps, locale?)
Transforms a content node with all available plugins:
getTranslation(languageContent, locale?, fallback?)
Extracts content for a specific locale:
getIntlayer(dictionaryKey, locale?, plugins?)
Retrieves and transforms content from a dictionary:
Notes
- All helpers accept
stringinputs; they are internally coerced to numbers or dates. - Locale defaults to your configured
internationalization.defaultLocaleif not provided. - These utilities are thin wrappers; for advanced formatting, pass through the standard
Intloptions.