API Reference
setRequestLocalesetRequestLocale(url: URL, getConfig?: GetRequestConfigFn): Promise<boolean>Extracts and validates the locale from the first URL pathname segment, then calls your getConfig function to load messages. Must be awaited before any other call. For SSR, prefer createIntlMiddleware() or runWithLocale() so the complete render stays request-isolated.
runWithLocalerunWithLocale<R>(url: URL, fn: () => R | Promise<R>, getConfig?: GetRequestConfigFn): Promise<R>Runs a function inside an isolated per-request context using Node.js AsyncLocalStorage. SSR runtimes without safe request-local storage fail explicitly instead of sharing global state.
getLocalegetLocale(): stringReturns the current locale string set by setRequestLocale. Throws if called before setting the locale.
getTranslationsgetTranslations<T>(namespace?: string)Returns a typed t(key, values?) function scoped to the given namespace. The optional values object replaces {curlyOpen}varName{curlyClose} placeholders. Also exposes parser-sanitized t.markup(key, tags | {curlyOpen} values?, tags {curlyClose}) for HTML interpolation and t.raw(key) for accessing raw values without coercion.
defineRequestConfigdefineRequestConfig(fn: GetRequestConfigFn): GetRequestConfigFnRegisters and returns a message loader. Import the module that declares it before initializing the language. See Custom message loading for complete files.
getLocalesgetLocales(): string[]Returns the array of locales configured via the integration options or createIntlMiddleware. Returns an empty array if not set.
isValidLocaleisValidLocale(locale: string): booleanChecks that a locale has valid BCP-47-style syntax and, when a locales list is configured, that it is included in that list.
getMessagesgetMessages(): Record<string, unknown>Returns the full messages object for the current request. Throws if called before setRequestLocale.
createIntlMiddlewarecreateIntlMiddleware(options: { locales: string[]; defaultLocale?: string; routes?: RoutesMap })Creates Astro middleware that validates and loads the request locale, then keeps the complete render or rewrite inside a Node.js AsyncLocalStorage context. It also sets locales, defaultLocale, and routes in the intl store. Import from astro-intl/middleware.
pathpath(routeKey: string, options?: { locale?: string; params?: Record<string, string>; encode?: boolean }): stringGenerates a localized URL for a named route. Uses the current locale if none is specified, rejects invalid locale segments, and substitutes [param] placeholders with the provided params. Import from astro-intl/routing.
switchLocalePathswitchLocalePath(currentPath: string | URL, nextLocale: string): stringConverts the current URL to its equivalent in another validated locale. Matches the path against route templates, extracts dynamic params, and rebuilds the URL using the target locale's template. Preserves query strings and hashes. Import from astro-intl/routing.
RequestConfigType returned by your getRequestConfig function. Contains locale: string and messages: Record.
IntlConfigConfiguration type for the integration options. Contains defaultLocale: string, locales: string[], routes?: RoutesMap, and fallbackRoutes?: FallbackRouteInfo[].
PrimitiveUnion type for interpolation values: string | number | boolean | null | undefined. Used as the value type in the values object passed to t() and t.markup().
DotPaths<T>Utility type that generates all valid dot-notation paths for a given messages object. Used internally to provide autocomplete for translation keys.
RoutesMapType for the routes configuration object. Maps route keys to an object of locale → URL template pairs. Example: { about: { en: "/about", es: "/sobre-nosotros" } }.
createGetTranslations (React)createGetTranslations<UI, DefaultLocale>(ui: UI, defaultLocale: DefaultLocale)Use an explicit catalog in React islands in your Astro project or in tests. Returns getTranslations(lang, namespace) with t.rich() support returning ReactNode[]. Import from astro-intl/react.
createGetTranslations (Preact)createGetTranslations(ui, defaultLocale)(lang, namespace)Import this function from astro-intl/preact to translate with an explicit catalog in Preact 10 and 11. t.rich() returns renderable Preact children.
createGetTranslations (SolidJS)createGetTranslations(ui, defaultLocale)(lang, namespace)Import this function from astro-intl/solid to test a SolidJS catalog with an explicit locale. t.rich() returns JSX.Element[] you can render in a component.
createGetTranslations (Vue)createGetTranslations(ui, defaultLocale)(lang, namespace)Import this function from astro-intl/vue to translate with an explicit catalog in Vue 3. t.rich() returns VNodeChild[] for Vue render functions.
createGetTranslations (Svelte)createGetTranslations<UI, DefaultLocale>(ui: UI, defaultLocale: DefaultLocale)Use an explicit catalog in Svelte islands in your Astro project or in tests. Returns getTranslations(lang, namespace) with t.rich() support returning RichSegment[]. Import from astro-intl/svelte.
renderRichTextrenderRichText(segments: RichSegment[], options?: { tags?: Record<string, string>; components?: Record<string, (chunks: string) => string> }): stringConverts an array of RichSegment[] into a sanitized HTML string. Text and chunks are escaped, unsafe native tag mappings are rejected, and component callbacks are treated as trusted application code before final sanitization. Import from astro-intl/svelte.
getFallbackRoutesgetFallbackRoutes(): FallbackRouteInfo[]Returns the i18n fallback routes collected from Astro 6.1's astro:routes:resolved hook. Returns an empty array on Astro < 6.1 or when no fallback routes are configured. Each entry contains the route pattern, optional pathname, and the locale.
FallbackRouteInfoType for fallback route entries. Contains pattern: string (the route pattern), pathname?: string (the static pathname if available), and locale: string (the locale this fallback serves).
t.raw()Returns the raw translation value without string coercion. Use this to access arrays, objects, and numbers in their native JavaScript type instead of getting [object Object].
MessagesDirConfigExported type shaped as {curlyOpen} dir: string {curlyClose}. The integration option messagesDir accepts a string directly, not this object. See Configuration options for its limitations.
AutoRedirect Component<AutoRedirect locales={string[]} defaultLocale={string} />Astro component that validates its locale props, detects the user's browser language, and redirects to the appropriate encoded localized route. defaultLocale must be included in locales. Import from astro-intl/components.
Auto-detect Locale (Static Mode)Only in the browser, getLocale() can read the language from window.location.pathname when there is no context. This does not load messages or replace initialization during a static build or server rendering.