Author:
    Creation:2026-01-21Last update:2026-09-19

    astro-intlayer Package

    The astro-intlayer package provides the necessary tools to integrate Intlayer into Astro applications. It configures locale-based routing, dictionary management, build-time page rewriting, request middleware, and hooks for accessing multilingual content across both server-rendered .astro components and client-side scripts.

    Installation

    bash
    npm install astro-intlayer
    

    Exports

    Integration

    The astro-intlayer package provides an Astro integration that sets up Intlayer in your project.

    Import:

    tsx
    import { intlayer } from "astro-intlayer";
    

    or default import in astro.config.mjs:

    ts
    import { defineConfig } from "astro/config";
    import intlayer from "astro-intlayer";
    
    export default defineConfig({
      integrations: [intlayer()],
    });
    
    FunctionDescriptionRelated Doc
    intlayerAstro integration that prepares dictionaries, configures Vite plugins (aliases, routing proxy, prune), automatically registers request middleware, and emits prerendered pages at localised rewritten URLs.intlayer

    Hooks (Server & Client)

    Import:

    tsx
    import { useIntlayer, useDictionary, useLocale } from "astro-intlayer";
    
    HookDescriptionRelated Doc
    useIntlayerPicks one dictionary by its key and returns its localised content. In .astro frontmatter, it reads the request locale from Astro.locals. In client <script>, it reads from the client store.useIntlayer
    useDictionaryTransforms a dictionary object and returns content for the resolved locale. Works in frontmatter and client scripts.useDictionary
    useLocaleReturns the current locale, default locale, available locales, and a function to update the locale.useLocale

    Middleware (astro-intlayer/middleware)

    Import:

    tsx
    import { onRequest } from "astro-intlayer/middleware";
    
    ExportTypeDescriptionRelated Doc
    onRequestMiddlewareHandlerAstro middleware that detects the request locale and attaches Astro.locals.intlayer. Registered automatically by intlayer(), or imported manually to compose.onRequest

    Utilities

    Import:

    tsx
    import { getIntlayerLocals } from "astro-intlayer";
    
    FunctionDescriptionRelated Doc
    getIntlayerLocalsHelper function to retrieve the current IntlayerLocals object from the request storage scope outside of Astro.locals.-

    Client Utilities (astro-intlayer/client)

    Import:

    tsx
    import {
      useIntlayer,
      useDictionary,
      useDictionaryDynamic,
      useLocale,
      useLocaleStorage,
      useLocaleCookie,
      getIntlayer,
      getDictionary,
      installIntlayer,
      setLocaleInStorage,
      setLocaleCookie,
      localeInStorage,
      localeCookie,
    } from "astro-intlayer/client";
    

    When imported in the browser or inside client <script> tags, astro-intlayer automatically maps to astro-intlayer/client (powered by vanilla-intlayer), providing client-side dictionary getters, store subscribers, and locale persistence tools.

    Formatters (astro-intlayer/format)

    Import:

    tsx
    import {
      useIntl,
      useDate,
      useNumber,
      useCurrency,
      usePercentage,
      useRelativeTime,
      useList,
      useUnit,
      useCompact,
    } from "astro-intlayer/format";
    
    HookDescription
    useIntlReturns an Intl instance bound to the request or client locale with caching and subscription capabilities.
    useDateReturns a date formatting function pre-bound to the current locale (Intl.DateTimeFormat).
    useNumberReturns a number formatting function pre-bound to the current locale (Intl.NumberFormat).
    useCurrencyReturns a currency formatting function pre-bound to the current locale.
    usePercentageReturns a percentage formatting function pre-bound to the current locale.
    useRelativeTimeReturns a relative time formatting function pre-bound to the current locale (Intl.RelativeTimeFormat).
    useListReturns a list formatting function pre-bound to the current locale (Intl.ListFormat).
    useUnitReturns a unit formatting function pre-bound to the current locale.
    useCompactReturns a compact number formatting function pre-bound to the current locale (e.g. 1.5K).

    HTML Utilities (astro-intlayer/html)

    Import:

    tsx
    import { renderHTML, useHTML, useHTMLRenderer } from "astro-intlayer/html";
    
    ExportTypeDescription
    renderHTMLFunctionStandalone utility function to render HTML nodes.
    useHTMLHookHook to get the HTML provider context and configuration.
    useHTMLRendererHookHook to obtain a pre-configured HTML renderer function.

    Markdown Utilities (astro-intlayer/markdown)

    Import:

    tsx
    import {
      compileMarkdown,
      renderMarkdown,
      parseMarkdown,
      useMarkdown,
      useMarkdownRenderer,
    } from "astro-intlayer/markdown";
    
    ExportTypeDescription
    compileMarkdownFunctionCompiles markdown strings into structured representation.
    renderMarkdownFunctionRenders markdown content into output nodes.
    parseMarkdownFunctionParses raw markdown content into an AST.
    useMarkdownHookHook to get the markdown provider context.
    useMarkdownRendererHookHook to obtain a pre-configured Markdown renderer function.

    Types

    Import:

    tsx
    import type {
      IntlayerLocals,
      UseLocaleProps,
      UseLocaleResult,
    } from "astro-intlayer";
    
    TypeDescription
    IntlayerLocalsThe object attached to Astro.locals.intlayer containing locale, defaultLocale, and availableLocales.
    UseLocalePropsOptional configuration properties accepted by useLocale().
    UseLocaleResultThe return type of useLocale(), providing locale properties and update methods.