Ask your question and get a summary of the document by referencing this page and the AI provider of your choice
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 make a component multilingual (i18n) with Intlayer
This guide shows the minimal steps to make a UI component multilingual in two common setups:
- React (Vite/SPA)
- Next.js (App Router)
You will first declare your content, then retrieve it in your component.
1) Declare your content (shared for React and Next.js)
Create a content declaration file near your component. This keeps translations close to where they are used and enables type safety.
JSON is also supported if you prefer configuration files.
2) Retrieve your content
Case A. React app (Vite/SPA)
Default approach: use useIntlayer to retrieve by key. This keeps components lean and typed.
Server-side rendering or outside provider: use react-intlayer/server and pass an explicit locale when needed.
Alternative: useDictionary can read a whole declared object if you prefer collocating structure at call site.
Case B. Next.js (App Router)
Prefer server components for data safety and performance. Use useIntlayer from next-intlayer/server in server files, and useIntlayer from next-intlayer in client components.
Tip: For page metadata and SEO, you can also fetch content using getIntlayer and generate multilingual URLs via getMultilingualUrls.
Why Intlayer’s component approach is best
- Collocation: Content declarations live near components, reducing drift and improving reuse across design systems.
- Type safety: Keys and structures are strongly typed; missing translations surface at build-time rather than at runtime.
- Server-first: Works natively in server components for better security and performance; client hooks remain ergonomic.
- Tree-shaking: Only content used by the component is bundled, keeping payloads small in large apps.
- DX & tooling: Built-in middleware, SEO helpers, and optional Visual Editor/AI translations streamline everyday work.
See the comparisons and patterns in the Next.js-focused roundup: https://intlayer.org/blog/next-i18next-vs-next-intl-vs-intlayer
Related guides and references
- React setup (Vite): https://intlayer.org/doc/environment/vite-and-react
- React Router v7: https://intlayer.org/doc/environment/vite-and-react/react-router-v7
- TanStack Start: https://intlayer.org/doc/environment/tanstack-start
- Next.js setup: https://intlayer.org/doc/environment/nextjs
- Why Intlayer vs. next-intl vs. next-i18next - https://intlayer.org/blog/next-i18next-vs-next-intl-vs-intlayer
These pages include end-to-end setup, providers, routing, and SEO helpers.