Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
Version History
- Initial versionv7.0.011/1/2025
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
How to internationalize your Next.js application using next-intl in 2026
Table of Contents
What is next-intl?
next-intl is a popular internationalization (i18n) library designed specifically for Next.js App Router. It provides a seamless way to build multilingual Next.js applications with excellent TypeScript support and built-in optimizations.
If you prefer, you can also refer to the next-i18next guide, or directly using Intlayer.
See the comparison in next-i18next vs next-intl vs Intlayer.
Practices you should follow
Before we dive into the implementation, here are some practices you should follow:
- Set HTML
langanddirattributes In your layout, computedirusinggetLocaleDirection(locale)and set<html lang={locale} dir={dir}>for proper accessibility and SEO. - Split messages by namespace
Organize JSON files per locale and namespace (e.g.,
common.json,about.json) to load only what you need. - Minimize client payload
On pages, send only required namespaces to
NextIntlClientProvider(e.g.,pick(messages, ['common', 'about'])). - Prefer static pages Use static page as much as possible for better performance and SEO.
- I18n in server components
Server components, like pages or all components not marked as
clientare statics and can be pre-rendered at build time. So we will have to pass the translation functions to them as props. - Set up TypeScript types For your locales to ensure type safety throughout your application.
- Proxy for redirection Use a proxy to handle the locale detection and routing and redirect the user to the appropriate locale-prefixed URL.
- Internationalization of your metadata, sitemap, robots.txt
Internationalize your metadata, sitemap, robots.txt using the
generateMetadatafunction provided by Next.js to ensure a better discovery by search engines in all locales. - Localize Links
Localize Links using the
Linkcomponent to redirect the user to the appropriate locale-prefixed URL. It's important to ensure the discovery of your pages in all locales. - Automate tests and translations Automate tests and translations help loosing time to maintain your multilingual application.
See our doc listing everything you need to know about internationalization and SEO: Internationalization (i18n) with next-intl.
Step-by-Step Guide to Set Up next-intl in a Next.js Application
See Application Template on GitHub.
Here's the project structure we'll be creating:
Copy the code to the clipboard
Install Dependencies
Install the necessary packages using npm:
bashCopy codeCopy the code to the clipboard
- next-intl: The core internationalization library for Next.js App Router that provides hooks, server functions, and client providers for managing translations.
Configure Your Project
Create a configuration file that defines your supported locales and sets up next-intl's request configuration. This file serves as the single source of truth for your i18n setup and ensures type safety throughout your application.
Centralizing your locale configuration prevents inconsistencies and makes it easier to add or remove locales in the future. The
getRequestConfigfunction runs on every request and loads only the translations needed for each page, enabling code-splitting and reducing bundle size.src/i18n.tsCopy codeCopy the code to the clipboard
Define Dynamic Locale Routes
Set up dynamic routing for locales by creating a
[locale]directory in your app folder. This allows Next.js to handle locale-based routing where each locale becomes a URL segment (e.g.,/en/about,/fr/about).Using dynamic routes enables Next.js to generate static pages for all locales at build time, improving performance and SEO. The layout component sets the HTML
langanddirattributes based on the locale, which is crucial for accessibility and search engine understanding.src/app/[locale]/layout.tsxCopy codeCopy the code to the clipboard
src/app/[locale]/about/page.tsxCopy codeCopy the code to the clipboard
Create Your Translation Files
Create JSON files for each locale and namespace. This structure allows you to organize translations logically and load only what you need for each page.
Organizing translations by namespace (e.g.,
common.json,about.json) enables code splitting and reduces bundle size. You only load the translations needed for each page, improving performance.locales/en/common.jsonCopy codeCopy the code to the clipboard
locales/fr/common.jsonCopy codeCopy the code to the clipboard
locales/en/about.jsonCopy codeCopy the code to the clipboard
locales/fr/about.jsonCopy codeCopy the code to the clipboard
Utilize Translations in Your Pages
Create a page component that loads translations on the server and passes them to both server and client components. This ensures that translations are loaded before rendering and prevents content flashing.
Server-side loading of translations improves SEO and prevents FOUC (Flash of Untranslated Content). By using
pickto send only required namespaces to the client provider, we minimize the JavaScript bundle sent to the browser.src/app/[locale]/about/page.tsxCopy codeCopy the code to the clipboard
Use Translations in Client Components
Client components can use the
useTranslationsanduseFormatterhooks to access translations and formatting functions. These hooks read from theNextIntlClientProvidercontext.Client components need React hooks to access translations. The
useTranslationsanduseFormatterhooks integrate seamlessly with next-intl and provide reactive updates when the locale changes.Don't forget to add the required namespaces to the page's client messages (only include the namespaces your client components actually need).
src/components/ClientComponent.tsxCopy codeCopy the code to the clipboard
Use Translations in Server Components
Server components cannot use React hooks, so they receive translations and formatters via props from their parent components. This approach keeps server components synchronous and allows them to be nested inside client components.
Server components that might be nested under client boundaries need to be synchronous. By passing translated strings and formatted values as props, we avoid async operations and ensure proper rendering. Pre-compute translations and formatting in the parent page component.
src/components/ServerComponent.tsxCopy codeCopy the code to the clipboard
In your page/layout, use
getTranslationsandgetFormatterfromnext-intl/serverto pre-compute translations and formatting, then pass them as props to server components.Change the language of your content
OptionalTo change the language of your content with next-intl, render locale-aware links that point to the same pathname while switching locale. The provider rewrites URLs automatically, so you only have to target the current route.
src/components/LocaleSwitcher.tsxCopy codeCopy the code to the clipboard
Use the localized Link component
Optionalnext-intlprovides a subpackagenext-intl/navigationthat contains a localized link component that automatically applies the active locale. We already extracted it for you in the@/i18nfile, so you can use it like this:src/components/MyComponent.tsxCopy codeCopy the code to the clipboard
Access the active locale inside Server Actions
OptionalServer Actions can read the current locale using
next-intl/server. This is useful for sending localized emails or storing language preferences alongside submitted data.src/app/actions/get-current-locale.tsCopy codeCopy the code to the clipboard
getLocalereads the locale set bynext-intlproxy, so it works anywhere on the server: Route Handlers, Server Actions, and edge functions.Internationalize Your Metadata
OptionalTranslating content is important, but the main goal of internationalization is to make your website more visible to the world. I18n is an incredible lever to improve your website visibility through proper SEO.
Properly internationalized metadata helps search engines understand what languages are available on your pages. This includes setting hreflang meta tags, translating titles and descriptions, and ensuring canonical URLs are correctly set for each locale.
src/app/[locale]/about/layout.tsxCopy codeCopy the code to the clipboard
Internationalize Your Sitemap
OptionalGenerate a sitemap that includes all locale versions of your pages. This helps search engines discover and index all language versions of your content.
A properly internationalized sitemap ensures search engines can find and index all language versions of your pages. This improves visibility in international search results.
src/app/sitemap.tsCopy codeCopy the code to the clipboard
Internationalize Your robots.txt
OptionalCreate a robots.txt file that properly handles all locale versions of your protected routes. This ensures that search engines don't index admin or dashboard pages in any language.
Properly configuring robots.txt for all locales prevents search engines from indexing sensitive pages when your routes are different for each locale.
src/app/robots.tsCopy codeCopy the code to the clipboard
Set Up Proxy for Locale Routing
OptionalCreate a proxy to automatically detect the user's preferred locale and redirect them to the appropriate locale-prefixed URL. next-intl provides a convenient proxy function that handles this automatically.
Proxy ensures that users are automatically redirected to their preferred language when they visit your site. It also saves the user's preference for future visits, improving user experience.
src/proxy.tsCopy codeCopy the code to the clipboard
Set Up TypeScript Types for the Locale
OptionalSetting up TypeScript will help you to get autocompletion and type safety for your keys.
For that, you can create a global.ts file in your project root and add the following code:
global.tsCopy codeCopy the code to the clipboard
This code will use Module Augmentation to add the locales and messages to the next-intl AppConfig type.
Automate Your Translations Using Intlayer
OptionalIntlayer is a free and open-source library designed to assist the localization process in your application. While next-intl handles the translation loading and management, Intlayer helps automate the translation workflow.
Managing translations manually can be time-consuming and error-prone. Intlayer automates translation testing, generation, and management, saving you time and ensuring consistency across your application.
Intlayer will allows your to:
Declare your content where you want in your codebase Intlayer allows to declare your content where you want in your codebase using
.content.{ts|js|json}files. It will allow a better organization of your content, ensuring better readability and maintainability of your codebase.Test missing translations Intlayer provide test functions to that can be integrated in your CI/CD pipeline, or in your unit tests. Learn more about testing your translations.
Automate your translations, Intlayer provide a CLI and a VSCode extension to automate your translations. It can be integrated in your CI/CD pipeline. Learn more about automating your translations. You can use your own API key, and the AI provider of your choice. It also provide context aware translations, see fill content.
Connect external content Intlayer allows you to connect your content to an external content management system (CMS). To fetch it in a optimized way and insert it in your JSON resources. Learn more about fetching external content.
Visual editor Intlayer offers an free visual editor to edit your content using a visual editor. Learn more about visual editing your translations.
And more. To discover all the features provided by Intlayer, please refer to the Interest of Intlayer documentation.
Comments
No comments yet. Be the first to share your thoughts.