שאלו את שאלתכם וקבלו סיכום של המסמך על ידי הפניה לדף הזה ולספק ה-AI שתבחרו
היסטוריית גרסאות
- "Formatters fall back to the request locale, then the stored locale, when no locale is passed"v9.6.02.10.2026
- "Update to Next.js >= 9.4.0 architecture"v9.4.022.8.2026
- "Add useIntl"v8.0.020.1.2026
- "Remove getIntlayerAsync from formatters"v6.2.014.10.2025
- "Add vue formatters"v5.8.020.8.2025
- "Add formatters documentation"v5.8.018.8.2025
- "Add list formatter documentation"v5.8.020.8.2025
- "Add additional Intl utilities (DisplayNames, Collator, PluralRules)"v5.8.020.8.2025
- "Add locale utilities (getLocaleName, getLocaleLang, getLocaleFromPath, etc.)"v5.8.020.8.2025
- "Add content handling utilities (getContent, getTranslation, getIntlayer, etc.)"v5.8.020.8.2025
התוכן של הדף הזה תורגם באמצעות AI.
צפייה בגרסה האחרונה של התוכן המקורי באנגליתאם יש לכם רעיון לשיפור התיעוד הזה, אל תהססו לתרום על ידי הגשת Pull Request ב-GitHub.
קישור GitHub לתיעודהעתקת ה-Markdown של המסמך ללוח
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:
פתיחת הטבלה בחלון כדי לראות את כל תוכן הנתונים בבירור
| 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 (no provider needed) |
Which locale is used?
When you pass a locale option, it always wins. Otherwise, the formatters, their hooks (useNumber, useDate, useList…) and useIntl resolve it in this order:
- The locale of the provider (
IntlayerProvider), for hooks and composables. - The locale of the current request, on the server, when an Intlayer integration handles it (
express-intlayer,fastify-intlayer,hono-intlayer,remix-intlayer,astro-intlayer…). - The locale stored in the browser (cookie,
localStorage,sessionStorage), the one your locale switcher persists. - The
defaultLocaleof your configuration.
העתקת הקוד ללוח
Outside of a provider or a server integration, the server formats with the defaultLocale while the browser uses the stored locale, which can cause a hydration mismatch. For server-rendered pages, use a provider or pass the locale explicitly.
React Formatters
Quick Start
העתקת הקוד ללוח
Available Hooks
All hooks automatically use the locale from IntlayerProvider (or IntlayerClientProvider / IntlayerServerProvider).
פתיחת הטבלה בחלון כדי לראות את כל תוכן הנתונים בבירור
| 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.
פתיחת הטבלה בחלון כדי לראות את כל תוכן הנתונים בבירור
| 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. The locale option is optional: without it, the request locale, then the stored locale, then the defaultLocale is used.
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.
