Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
Version History
- "Update to Next.js >= 9.4.0 architecture"v9.4.08/22/2026
- "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
Copy the code to the clipboard
Available Hooks
All hooks automatically use the locale from IntlayerProvider (or IntlayerClientProvider / 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
Copy the code to the clipboard
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.
Copy the code to the clipboard
Vue Formatters
Quick Start
Copy the code to the clipboard
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
Copy the code to the clipboard
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.
Copy the code to the clipboard
Vanilla JS / Node.js Formatters
For non-framework contexts, import formatters directly from intlayer. Note that you must pass the locale manually.
Import
Copy the code to the clipboard
Formatter Functions
number(value, options?)
Formats a numeric value using locale-aware grouping and decimals.
- value:
number | string - options:
Intl.NumberFormatOptions & { locale?: LocalesValues }
Copy the code to the clipboard
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 }
Copy the code to the clipboard
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:
Copy the code to the clipboard
date(date, optionsOrPreset?)
Formats a date/time value.
- date:
Date | string | number - optionsOrPreset:
Intl.DateTimeFormatOptions & { locale?: LocalesValues }or preset:"short" | "long" | "dateOnly" | "timeOnly" | "full"
Copy the code to the clipboard
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? }
Copy the code to the clipboard
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:
Copy the code to the clipboard
compact(value, options?)
Formats a number using compact notation.
- value:
number | string - options:
Intl.NumberFormatOptions & { locale?: LocalesValues }
Copy the code to the clipboard
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:
Copy the code to the clipboard
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.
Copy the code to the clipboard
Additional Intl Features
Intl.DisplayNames
For localized names of languages, regions, currencies, and scripts:
Copy the code to the clipboard
Intl.Collator
For locale-aware string comparison and sorting:
Copy the code to the clipboard
Intl.PluralRules
For determining plural forms in different locales:
Copy the code to the clipboard
Locale Utilities
getLocaleName(displayLocale, targetLocale?)
Gets the localized name of a locale:
Copy the code to the clipboard
getLocaleLang(locale?)
Extracts the language code from a locale string:
Copy the code to the clipboard
getLocaleFromPath(inputUrl)
Extracts the locale segment from a URL or pathname:
Copy the code to the clipboard
getPathWithoutLocale(inputUrl, locales?)
Removes the locale segment from a URL:
Copy the code to the clipboard
getLocalizedUrl(url, currentLocale, locales?, defaultLocale?, prefixDefault?)
Generates a localized URL:
Copy the code to the clipboard
getHTMLTextDir(locale?)
Returns the text direction for a locale:
Copy the code to the clipboard
Content Handling Utilities
getContent(node, nodeProps, locale?)
Transforms a content node with all available plugins:
Copy the code to the clipboard
getTranslation(languageContent, locale?, fallback?)
Extracts content for a specific locale:
Copy the code to the clipboard
getIntlayer(dictionaryKey, locale?, plugins?)
Retrieves and transforms content from a dictionary:
Copy the code to the clipboard
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.
