Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
Version History
- "Initial history"v9.8.423/11/2026
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
Translate your vinext website using Intlayer
vinext reimplements the Next.js API on top of Vite. Your app/ directory, next/* imports and proxy.ts keep working, but the build runs through Vite instead of Turbopack or webpack.
Intlayer plugs into that setup with two packages: next-intlayer for the hooks, providers and proxy your components already use on Next.js, and vite-intlayer for the build side (dictionary compilation, watching and bundle optimisation).
Running Next.js with its own toolchain? Follow the Next.js 16 guide instead.
Table of Contents
Why Intlayer over alternatives?
Compared to solutions like next-intl or i18next, Intlayer comes with integrated optimisations:
The same next-intlayer code runs on Next.js and on vinext. Server Components resolve content on the server, Client Components read it through the provider, and the locale routing runs from your proxy.ts. Migrating between the two toolchains does not touch your components.
Instead of loading massive JSON files into your pages, load only the necessary content. The Vite plugin replaces each useIntlayer call with the entries the component actually uses, which reduces bundle and page size by up to 50%.
Scoping content per component simplifies maintenance for large applications. You can duplicate or delete a feature folder without reviewing your whole content codebase, and Intlayer is fully typed to keep your content accurate.
Co-locating content reduces the context needed by LLMs. Intlayer ships a CLI to test for missing translations, an LSP, an MCP server and agent skills.
Translate in your CI/CD pipeline with the LLM of your choice, at the cost of your AI provider. Intlayer also offers a compiler to automate content extraction, and a web platform to translate in the background.
Intlayer provides a self-hosted visual editor and a full CMS to manage multilingual content in real time with translators and copywriters. Content can be stored locally and/or remotely.
Step-by-Step Guide to Set Up Intlayer in a vinext Application
Install Dependencies
Start from a working vinext project. To create one, run
npm create vinext-app@latest. To migrate an existing Next.js app, runnpx vinext init.Then install Intlayer:
bashCopy codeCopy the code to the clipboard
intlayer
The core package that provides internationalisation tools for configuration management, translation, content declaration, transpilation, and CLI commands.
next-intlayer
Provides the providers, hooks and proxy for the Next.js API. vinext resolves
next/navigation,next/headersandnext/serverto its own implementations, sonext-intlayerworks unchanged.vite-intlayer
The Vite plugin that builds your content declarations, watches them in development, and optimises dictionaries in the production bundle. It replaces the
withIntlayer()Next.js plugin, which vinext does not run.
Configure Your Project
Choose whether your application should use localised URL paths (e.g.
/en/about,/fr/about) or serve content without a locale segment in the path (e.g./about, detecting the locale via cookies, headers, or query parameters).Architecture
All localised pages are nested under a
[locale]dynamic segment. This is recommended for SEO and static rendering, because each language has its own URL:bashCopy codeCopy the code to the clipboard
Configuration
Create an
intlayer.config.tsfile to declare the supported languages:intlayer.config.tsCopy codeCopy the code to the clipboard
import { Locales, type IntlayerConfig } from "intlayer"; const config: IntlayerConfig = { internationalization: { locales: [ Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH, // Your other locales ], defaultLocale: Locales.ENGLISH, }, routing: { mode: "prefix-no-default", // or `prefix-all` }, }; export default config;Architecture
Routes do not include a
[locale]segment. All pages live directly undersrc/app/, and the locale comes from cookies, headers, or query parameters. This fits dashboards and authenticated apps:bashCopy codeCopy the code to the clipboard
Configuration
Set
routing.modeto"search-params"(e.g./about?locale=fr) or"no-prefix":intlayer.config.tsCopy codeCopy the code to the clipboard
import { Locales, type IntlayerConfig } from "intlayer"; const config: IntlayerConfig = { internationalization: { locales: [ Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH, // Your other locales ], defaultLocale: Locales.ENGLISH, }, routing: { mode: "search-params", // or `no-prefix` }, }; export default config;This file also sets proxy redirection, cookie names, the location and extension of your content declarations, logs, and more. See the configuration documentation for the full list.
Integrate Intlayer in Your Vite Configuration
Add the
intlayer()plugin next tovinext()invite.config.ts:vite.config.tsCopy codeCopy the code to the clipboard
import { defineConfig } from "vite"; import vinext from "vinext"; import { intlayer } from "vite-intlayer"; export default defineConfig({ plugins: [ vinext(), intlayer({ // Locale routing is handled by `src/proxy.ts` (step 7) proxy: { ignore: () => true }, }), ], });The
intlayer()plugin builds your dictionaries before the build starts, watches content files in development, and sets up the aliases and optimisations used bynext-intlayerin the RSC, SSR and client environments.intlayer()also ships a locale routing middleware for the Vite dev server. On vinext,src/proxy.tsalready does that job, in development and on your production runtime, so theignoreoption turns the Vite one off to avoid routing every request twice.Leave
next.config.tsfree ofwithIntlayer(). vinext readsnext.config.tsfor options such asredirects,rewritesandheaders, but does not run webpack or Turbopack plugins.If you deploy to Cloudflare Workers, keep the
cloudflare()plugin generated byvinext init:vite.config.tsCopy codeCopy the code to the clipboard
import { cloudflare } from "@cloudflare/vite-plugin"; import { defineConfig } from "vite"; import vinext from "vinext"; import { intlayer } from "vite-intlayer"; export default defineConfig({ plugins: [ vinext(), intlayer({ proxy: { ignore: () => true } }), cloudflare({ viteEnvironment: { name: "rsc", childEnvironments: ["ssr"] }, }), ], });Define Dynamic Locale Routes
Remove everything from
RootLayoutand replace it with the following code:src/app/layout.tsxCopy codeCopy the code to the clipboard
import type { PropsWithChildren, FC } from "react"; import "./globals.css"; const RootLayout: FC<PropsWithChildren> = ({ children }) => ( // You can still wrap the children with other providers, like `next-themes` or `react-query` <>{children}</> ); export default RootLayout;Keeping
RootLayoutempty lets the locale layout set thelanganddirattributes on the<html>tag.Add a layout in your
[locale]directory:src/app/[locale]/layout.tsxCopy codeCopy the code to the clipboard
import { getHTMLTextDir } from "intlayer"; import type { NextLayoutIntlayer } from "next-intlayer"; import { IntlayerProvider } from "next-intlayer/server"; export { generateStaticParams } from "next-intlayer"; const LocaleLayout: NextLayoutIntlayer = async ({ children, params }) => { const { locale } = await params; return ( <html lang={locale} dir={getHTMLTextDir(locale)}> <body> <IntlayerProvider locale={locale}>{children}</IntlayerProvider> </body> </html> ); }; export default LocaleLayout;A single
IntlayerProvidercovers both halves of the tree: it provides the locale to Server Components and mounts the client provider so Client Components receive the same locale.The
[locale]segment holds the locale:/en-US/aboutresolves toen-US,/fr/abouttofr. The previoussrc/app/page.tsxis no longer used and can be removed. The proxy (step 7) serves the default locale at the root.generateStaticParamsmakes vinext prerender every page for each locale. vinext also enforcesdynamicParams, so an unknown locale returns a 404 when you setexport const dynamicParams = false.There is no
[locale]directory. Configuresrc/app/layout.tsxto read the locale from the request and wrap your application withIntlayerProvider:src/app/layout.tsxCopy codeCopy the code to the clipboard
import type { Metadata } from "next"; import type { ReactNode } from "react"; import "./globals.css"; import { getHTMLTextDir, getIntlayer } from "intlayer"; import { getLocale, IntlayerProvider } from "next-intlayer/server"; export const generateMetadata = async (): Promise<Metadata> => { const locale = await getLocale(); const { title, description, keywords } = getIntlayer("metadata", locale); return { title, description, keywords, }; }; const RootLayout = async ({ children, }: Readonly<{ children: ReactNode; }>) => { const locale = await getLocale(); return ( <html lang={locale} dir={getHTMLTextDir(locale)}> <body> <IntlayerProvider locale={locale}>{children}</IntlayerProvider> </body> </html> ); }; export default RootLayout;Declare Your Content
Create content declarations to store your translations:
src/app/[locale]/page.content.tsCopy codeCopy the code to the clipboard
import { t, type Dictionary } from "intlayer"; const pageContent = { key: "page", content: { getStarted: { main: t({ "en-GB": "Get started by editing", en: "Get started by editing", fr: "Commencez par éditer", es: "Comience por editar", }), pageLink: "src/app/page.tsx", }, }, } satisfies Dictionary; export default pageContent;Content declarations can live anywhere under the
contentDirdirectory (by default,./src), as long as they match the content declaration extension (by default,.content.{json,ts,tsx,js,jsx,mjs,cjs,md,mdx,yaml,yml}).For more details, refer to the content declaration documentation.
Utilize Content in Your Code
Access your dictionaries from any component:
src/app/[locale]/page.tsxCopy codeCopy the code to the clipboard
import type { FC } from "react"; import { ClientComponentExample } from "@components/ClientComponentExample"; import { ServerComponentExample } from "@components/ServerComponentExample"; import { type NextPageIntlayer, useIntlayer } from "next-intlayer"; const PageContent: FC = () => { const content = useIntlayer("page"); return ( <> <p>{content.getStarted.main}</p> <code>{content.getStarted.pageLink}</code> </> ); }; const Page: NextPageIntlayer = () => ( <> <PageContent /> <ServerComponentExample /> <ClientComponentExample /> </> ); export default Page;src/components/ClientComponentExample.tsxCopy codeCopy the code to the clipboard
"use client"; import type { FC } from "react"; import { useIntlayer } from "next-intlayer"; export const ClientComponentExample: FC = () => { const content = useIntlayer("client-component-example"); // Create related content declaration return ( <div> <h2>{content.title}</h2> <p>{content.content}</p> </div> ); };src/components/ServerComponentExample.tsxCopy codeCopy the code to the clipboard
import type { FC } from "react"; import { useIntlayer } from "next-intlayer"; export const ServerComponentExample: FC = () => { const content = useIntlayer("server-component-example"); // Create related content declaration return ( <div> <h2>{content.title}</h2> <p>{content.content}</p> </div> ); };next-intlayeris isomorphic: thereact-serverexport condition, which vinext applies to its RSC environment, gives Server Components the server implementation, while Client Components get the context-backed one. The same call works on both sides.To use your content in a
stringattribute, such asalt,title,hreforaria-label, read its value:tsxCopy codeCopy the code to the clipboard
Learn more in the
useIntlayerdocumentation.If your app already exists, the Intlayer Compiler and the extract command transform thousands of components in a second.
Configure Proxy for Locale Detection
vinext runs
proxy.ts(andmiddleware.ts) like Next.js 16, in development and in production, including on Cloudflare Workers. Export the Intlayer proxy:src/proxy.tsCopy codeCopy the code to the clipboard
export { intlayerProxy as proxy } from "next-intlayer/proxy"; export const config = { matcher: "/((?!api|static|assets|robots|sitemap|sw|service-worker|manifest|.*\\..*|_next).*)", };intlayerProxydetects the user's preferred locale, redirects to the matching URL as set in the configuration, and stores the locale in a cookie. It also passes the locale togetLocale()and the server hooks, so keep it even with the without locale path architecture.To chain several proxies (for example,
intlayerProxywith authentication), usemultipleProxies:tsCopy codeCopy the code to the clipboard
Internationalisation of your metadata
Optionalvinext supports the Metadata API. Use
generateMetadatawithgetIntlayerto translate your page metadata:src/app/[locale]/metadata.content.tsCopy codeCopy the code to the clipboard
import { type Dictionary, t } from "intlayer"; import type { Metadata } from "next"; const metadataContent = { key: "page-metadata", content: { title: t({ "en-GB": "My vinext app", en: "My vinext app", fr: "Mon application vinext", es: "Mi aplicación vinext", }), description: t({ "en-GB": "A Next.js app running on Vite", en: "A Next.js app running on Vite", fr: "Une application Next.js qui tourne sur Vite", es: "Una aplicación Next.js que funciona con Vite", }), }, } satisfies Dictionary<Metadata>; export default metadataContent;src/app/[locale]/layout.tsx or src/app/[locale]/page.tsxCopy codeCopy the code to the clipboard
import { getIntlayer, getMultilingualUrls } from "intlayer"; import type { Metadata } from "next"; import type { LocalPromiseParams } from "next-intlayer"; export const generateMetadata = async ({ params, }: LocalPromiseParams): Promise<Metadata> => { const { locale } = await params; const metadata = getIntlayer("page-metadata", locale); /** * Generates an object containing all url for each locale. * * Example: * ```ts * getMultilingualUrls('/about'); * * // Returns * // { * // en: '/about', * // fr: '/fr/about', * // es: '/es/about', * // } * ``` */ const multilingualUrls = getMultilingualUrls("/"); const localizedUrl = multilingualUrls[locale as keyof typeof multilingualUrls]; return { ...metadata, alternates: { canonical: localizedUrl, languages: { ...multilingualUrls, "x-default": "/" }, }, openGraph: { url: localizedUrl, }, }; }; // ... Rest of the codeThe
getIntlayerfunction imported fromintlayerreturns raw values, ready for the metadata object. The one fromnext-intlayerwraps them for the visual editor.Internationalisation of your sitemap.xml and robots.txt
Optionalsitemap.tsandrobots.tswork as on Next.js. UsegetMultilingualUrlsto list every localised URL:src/app/sitemap.tsCopy codeCopy the code to the clipboard
import { getMultilingualUrls } from "intlayer"; import type { MetadataRoute } from "next"; const sitemap = (): MetadataRoute.Sitemap => [ { url: "https://example.com", alternates: { languages: { ...getMultilingualUrls("https://example.com"), "x-default": "https://example.com", }, }, }, { url: "https://example.com/login", alternates: { languages: { ...getMultilingualUrls("https://example.com/login"), "x-default": "https://example.com/login", }, }, }, ]; export default sitemap;src/app/robots.tsCopy codeCopy the code to the clipboard
import type { MetadataRoute } from "next"; import { getMultilingualUrls } from "intlayer"; const getAllMultilingualUrls = (urls: string[]) => urls.flatMap((url) => Object.values(getMultilingualUrls(url)) as string[]); const robots = (): MetadataRoute.Robots => ({ rules: { userAgent: "*", allow: ["/"], disallow: getAllMultilingualUrls(["/login", "/register"]), }, host: "https://example.com", sitemap: `https://example.com/sitemap.xml`, }); export default robots;Change the language of your content
OptionalUse
next/linkto navigate to the localised page. vinext keeps client-side navigation and prefetching, so the switch happens without a full reload:src/components/LocaleSwitcher.tsxCopy codeCopy the code to the clipboard
"use client"; import type { FC } from "react"; import { Locales, getHTMLTextDir, getLocaleName, getLocalizedUrl, } from "intlayer"; import { useLocale } from "next-intlayer"; import Link from "next/link"; export const LocaleSwitcher: FC = () => { const { locale, pathWithoutLocale, availableLocales, setLocale } = useLocale(); return ( <div> <button popoverTarget="localePopover">{getLocaleName(locale)}</button> <div id="localePopover" popover="auto"> {availableLocales.map((localeItem) => ( <Link href={getLocalizedUrl(pathWithoutLocale, localeItem)} key={localeItem} aria-current={locale === localeItem ? "page" : undefined} onClick={() => setLocale(localeItem)} replace // The browser "back" button returns to the previous page > <span> {/* Locale - e.g. FR */} {localeItem} </span> <span> {/* Language in its own Locale - e.g. Français */} {getLocaleName(localeItem, locale)} </span> <span dir={getHTMLTextDir(localeItem)} lang={localeItem}> {/* Language in current Locale - e.g. Francés with current locale set to Locales.SPANISH */} {getLocaleName(localeItem)} </span> <span dir="ltr" lang={Locales.ENGLISH}> {/* Language in English - e.g. French */} {getLocaleName(localeItem, Locales.ENGLISH)} </span> </Link> ))} </div> </div> ); };Documentation references:
Creating a Localised Link Component
OptionalA custom
Linkcomponent prefixes internal URLs with the current locale, so a French user clicking/aboutlands on/fr/about:src/components/Link.tsxCopy codeCopy the code to the clipboard
"use client"; import { getLocalizedUrl } from "intlayer"; import NextLink, { type LinkProps as NextLinkProps } from "next/link"; import { useLocale } from "next-intlayer"; import type { PropsWithChildren, FC } from "react"; /** * Checks whether a URL is external (starts with http:// or https://). */ export const checkIsExternalLink = (href?: string): boolean => /^https?:\/\//.test(href ?? ""); /** * Link that localizes internal URLs with the current locale. */ export const Link: FC<PropsWithChildren<NextLinkProps>> = ({ href, children, ...props }) => { const { locale } = useLocale(); const isExternalLink = checkIsExternalLink(href.toString()); const hrefI18n: NextLinkProps["href"] = href && !isExternalLink ? getLocalizedUrl(href.toString(), locale) : href; return ( <NextLink href={hrefI18n} {...props}> {children} </NextLink> ); };Get the current locale in Server Actions
OptionalCall
getLocalefromnext-intlayer/serverinside a Server Action:src/app/actions/getLocale.tsCopy codeCopy the code to the clipboard
getLocalereads the locale set by the proxy in the request headers, then the locale cookie, then the browserAccept-Languageheader, and falls back to the default locale.Deploy to Cloudflare Workers
OptionalIntlayer compiles dictionaries into the bundle at build time, so nothing reads the file system at runtime and the app runs as is in workerd. Build and deploy with the vinext CLI:
bashCopy codeCopy the code to the clipboard
To deploy elsewhere (Vercel, Netlify, AWS, Node.js), add the Nitro Vite plugin next to
vinext(), or setoutput: "standalone"innext.config.ts. The Intlayer setup does not change.Extract the content of your components
OptionalOn an existing codebase, Intlayer provides a compiler and an extractor to move hardcoded strings into content declarations.
Enable the compiler in
intlayer.config.ts:intlayer.config.tsCopy codeCopy the code to the clipboard
import { type IntlayerConfig } from "intlayer"; const config: IntlayerConfig = { // ... Rest of your config compiler: { /** * Indicates if the compiler should be enabled. */ enabled: true, /** * Defines the output files path */ output: ({ fileName, extension }) => `./${fileName}${extension}`, /** * If `true`, the compiler rewrites the component files on disk. * If `false`, the transformation stays in the build output only. */ saveComponents: false, /** * Dictionary key prefix */ dictionaryKeyPrefix: "", }, }; export default config;Run the extractor to transform your components and extract the content:
bashCopy codeCopy the code to the clipboard
The
intlayer()Vite plugin includes the compiler. Oncecompiler.enabledis set, run your dev server or build as usual:bashCopy codeCopy the code to the clipboard
Configure TypeScript
Intlayer uses module augmentation to type your content keys and values.


Include the generated types in your TypeScript configuration:
Copy the code to the clipboard
Git Configuration
Ignore the files generated by Intlayer:
Copy the code to the clipboard
VS Code Extension
Install the official Intlayer VS Code Extension for key autocompletion, missing translation errors, inline previews and quick actions. See the extension documentation.
Go Further
Add the visual editor or externalize your content with the CMS.
Frequently Asked Questions
vinext is an open source Vite plugin, maintained by Cloudflare, that reimplements the public Next.js API: App Router and Pages Router, React Server Components, Server Actions, proxy.ts, route handlers and the next/* modules. Your Next.js code runs on Vite, and deploys natively to Cloudflare Workers or to other platforms through Nitro.
Only the build integration. On Next.js, withIntlayer() wraps next.config.ts. On vinext, the intlayer() plugin from vite-intlayer goes in vite.config.ts instead. Providers, hooks, proxy.ts, metadata and sitemap code stay identical, so you can follow the Next.js 16 guide for anything this page does not cover.
No. The i18n field of next.config.ts only covers Pages Router locale prefixes on vinext, and Intlayer does its own routing through proxy.ts. The @intlayer/swc plugin is also not needed: the Vite plugin already replaces useIntlayer calls so each page ships only the dictionaries it uses. See bundle optimisation.
No. The intlayer() Vite plugin starts the content watcher with vite dev, and a content edit hot-updates only the components that read the changed dictionary.
Yes. Follow the next-intl migration guide or the i18next migration guide, or keep your current API with the compat adapters, which expose the next-intl, react-i18next and react-intl APIs served by Intlayer dictionaries.
No. routing.mode accepts:
"prefix-no-default"(default):/aboutfor the default locale,/fr/aboutfor the others."prefix-all": every locale is prefixed,/en/aboutand/fr/about."no-prefix": no locale in the path, resolved from cookie or header."search-params":/about?locale=fr.
See the configuration reference and the without locale path architecture in step 2.
