Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
Version History
- "Update Solid useIntlayer API usage to direct property access"v8.9.05/4/2026
- "Initial release"v8.0.01/10/2026
If 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 Next.js 16 website (without [locale] in the page path) using Intlayer | Internationalization (i18n)
See Application Template on GitHub.
Table of Contents
Why Intlayer over alternatives?
Compared to main solutions like next-intl or i18next, Intlayer is a solution that comes with integrated optimizations such as:
Intlayer is optimized to work with Server Components for efficient rendering and is fully compatible with Turbopack. It does not block static rendering and offers middleware as well as all the features needed for scaling internationalization (i18n).
Intlayer is compatible with Next.js 12, 13, 14, 15, and 16. If you are using the Next.js Pages Router, you can refer to this guide. Locale routing is useful for SEO, bundle size, and performance. If you don't need it, you can refer to this guide. For Next.js 12, 13, 14, and 15 with the App Router, refer to this guide.
Instead of loading massive JSON files into your pages, load only the necessary content. Intlayer helps reduce your bundle and page sizes by up to 50%.
Scoping your application's content facilitates maintenance for large-scale applications. You can duplicate or delete a single feature folder without the mental burden of reviewing your entire content codebase. Additionally, Intlayer is fully typed to ensure your content's accuracy.
Co-locating content reduces the context needed by Large Language Models (LLMs). Intlayer also comes with a suite of tools, such as a CLI to test for missing translations,LSP, MCP, and agent skills, to make the developer experience (DX) even smoother for AI agents.
Use automation to translate in your CI/CD pipeline using the LLM of your choice at the cost of your AI provider. Intlayer also offers a compiler to automate content extraction, as well as a web platform to help translate in the background.
Connecting massive JSON files to components can lead to performance and reactivity issues. Intlayer optimizes your content loading at build time.
More than just an i18n solution, Intlayer provides an self-hosted visual editor and a full CMS to help you manage your multilingual content in real-time, making collaboration with translators, copywriters, and other team members seamless. Content can be stored locally and/or remotely.
Step-by-Step Guide to Set Up Intlayer in a Next.js Application
Install Dependencies
Install the necessary packages using npm:
bashCopy codeCopy the code to the clipboard
npm install intlayer next-intlayernpx intlayer initintlayer
The core package that provides internationalization tools for configuration management, translation, content declaration, transpilation, and CLI commands.
next-intlayer
The package that integrates Intlayer with Next.js. It provides context providers and hooks for Next.js internationalization. Additionally, it includes the Next.js plugin for integrating Intlayer with Webpack or Turbopack, as well as proxy for detecting the user's preferred locale, managing cookies, and handling URL redirection.
Configure Your Project
Here is the final structure that we will make:
bashCopy codeCopy the code to the clipboard
.├── src│ ├── app│ │ ├── layout.tsx│ │ ├── page.content.ts│ │ └── page.tsx│ ├── components│ │ ├── clientComponentExample│ │ │ ├── client-component-example.content.ts│ │ │ └── ClientComponentExample.tsx│ │ ├── localeSwitcher│ │ │ ├── localeSwitcher.content.ts│ │ │ └── LocaleSwitcher.tsx│ │ └── serverComponentExample│ │ ├── server-component-example.content.ts│ │ └── ServerComponentExample.tsx│ └── proxy.ts├── intlayer.config.ts├── next.config.ts├── package.json└── tsconfig.jsonIf you don't want locale routing, intlayer can be used as a simple provider / hook. See this guide for more details.
Create a config file to configure the languages of your application:
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` - Useful for middleware detection }, }; export default config;Through this configuration file, you can set up localized URLs, proxy redirection, cookie names, the location and extension of your content declarations, disable Intlayer logs in the console, and more. For a complete list of available parameters, refer to the configuration documentation.
Integrate Intlayer in Your Next.js Configuration
Configure your Next.js setup to use Intlayer:
next.config.tsCopy codeCopy the code to the clipboard
import type { NextConfig } from "next"; import { withIntlayer } from "next-intlayer/server"; const nextConfig: NextConfig = { /* config options here */ }; export default withIntlayer(nextConfig);The
withIntlayer()Next.js plugin is used to integrate Intlayer with Next.js. It ensures the building of content declaration files and monitors them in development mode. It defines Intlayer environment variables within the Webpack or Turbopack environments. Additionally, it provides aliases to optimize performance and ensures compatibility with server components.The
withIntlayer()function is a promise function. It allows to prepare the intlayer dictionaries before the build starts. If you want to use it with other plugins, you can await it. Example:tsCopy codeCopy the code to the clipboard
const nextConfig = await withIntlayer(nextConfig);const nextConfigWithOtherPlugins = withOtherPlugins(nextConfig);export default nextConfigWithOtherPlugins;If you want to use it synchronously, you can use the
withIntlayerSync()function. Example:tsCopy codeCopy the code to the clipboard
const nextConfig = withIntlayerSync(nextConfig);const nextConfigWithOtherPlugins = withOtherPlugins(nextConfig);export default nextConfigWithOtherPlugins;Intlayer automatically detects whether your project is using webpack or Turbopack based on the command-line flags
--webpack,--turbo, or--turbopack, as well as your current Next.js version.Since
next>=16, if you are using Rspack, you must explicitly force Intlayer to use the webpack configuration by disabling Turbopack:tsCopy codeCopy the code to the clipboard
withRspack(withIntlayer(nextConfig, { enableTurbopack: false }));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 { Metadata } from "next"; import type { ReactNode } from "react"; import "./globals.css"; import { IntlayerClientProvider, LocalPromiseParams } from "next-intlayer"; import { getHTMLTextDir, getIntlayer } from "intlayer"; import { getLocale } from "next-intlayer/server"; export { generateStaticParams } from "next-intlayer"; 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)}> <IntlayerClientProvider defaultLocale={locale}> <body>{children}</body> </IntlayerClientProvider> </html> ); }; export default RootLayout;Declare Your Content
Create and manage your content declarations to store translations:
src/app/metadata.content.tsCopy codeCopy the code to the clipboard
import { t, type Dictionary } from "intlayer"; import { Metadata } from "next"; const metadataContent = { key: "metadata", content: { title: t({ en: "My Project Title", fr: "Le Titre de mon Projet", es: "El Título de mi Proyecto", }), description: t({ en: "Discover our innovative platform designed to streamline your workflow and boost productivity.", fr: "Découvrez notre plateforme innovante conçue pour simplifier votre flux de travail et booster votre productivité.", es: "Descubra nuestra plataforma innovadora diseñada para simplificar su flujo de trabajo y aumentar su productividad.", }), keywords: t({ en: ["innovation", "productivity", "workflow", "SaaS"], fr: ["innovation", "productivité", "flux de travail", "SaaS"], es: ["innovación", "productividad", "flujo de trabajo", "SaaS"], }), }, } as Dictionary<Metadata>; export default metadataContent;src/app/page.content.tsCopy codeCopy the code to the clipboard
import { t, type Dictionary } from "intlayer"; const pageContent = { key: "page", content: { getStarted: { main: t({ en: "Get started by editing", fr: "Commencez par éditer", es: "Comience por editar", }), pageLink: "src/app/page.tsx", }, }, } satisfies Dictionary; export default pageContent;Your content declarations can be defined anywhere in your application as soon they are included into the
contentDirdirectory (by default,./src). And match the content declaration file 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 content dictionaries throughout your application:
src/app/page.tsxCopy codeCopy the code to the clipboard
import type { FC } from "react"; import { ClientComponentExample } from "@components/clientComponentExample/ClientComponentExample"; import { ServerComponentExample } from "@components/serverComponentExample/ServerComponentExample"; import { IntlayerServerProvider, useIntlayer, getLocale, } from "next-intlayer/server"; import { NextPage } from "next"; import { headers, cookies } from "next/headers"; const PageContent: FC = () => { const content = useIntlayer("page"); return ( <> <p>{content.getStarted.main}</p> <code>{content.getStarted.pageLink}</code> </> ); }; const Page: NextPage = async () => { const locale = await getLocale(); return ( <IntlayerServerProvider locale={locale}> <PageContent /> <ServerComponentExample /> <ClientComponentExample /> </IntlayerServerProvider> ); }; export default Page;IntlayerClientProvideris used to provide the locale to client-side components. It can be placed in any parent component, including the layout. However, placing it in a layout is recommended because Next.js shares layout code across pages, making it more efficient. By usingIntlayerClientProviderin the layout, you avoid reinitializing it for every page, improving performance and maintaining a consistent localization context throughout your application.IntlayerServerProvideris used to provide the locale to the server children. It cannot be set set in the layout.Layout and page cannot share a common server context because the server context system is based on a per-request data store (via React's cache mechanism), causing each "context" to be re-created for different segments of the application. Placing the provider in a shared layout would break this isolation, preventing the correct propagation of the server context values to your server components.
src/components/clientComponentExample/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/ServerComponentExample.tsxCopy codeCopy the code to the clipboard
import type { FC } from "react"; import { useIntlayer } from "next-intlayer/server"; 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> ); };If you want to use your content in a
stringattribute, such asalt,title,href,aria-label, etc., you can use the value of the function, like:htmlCopy codeCopy the code to the clipboard
<img src="{content.image.src.value}" alt="{content.image.value}" /><img src="{content.image.src.toString()}" alt="{content.image.toString()}" /><img src="{String(content.image.src)}" alt="{String(content.image)}" />To Learn more about the
useIntlayerhook, refer to the documentation.Configure Proxy for Locale Detection
OptionalSet up proxy to detect the user's preferred locale:
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).*)", };The
intlayerProxyis used to detect the user's preferred locale and redirect them to the appropriate URL as specified in the configuration. Additionally, it enables saving the user's preferred locale in a cookie.If you need to chain several proxies together (for example,
intlayerProxywith authentication or custom proxies), Intlayer now provides a helper calledmultipleProxies.tsCopy codeCopy the code to the clipboard
import { multipleProxies, intlayerProxy } from "next-intlayer/proxy";import { customProxy } from "@utils/customProxy";export const proxy = multipleProxies([intlayerProxy, customProxy]);Change the language of your content
OptionalTo change the language of your content in Next.js, the recommended way is to use the
Linkcomponent to redirect users to the appropriate localized page. TheLinkcomponent enables prefetching of the page, which helps avoid a full page reload.src/components/localeSwitcher/LocaleSwitcher.tsxCopy codeCopy the code to the clipboard
"use client"; import type { FC } from "react"; import { Locales, getHTMLTextDir, getLocaleName } from "intlayer"; import { useLocale } from "next-intlayer"; export const LocaleSwitcher: FC = () => { const { locale, availableLocales, setLocale } = useLocale(); return ( <div> <button popoverTarget="localePopover">{getLocaleName(locale)}</button> <div id="localePopover" popover="auto"> {availableLocales.map((localeItem) => ( <button key={localeItem} aria-current={locale === localeItem ? "page" : undefined} onClick={() => setLocale(localeItem)} > <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> </button> ))} </div> </div> ); };An alternative way is to use the
setLocalefunction provided by theuseLocalehook. This function will not allow prefetching the page. See theuseLocalehook documentation for more details.Documentation references:
Get the current locale in Server Actions
OptionalIf you need the active locale inside a Server Action (e.g., to localize emails or run locale-aware logic), call
getLocalefromnext-intlayer/server:src/app/actions/getLocale.tsCopy codeCopy the code to the clipboard
"use server";import { getLocale } from "next-intlayer/server";export const myServerAction = async () => { const locale = await getLocale(); // Do something with the locale};The
getLocalefunction follows a cascading strategy to determine the user's locale:- First, it checks the request headers for a locale value that may have been set by the proxy
- If no locale is found in headers, it looks for a locale stored in cookies
- If no cookie is found, it attempts to detect the user's preferred language from their browser settings
- As a last resort, it falls back to the application's configured default locale
This ensures the most appropriate locale is selected based on available context.
Optimize your bundle size
OptionalWhen using
next-intlayer, dictionaries are included in the bundle for every page by default. To optimize bundle size, Intlayer provides an optional SWC plugin that intelligently replaceuseIntlayercalls using macros. This ensures dictionaries are only included in bundles for pages that actually use them.To enable this optimization, install the
@intlayer/swcpackage. Once installed,next-intlayerwill automatically detect and use the plugin:bashCopy codeCopy the code to the clipboard
npm install @intlayer/swc --save-devNote: This optimization is only available for Next.js 13 and above.
Note: This package is not installed by default because SWC plugins are still experimental on Next.js. It may change in the future.
Note: If you set the option as
importMode: 'dynamic'orimportMode: 'fetch'(in thedictionaryconfiguration), it will rely on Suspense, so you will have to wrap youruseIntlayercalls in aSuspenseboundary. That means, you will not be able to use theuseIntlayerdirectly at the top level of your Page / Layout component.
Watch dictionaries changes on Turbopack
When using Turbopack as your development server with the next dev command, dictionary changes will not be automatically detected by default.
This limitation occurs because Turbopack cannot run webpack plugins in parallel to monitor changes in your content files. To work around this, you'll need to use the intlayer watch command to run both the development server and the Intlayer build watcher simultaneously.
Copy the code to the clipboard
{ // ... Your existing package.json configurations "scripts": { // ... Your existing scripts configurations "dev": "intlayer watch --with 'next dev'", },}If you are using next-intlayer@<=6.x.x, you need to keep the --turbopack flag to make the Next.js 16 application work correctly with Turbopack. We recommend using next-intlayer@>=7.x.x to avoid this limitation.
Configure TypeScript
Intlayer use module augmentation to get benefits of TypeScript and make your codebase stronger.


Ensure your TypeScript configuration includes the autogenerated types.
Copy the code to the clipboard
{ // ... Your existing TypeScript configurations "include": [ // ... Your existing TypeScript configurations ".intlayer/**/*.ts", // Include the auto-generated types ],}Git Configuration
It is recommended to ignore the files generated by Intlayer. This allows you to avoid committing them to your Git repository.
To do this, you can add the following instructions to your .gitignore file:
Copy the code to the clipboard
# Ignore the files generated by Intlayer.intlayerVS Code Extension
To improve your development experience with Intlayer, you can install the official Intlayer VS Code Extension.
Install from the VS Code Marketplace
This extension provides:
- Autocompletion for translation keys.
- Real-time error detection for missing translations.
- Inline previews of translated content.
- Quick actions to easily create and update translations.
For more details on how to use the extension, refer to the Intlayer VS Code Extension documentation.
Go Further
To go further, you can implement the visual editor or externalize your content using the CMS.