Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
This doc is out of date, the base version has been updated on 22 August 2026.
Go to English docVersion History
- "Add Vue formatters"v5.8.020/08/2025
- "Add formatters documentation"v5.8.018/08/2025
- "Add list formatter documentation"v5.8.020/08/2025
- "Add additional Intl utilities (DisplayNames, Collator, PluralRules)"v5.8.020/08/2025
- "Add locale utilities (getLocaleName, getLocaleLang, getLocaleFromPath, etc.)"v5.8.020/08/2025
- "Add content handling utilities (getContent, getTranslation, getIntlayer, etc.)"v5.8.020/08/2025
The content of this page was translated using an AI.
See the last version of the original content in EnglishIf 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
Overview
Intlayer provides a set of lightweight helpers built on top of the native Intl APIs, plus a cached Intl wrapper to avoid repeatedly constructing heavy formatters. These utilities are fully locale-aware and can be used from the main intlayer package.
Cached Intl
Because formatter construction is relatively expensive, this caching improves performance without changing behaviour. The wrapper exposes the same API as the native Intl, so usage is identical.
If Intl.DisplayNames is not available in the environment, a single dev-only warning is printed (consider a polyfill).
Examples:
Locale Utilities
getLocaleFromPath(inputUrl)
Copy the code to the clipboard
getPathWithoutLocale(inputUrl, locales?)
Removes the locale segment from a URL or pathname:
- inputUrl: The complete URL string or pathname to process
- locales: Optional array of supported locales (defaults to configured locales)
- returns: The URL without the locale segment
getLocalizedUrl(url, currentLocale, locales?, defaultLocale?, prefixDefault?)
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?)
Copy the code to the clipboard
getTranslation(languageContent, locale?, fallback?)
Extracts content for a specific locale from a language content object:
- languageContent: Object mapping locales to content
- locale: Target locale (defaults to configured default locale)
- fallback: Whether to fallback to the default locale (defaults to true)
getIntlayer(dictionaryKey, locale?, plugins?)
Copy the code to the clipboard
getIntlayerAsync(dictionaryKey, locale?, plugins?)
Asynchronously retrieves content from a remote dictionary:
Copy the code to the clipboard
Formatters
All helpers below are exported from intlayer.
percentage(value, options?)
Copy the code to the clipboard
Additional Intl Features
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 normalised (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 localised 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 localised 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 localised 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
units(value, options?)
Examples:
Copy the code to the clipboard
compact(value, options?)
Examples:
Copy the code to the clipboard
list(values, options?)
Examples:
Copy the code to the clipboard
getLocaleLang(locale?)
Extracts the language code from a locale string:
Copy the code to the clipboard
React
Client components:
Copy the code to the clipboard
getHTMLTextDir(locale?)
Returns the text direction for a locale:
Copy the code to the clipboard
Content Handling Utilities
Vue
Client components:
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.
