@intlayer/docs 6.1.3 → 6.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/blog/ar/next-i18next_vs_next-intl_vs_intlayer.md +1135 -75
- package/blog/ar/nextjs-multilingual-seo-comparison.md +364 -0
- package/blog/de/next-i18next_vs_next-intl_vs_intlayer.md +1139 -72
- package/blog/de/nextjs-multilingual-seo-comparison.md +362 -0
- package/blog/en/next-i18next_vs_next-intl_vs_intlayer.md +1103 -36
- package/blog/en/nextjs-multilingual-seo-comparison.md +360 -0
- package/blog/en-GB/next-i18next_vs_next-intl_vs_intlayer.md +1134 -37
- package/blog/en-GB/nextjs-multilingual-seo-comparison.md +360 -0
- package/blog/es/next-i18next_vs_next-intl_vs_intlayer.md +1122 -64
- package/blog/es/nextjs-multilingual-seo-comparison.md +363 -0
- package/blog/fr/next-i18next_vs_next-intl_vs_intlayer.md +1132 -75
- package/blog/fr/nextjs-multilingual-seo-comparison.md +362 -0
- package/blog/hi/nextjs-multilingual-seo-comparison.md +363 -0
- package/blog/it/next-i18next_vs_next-intl_vs_intlayer.md +1120 -55
- package/blog/it/nextjs-multilingual-seo-comparison.md +363 -0
- package/blog/ja/next-i18next_vs_next-intl_vs_intlayer.md +1140 -76
- package/blog/ja/nextjs-multilingual-seo-comparison.md +362 -0
- package/blog/ko/next-i18next_vs_next-intl_vs_intlayer.md +1129 -73
- package/blog/ko/nextjs-multilingual-seo-comparison.md +362 -0
- package/blog/pt/next-i18next_vs_next-intl_vs_intlayer.md +1133 -76
- package/blog/pt/nextjs-multilingual-seo-comparison.md +362 -0
- package/blog/ru/next-i18next_vs_next-intl_vs_intlayer.md +1142 -74
- package/blog/ru/nextjs-multilingual-seo-comparison.md +370 -0
- package/blog/tr/nextjs-multilingual-seo-comparison.md +362 -0
- package/blog/zh/next-i18next_vs_next-intl_vs_intlayer.md +1142 -75
- package/blog/zh/nextjs-multilingual-seo-comparison.md +394 -0
- package/dist/cjs/generated/blog.entry.cjs +16 -0
- package/dist/cjs/generated/blog.entry.cjs.map +1 -1
- package/dist/esm/generated/blog.entry.mjs +16 -0
- package/dist/esm/generated/blog.entry.mjs.map +1 -1
- package/dist/types/generated/blog.entry.d.ts +1 -0
- package/dist/types/generated/blog.entry.d.ts.map +1 -1
- package/docs/en/interest_of_intlayer.md +2 -1
- package/package.json +10 -10
- package/src/generated/blog.entry.ts +16 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
createdAt: 2025-08-23
|
|
3
|
-
updatedAt: 2025-
|
|
3
|
+
updatedAt: 2025-09-29
|
|
4
4
|
title: next-i18next vs next-intl vs Intlayer
|
|
5
5
|
description: Compare next-i18next with next-intl and Intlayer for the internationalization (i18n) of a Next.js app
|
|
6
6
|
keywords:
|
|
@@ -19,7 +19,10 @@ slugs:
|
|
|
19
19
|
|
|
20
20
|
# next-i18next VS next-intl VS intlayer | Next.js Internationalization (i18n)
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
Let’s take a look into the similarities and differences between three i18n options for Next.js: next-i18next, next-intl, and Intlayer.
|
|
23
|
+
|
|
24
|
+
This is not a full tutorial. It’s a comparison to help you pick.
|
|
25
|
+
|
|
23
26
|
We focus on **Next.js 13+ App Router** (with **React Server Components**) and evaluate:
|
|
24
27
|
|
|
25
28
|
1. **Architecture & content organization**
|
|
@@ -32,9 +35,11 @@ We focus on **Next.js 13+ App Router** (with **React Server Components**) and ev
|
|
|
32
35
|
|
|
33
36
|
> **tl;dr**: All three can localize a Next.js app. If you want **component-scoped content**, **strict TypeScript types**, **build-time missing-key checks**, **tree-shaken dictionaries**, and **first-class App Router + SEO helpers**, **Intlayer** is the most complete, modern choice.
|
|
34
37
|
|
|
38
|
+
> One confusion often made by developers is to think that `next-intl` is the Next.js version of `react-intl`. It's not—`next-intl` is maintained by [Amann](https://github.com/amannn), while `react-intl` is maintained by [FormatJS](https://github.com/formatjs/formatjs).
|
|
39
|
+
|
|
35
40
|
---
|
|
36
41
|
|
|
37
|
-
##
|
|
42
|
+
## In short
|
|
38
43
|
|
|
39
44
|
- **next-intl** - Lightweight, straightforward message formatting with solid Next.js support. Centralized catalogs are common; DX is simple, but safety and large-scale maintenance remain mostly your responsibility.
|
|
40
45
|
- **next-i18next** - i18next in Next.js clothing. Mature ecosystem and features via plugins (e.g., ICU), but configuration can be verbose and catalogs tend to centralize as projects grow.
|
|
@@ -42,6 +47,17 @@ We focus on **Next.js 13+ App Router** (with **React Server Components**) and ev
|
|
|
42
47
|
|
|
43
48
|
---
|
|
44
49
|
|
|
50
|
+
| Library | GitHub Stars | Total Commits | Last Commit | First Version | NPM Version | NPM Downloads |
|
|
51
|
+
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
|
|
52
|
+
| `aymericzip/intlayer` | [](https://github.com/aymericzip/intlayer/stargazers) | [](https://github.com/aymericzip/intlayer/commits) | [](https://github.com/aymericzip/intlayer/commits) | April 2024 | [](https://www.npmjs.com/package/intlayer) | [](https://www.npmjs.com/package/intlayer) |
|
|
53
|
+
| `amannn/next-intl` | [](https://github.com/amannn/next-intl/stargazers) | [](https://github.com/amannn/next-intl/commits) | [](https://github.com/amannn/next-intl/commits) | Nov 2020 | [](https://www.npmjs.com/package/next-intl) | [](https://www.npmjs.com/package/next-intl) |
|
|
54
|
+
| `i18next/i18next` | [](https://github.com/i18next/i18next/stargazers) | [](https://github.com/i18next/i18next/commits) | [](https://github.com/i18next/i18next/commits) | Jan 2012 | [](https://www.npmjs.com/package/i18next) | [](https://www.npmjs.com/package/i18next) |
|
|
55
|
+
| `i18next/next-i18next` | [](https://github.com/i18next/next-i18next/stargazers) | [](https://github.com/i18next/next-i18next/commits) | [](https://github.com/i18next/next-i18next/commits) | Nov 2018 | [](https://www.npmjs.com/package/next-i18next) | [](https://www.npmjs.com/package/next-i18next) |
|
|
56
|
+
|
|
57
|
+
> Badges update automatically. Snapshots will vary over time.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
45
61
|
## Side-by-Side Feature Comparison (Next.js focused)
|
|
46
62
|
|
|
47
63
|
| Feature | `next-intlayer` (Intlayer) | `next-intl` | `next-i18next` |
|
|
@@ -62,15 +78,22 @@ We focus on **Next.js 13+ App Router** (with **React Server Components**) and ev
|
|
|
62
78
|
| **Ecosystem / Community** | ⚠️ Smaller but growing fast and reactive | ✅ Good | ✅ Good |
|
|
63
79
|
| **Server-side Rendering & Server Components** | ✅ Yes, streamlined for SSR / React Server Components | ⚠️ Supported at page level but need to pass t-functions on component tree for children server components | ⚠️ Supported at page level but need to pass t-functions on component tree for children server components |
|
|
64
80
|
| **Tree-shaking (load only used content)** | ✅ Yes, per-component at build time via Babel/SWC plugins | ⚠️ Partial | ⚠️ Partial |
|
|
65
|
-
| **Lazy loading** | ✅ Yes, per-locale / per-dictionary | ✅ Yes (per-route/per-locale), need
|
|
81
|
+
| **Lazy loading** | ✅ Yes, per-locale / per-dictionary | ✅ Yes (per-route/per-locale), need namespace management | ✅ Yes (per-route/per-locale), need namespace management |
|
|
66
82
|
| **Purge unused content** | ✅ Yes, per-dictionary at build time | ❌ No, can be managed manually with namespace management | ❌ No, can be managed manually with namespace management |
|
|
67
83
|
| **Management of Large Projects** | ✅ Encourages modular, suited for design-system | ✅ Modular with setup | ✅ Modular with setup |
|
|
84
|
+
| **Testing Missing Translations (CLI/CI)** | ✅ CLI: `npx intlayer content test` (CI-friendly audit) | ⚠️ Not built-in; docs suggest `npx @lingual/i18n-check` | ⚠️ Not built-in; rely on i18next tools / runtime `saveMissing` |
|
|
68
85
|
|
|
69
86
|
---
|
|
70
87
|
|
|
71
|
-
##
|
|
88
|
+
## Introduction
|
|
72
89
|
|
|
73
|
-
|
|
90
|
+
Next.js gives you built-in support for internationalized routing (e.g. locale segments). But that feature doesn’t do translations on its own. You still need a library to render localized content to your users.
|
|
91
|
+
|
|
92
|
+
Many i18n libraries exist, but in the Next.js world today, three are gaining traction: next-i18next, next-intl, and Intlayer.
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## Architecture & scalability
|
|
74
97
|
|
|
75
98
|
- **next-intl / next-i18next**: Default to **centralized catalogs** per locale (plus **namespaces** in i18next). Works fine early on, but often becomes a big shared surface area with rising coupling and key churn.
|
|
76
99
|
- **Intlayer**: Encourages **per-component** (or per-feature) dictionaries **co-located** with the code they serve. This lowers cognitive load, eases duplication/migration of UI pieces, and reduces cross-team conflicts. Unused content is naturally easier to spot and purge.
|
|
@@ -79,79 +102,1123 @@ We focus on **Next.js 13+ App Router** (with **React Server Components**) and ev
|
|
|
79
102
|
|
|
80
103
|
---
|
|
81
104
|
|
|
82
|
-
|
|
105
|
+
## Bundle sizes & dependencies
|
|
106
|
+
|
|
107
|
+
After building the application, the bundle is the JavaScript that the browser will load to render the page. Bundle size is therefore important for application performance.
|
|
108
|
+
|
|
109
|
+
Two components are important in the context of a multi-language application bundle:
|
|
110
|
+
|
|
111
|
+
- The application code
|
|
112
|
+
- The content loaded by the browser
|
|
113
|
+
|
|
114
|
+
## Application Code
|
|
115
|
+
|
|
116
|
+
The importance of application code is minimal in this case. All three solutions are tree-shakable, meaning that unused parts of the code are not included in the bundle.
|
|
117
|
+
|
|
118
|
+
Here's a comparison of the JavaScript bundle size loaded by the browser for a multi-language application with the three solutions.
|
|
119
|
+
|
|
120
|
+
If we don't need any formatter in the application, the list of exported functions after tree-shaking will be:
|
|
121
|
+
|
|
122
|
+
- **next-intlayer**: `useIntlayer`, `useLocale`, `NextIntlClientProvider`, (Bundle size is 180.6 kB -> 78.6 kB (gzip))
|
|
123
|
+
- **next-intl**: `useTranslations`, `useLocale`, `NextIntlClientProvider`, (Bundle size is 101.3 kB -> 31.4 kB (gzip))
|
|
124
|
+
- **next-i18next**: `useTranslation`, `useI18n`, `I18nextProvider`, (Bundle size is 80.7 kB -> 25.5 kB (gzip))
|
|
125
|
+
|
|
126
|
+
These functions are only wrappers around React context/state, so the total impact of the i18n library on bundle size is minimal.
|
|
127
|
+
|
|
128
|
+
> Intlayer is slightly bigger than `next-intl` and `next-i18next` because it includes more logic in the `useIntlayer` function. This is related to markdown and `intlayer-editor` integration.
|
|
129
|
+
|
|
130
|
+
## Content and Translations
|
|
131
|
+
|
|
132
|
+
This part is often ignored by developers, but let's consider the case of an application composed of 10 pages in 10 languages. Let's assume that each page integrates 100% unique content to simplify the calculation (in reality, much content is redundant between pages, e.g., page title, header, footer, etc.).
|
|
133
|
+
|
|
134
|
+
A user wanting to visit the `/fr/about` page will load the content of one page in a given language. Ignoring content optimization would mean loading 8,200% `((1 + (((10 pages - 1) × (10 languages - 1)))) × 100)` of the application content unnecessarily. Do you see the problem? Even if this content remains text, and while you probably prefer to think about optimizing your site's images, you're sending useless content across the globe and making users' computers process it for nothing.
|
|
135
|
+
|
|
136
|
+
Two important issues:
|
|
137
|
+
|
|
138
|
+
- **Splitting by route:**
|
|
139
|
+
|
|
140
|
+
> If I'm on the `/about` page, I don't want to load the content of the `/home` page
|
|
141
|
+
|
|
142
|
+
- **Splitting by locale:**
|
|
143
|
+
|
|
144
|
+
> If I'm on the `/fr/about` page, I don't want to load the content of the `/en/about` page
|
|
145
|
+
|
|
146
|
+
Again, all three solutions are aware of these issues and allow managing these optimizations. The difference between the three solutions is the DX (Developer Experience).
|
|
147
|
+
|
|
148
|
+
`next-intl` and `next-i18next` use a centralized approach to manage translations, allowing splitting JSON by locale and by sub-files. In `next-i18next`, we call the JSON files 'namespaces'; `next-intl` allows declaring messages. In `intlayer`, we call the JSON files 'dictionaries'.
|
|
149
|
+
|
|
150
|
+
- In the case of `next-intl`, like `next-i18next`, content is loaded at the page/layout level, then this content is loaded into a context provider. This means the developer must manually manage the JSON files that will be loaded for each page.
|
|
151
|
+
|
|
152
|
+
> In practice, this implies that developers often skip this optimization, preferring to load all content in the page's context provider for simplicity.
|
|
153
|
+
|
|
154
|
+
- In the case of `intlayer`, all content is loaded in the application. Then a plugin (`@intlayer/babel` / `@intlayer/swc`) takes care of optimizing the bundle by loading only the content used on the page. The developer therefore doesn't need to manually manage the dictionaries that will be loaded. This allows better optimization, better maintainability, and reduces development time.
|
|
155
|
+
|
|
156
|
+
As the application grows (especially when multiple developers work on the application), it's common to forget to remove content that's no longer used from JSON files.
|
|
157
|
+
|
|
158
|
+
> Note that all JSON is loaded in all cases (next-intl, next-i18next, intlayer).
|
|
159
|
+
|
|
160
|
+
This is why Intlayer's approach is more performant: if a component is no longer used, its dictionary is not loaded in the bundle.
|
|
161
|
+
|
|
162
|
+
How the library handles fallbacks is also important. Let's consider that the application is in English by default, and the user visits the `/fr/about` page. If translations are missing in French, we'll consider the English fallback.
|
|
163
|
+
|
|
164
|
+
In the case of `next-intl` and `next-i18next`, the library requires loading the JSON related to the current locale, but also to the fallback locale. Thus, considering that all content has been translated, each page will load 100% unnecessary content. **In comparison, `intlayer` processes the fallback at dictionary build time. Thus, each page will load only the content used.**
|
|
165
|
+
|
|
166
|
+
Here an example of the impact of bundle size optimization using `intlayer` in a vite + react application:
|
|
167
|
+
|
|
168
|
+
| Optimized bundle | Bundle not optimized |
|
|
169
|
+
| -------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
|
|
170
|
+
|  |  |
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## TypeScript & safety
|
|
175
|
+
|
|
176
|
+
<Columns>
|
|
177
|
+
<Column>
|
|
178
|
+
|
|
179
|
+
**next-intl**
|
|
180
|
+
|
|
181
|
+
- Solid TypeScript support, but **keys aren’t strictly typed by default**; you’ll maintain safety patterns manually.
|
|
182
|
+
|
|
183
|
+
</Column>
|
|
184
|
+
<Column>
|
|
185
|
+
|
|
186
|
+
**next-i18next**
|
|
187
|
+
|
|
188
|
+
- Base typings for hooks; **strict key typing requires extra tooling/config**.
|
|
189
|
+
|
|
190
|
+
</Column>
|
|
191
|
+
<Column>
|
|
83
192
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
- **
|
|
193
|
+
**intlayer**
|
|
194
|
+
|
|
195
|
+
- **Generates strict types** from your content. **IDE autocompletion** and **compile-time errors** catch typos and missing keys before deploy.
|
|
196
|
+
|
|
197
|
+
</Column>
|
|
198
|
+
</Columns>
|
|
87
199
|
|
|
88
200
|
**Why it matters:** Strong typing shifts failures **left** (CI/build) instead of **right** (runtime).
|
|
89
201
|
|
|
90
202
|
---
|
|
91
203
|
|
|
92
|
-
|
|
204
|
+
## Missing translation handling
|
|
205
|
+
|
|
206
|
+
<Columns>
|
|
207
|
+
<Column>
|
|
208
|
+
|
|
209
|
+
**next-intl**
|
|
210
|
+
|
|
211
|
+
- Relies on **runtime fallbacks** (e.g., show the key or default locale). Build doesn’t fail.
|
|
212
|
+
|
|
213
|
+
</Column>
|
|
214
|
+
<Column>
|
|
215
|
+
|
|
216
|
+
**next-i18next**
|
|
217
|
+
|
|
218
|
+
- Relies on **runtime fallbacks** (e.g., show the key or default locale). Build doesn’t fail.
|
|
219
|
+
|
|
220
|
+
</Column>
|
|
221
|
+
<Column>
|
|
93
222
|
|
|
94
|
-
|
|
95
|
-
|
|
223
|
+
**intlayer**
|
|
224
|
+
|
|
225
|
+
- **Build-time detection** with **warnings/errors** for missing locales or keys.
|
|
226
|
+
|
|
227
|
+
</Column>
|
|
228
|
+
</Columns>
|
|
96
229
|
|
|
97
230
|
**Why it matters:** Catching gaps during build prevents “mystery strings” in production and aligns with strict release gates.
|
|
98
231
|
|
|
99
232
|
---
|
|
100
233
|
|
|
101
|
-
|
|
234
|
+
## Routing, middleware & URL strategy
|
|
235
|
+
|
|
236
|
+
<Columns>
|
|
237
|
+
<Column>
|
|
238
|
+
|
|
239
|
+
**next-intl**
|
|
240
|
+
|
|
241
|
+
- Works with **Next.js localized routing** on the App Router.
|
|
242
|
+
|
|
243
|
+
</Column>
|
|
244
|
+
<Column>
|
|
245
|
+
|
|
246
|
+
**next-i18next**
|
|
247
|
+
|
|
248
|
+
- Works with **Next.js localized routing** on the App Router.
|
|
102
249
|
|
|
103
|
-
|
|
104
|
-
|
|
250
|
+
</Column>
|
|
251
|
+
<Column>
|
|
252
|
+
|
|
253
|
+
**intlayer**
|
|
254
|
+
|
|
255
|
+
- All of the above, plus **i18n middleware** (locale detection via headers/cookies) and **helpers** to generate localized URLs and `<link rel="alternate" hreflang="…">` tags.
|
|
256
|
+
|
|
257
|
+
</Column>
|
|
258
|
+
</Columns>
|
|
105
259
|
|
|
106
260
|
**Why it matters:** Fewer custom glue layers; **consistent UX** and **clean SEO** across locales.
|
|
107
261
|
|
|
108
262
|
---
|
|
109
263
|
|
|
110
|
-
|
|
264
|
+
## Server Components (RSC) alignment
|
|
265
|
+
|
|
266
|
+
<Columns>
|
|
267
|
+
<Column>
|
|
268
|
+
|
|
269
|
+
**next-intl**
|
|
270
|
+
|
|
271
|
+
- Supports Next.js 13+. Often requires passing t-functions/formatters through component trees in hybrid setups.
|
|
272
|
+
|
|
273
|
+
</Column>
|
|
274
|
+
<Column>
|
|
275
|
+
|
|
276
|
+
**next-i18next**
|
|
277
|
+
|
|
278
|
+
- Supports Next.js 13+. Similar constraints with passing translation utilities across boundaries.
|
|
111
279
|
|
|
112
|
-
|
|
113
|
-
|
|
280
|
+
</Column>
|
|
281
|
+
<Column>
|
|
282
|
+
|
|
283
|
+
**intlayer**
|
|
284
|
+
|
|
285
|
+
- Supports Next.js 13+ and smooths the **server/client boundary** with a consistent API and RSC-oriented providers, avoiding shuttling formatters or t-functions.
|
|
286
|
+
|
|
287
|
+
</Column>
|
|
288
|
+
</Columns>
|
|
114
289
|
|
|
115
290
|
**Why it matters:** Cleaner mental model and fewer edge cases in hybrid trees.
|
|
116
291
|
|
|
117
292
|
---
|
|
118
293
|
|
|
119
|
-
|
|
294
|
+
## DX, tooling & maintenance
|
|
120
295
|
|
|
121
|
-
|
|
122
|
-
|
|
296
|
+
<Columns>
|
|
297
|
+
<Column>
|
|
123
298
|
|
|
124
|
-
**
|
|
299
|
+
**next-intl**
|
|
125
300
|
|
|
126
|
-
|
|
301
|
+
- Commonly paired with external localization platforms and editorial workflows.
|
|
302
|
+
|
|
303
|
+
</Column>
|
|
304
|
+
<Column>
|
|
305
|
+
|
|
306
|
+
**next-i18next**
|
|
307
|
+
|
|
308
|
+
- Commonly paired with external localization platforms and editorial workflows.
|
|
309
|
+
|
|
310
|
+
</Column>
|
|
311
|
+
<Column>
|
|
127
312
|
|
|
128
|
-
|
|
313
|
+
**intlayer**
|
|
129
314
|
|
|
130
|
-
- **
|
|
131
|
-
|
|
315
|
+
- Ships a **free Visual Editor** and **optional CMS** (Git-friendly or externalized), plus a **VSCode extension** and **AI-assisted translations** using your own provider keys.
|
|
316
|
+
|
|
317
|
+
</Column>
|
|
318
|
+
</Columns>
|
|
132
319
|
|
|
133
320
|
**Why it matters:** Lowers ops cost and shortens the loop between developers and content authors.
|
|
134
321
|
|
|
135
|
-
|
|
322
|
+
## Integration with localization platforms (TMS)
|
|
323
|
+
|
|
324
|
+
Large organizations often rely on Translation Management Systems (TMS) like **Crowdin**, **Phrase**, **Lokalise**, **Localizely**, or **Localazy**.
|
|
325
|
+
|
|
326
|
+
- **Why companies care**
|
|
327
|
+
- **Collaboration & roles**: Multiple actors are involved: developers, product managers, translators, reviewers, marketing teams.
|
|
328
|
+
- **Scale & efficiency**: continuous localization, in‑context review.
|
|
329
|
+
|
|
330
|
+
- **next-intl / next-i18next**
|
|
331
|
+
- Typically use **centralized JSON catalogs**, so export/import with TMS is straightforward.
|
|
332
|
+
- Mature ecosystems and examples/integrations for the platforms above.
|
|
333
|
+
|
|
334
|
+
- **Intlayer**
|
|
335
|
+
- Encourages **decentralized, per-component dictionaries** and supports **TypeScript/TSX/JS/JSON/MD** content.
|
|
336
|
+
- This improves modularity in code, but can make plug‑and‑play TMS integration harder when a tool expects centralized, flat JSON files.
|
|
337
|
+
- Intlayer provides alternatives: **AI‑assisted translations** (using your own provider keys), a **Visual Editor/CMS**, and **CLI/CI** workflows to catch and prefill gaps.
|
|
338
|
+
|
|
339
|
+
> Note: `next-intl` and `i18next` also accepts TypeScript catalogs. If your team stores messages in `.ts` files or decentralizes them by feature, you can face similar TMS friction. However, many `next-intl` setups remain centralized in a `locales/` folder, which is a bit easier to refactor to JSON for TMS.
|
|
340
|
+
|
|
341
|
+
## Developer Experience
|
|
342
|
+
|
|
343
|
+
This part makes a deep comparison between the three solutions. Rather than considering simple cases, as described in the 'getting started' documentation for each solution, we will consider a real use case, more similar to a real project.
|
|
344
|
+
|
|
345
|
+
### App structure
|
|
346
|
+
|
|
347
|
+
The app structure is important to ensure good maintainability for your codebase.
|
|
348
|
+
|
|
349
|
+
<Tab defaultTab="next-intl" group='techno'>
|
|
350
|
+
|
|
351
|
+
<TabItem label="next-i18next" value="next-i18next">
|
|
352
|
+
|
|
353
|
+
```bash
|
|
354
|
+
.
|
|
355
|
+
├── public
|
|
356
|
+
│ └── locales
|
|
357
|
+
│ ├── en
|
|
358
|
+
│ │ ├── home.json
|
|
359
|
+
│ │ └── navbar.json
|
|
360
|
+
│ ├── fr
|
|
361
|
+
│ │ ├── home.json
|
|
362
|
+
│ │ └── navbar.json
|
|
363
|
+
│ └── es
|
|
364
|
+
│ ├── home.json
|
|
365
|
+
│ └── navbar.json
|
|
366
|
+
├── next-i18next.config.js
|
|
367
|
+
└── src
|
|
368
|
+
├── middleware.ts
|
|
369
|
+
├── app
|
|
370
|
+
│ └── home.tsx
|
|
371
|
+
└── components
|
|
372
|
+
└── Navbar
|
|
373
|
+
└── index.tsx
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
</TabItem>
|
|
377
|
+
<TabItem label="next-intl" value="next-intl">
|
|
378
|
+
|
|
379
|
+
```bash
|
|
380
|
+
.
|
|
381
|
+
├── locales
|
|
382
|
+
│ ├── en
|
|
383
|
+
│ │ ├── home.json
|
|
384
|
+
│ │ └── navbar.json
|
|
385
|
+
│ ├── fr
|
|
386
|
+
│ │ ├── home.json
|
|
387
|
+
│ │ └── navbar.json
|
|
388
|
+
│ └── es
|
|
389
|
+
│ ├── home.json
|
|
390
|
+
│ └── navbar.json
|
|
391
|
+
├── i18n.ts
|
|
392
|
+
└── src
|
|
393
|
+
├── middleware.ts
|
|
394
|
+
├── app
|
|
395
|
+
│ └── home.tsx
|
|
396
|
+
└── components
|
|
397
|
+
└── Navbar
|
|
398
|
+
└── index.tsx
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
</TabItem>
|
|
402
|
+
<TabItem label="intlayer" value="intlayer">
|
|
403
|
+
|
|
404
|
+
```bash
|
|
405
|
+
.
|
|
406
|
+
├── intlayer.config.ts
|
|
407
|
+
└── src
|
|
408
|
+
├── middleware.ts
|
|
409
|
+
├── app
|
|
410
|
+
│ └── home
|
|
411
|
+
│ └── index.tsx
|
|
412
|
+
│ └── index.content.ts
|
|
413
|
+
└── components
|
|
414
|
+
└── Navbar
|
|
415
|
+
├── index.tsx
|
|
416
|
+
└── index.content.ts
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
</TabItem>
|
|
420
|
+
</Tab>
|
|
421
|
+
|
|
422
|
+
#### Comparison
|
|
423
|
+
|
|
424
|
+
- **next-intl / next-i18next**: Centralized catalogs (JSON; namespaces/messages). Clear structure, integrates well with translation platforms, but can lead to more cross-file edits as apps grow.
|
|
425
|
+
- **Intlayer**: Per-component `.content.{ts|js|json}` dictionaries co-located with components. Easier component reuse and local reasoning; adds files and relies on build-time tooling.
|
|
426
|
+
|
|
427
|
+
#### Setup and Loading Content
|
|
428
|
+
|
|
429
|
+
As mentioned previously, you must optimize how each JSON file is imported into your code.
|
|
430
|
+
How the library handles content loading is important.
|
|
431
|
+
|
|
432
|
+
<Tab defaultTab="next-intl" group='techno'>
|
|
433
|
+
<TabItem label="next-i18next" value="next-i18next">
|
|
434
|
+
|
|
435
|
+
```tsx fileName="next-i18next.config.js"
|
|
436
|
+
module.exports = {
|
|
437
|
+
i18n: {
|
|
438
|
+
locales: ["en", "fr", "es"],
|
|
439
|
+
defaultLocale: "en",
|
|
440
|
+
},
|
|
441
|
+
};
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
```tsx fileName="src/app/_app.tsx"
|
|
445
|
+
import { appWithTranslation } from "next-i18next";
|
|
446
|
+
|
|
447
|
+
const MyApp = ({ Component, pageProps }) => <Component {...pageProps} />;
|
|
448
|
+
|
|
449
|
+
export default appWithTranslation(MyApp);
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
```tsx fileName="src/app/[locale]/about/page.tsx"
|
|
453
|
+
import type { GetStaticProps } from "next";
|
|
454
|
+
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
|
|
455
|
+
import { useTranslation } from "next-i18next";
|
|
456
|
+
import { I18nextProvider, initReactI18next } from "react-i18next";
|
|
457
|
+
import { createInstance } from "i18next";
|
|
458
|
+
import { ClientComponent, ServerComponent } from "@components";
|
|
459
|
+
|
|
460
|
+
export default function HomePage({ locale }: { locale: string }) {
|
|
461
|
+
// Déclarez explicitement le namespace utilisé par ce composant
|
|
462
|
+
const resources = await loadMessagesFor(locale); // your loader (JSON, etc.)
|
|
463
|
+
|
|
464
|
+
const i18n = createInstance();
|
|
465
|
+
i18n.use(initReactI18next).init({
|
|
466
|
+
lng: locale,
|
|
467
|
+
fallbackLng: "en",
|
|
468
|
+
resources,
|
|
469
|
+
ns: ["common", "about"],
|
|
470
|
+
defaultNS: "common",
|
|
471
|
+
interpolation: { escapeValue: false },
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
const { t } = useTranslation("about");
|
|
475
|
+
|
|
476
|
+
return (
|
|
477
|
+
<I18nextProvider i18n={i18n}>
|
|
478
|
+
<main>
|
|
479
|
+
<h1>{t("title")}</h1>
|
|
480
|
+
<ClientComponent />
|
|
481
|
+
<ServerComponent />
|
|
482
|
+
</main>
|
|
483
|
+
</I18nextProvider>
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
export const getStaticProps: GetStaticProps = async ({ locale }) => {
|
|
488
|
+
// Ne préchargez que les namespaces nécessaires à CETTE page
|
|
489
|
+
return {
|
|
490
|
+
props: {
|
|
491
|
+
...(await serverSideTranslations(locale ?? "en", ["common", "about"])),
|
|
492
|
+
},
|
|
493
|
+
};
|
|
494
|
+
};
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
</TabItem>
|
|
498
|
+
<TabItem label="next-intl" value="next-intl">
|
|
499
|
+
|
|
500
|
+
```tsx fileName="i18n.ts"
|
|
501
|
+
import { getRequestConfig } from "next-intl/server";
|
|
502
|
+
import { notFound } from "next/navigation";
|
|
503
|
+
|
|
504
|
+
// Can be imported from a shared config
|
|
505
|
+
const locales = ["en", "fr", "es"];
|
|
506
|
+
|
|
507
|
+
export default getRequestConfig(async ({ locale }) => {
|
|
508
|
+
// Validate that the incoming `locale` parameter is valid
|
|
509
|
+
if (!locales.includes(locale as any)) notFound();
|
|
510
|
+
|
|
511
|
+
return {
|
|
512
|
+
messages: (await import(`../messages/${locale}.json`)).default,
|
|
513
|
+
};
|
|
514
|
+
});
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
```tsx fileName="src/app/[locale]/about/layout.tsx"
|
|
518
|
+
import { NextIntlClientProvider } from "next-intl";
|
|
519
|
+
import { getMessages, unstable_setRequestLocale } from "next-intl/server";
|
|
520
|
+
import pick from "lodash/pick";
|
|
521
|
+
|
|
522
|
+
export default async function LocaleLayout({
|
|
523
|
+
children,
|
|
524
|
+
params,
|
|
525
|
+
}: {
|
|
526
|
+
children: React.ReactNode;
|
|
527
|
+
params: { locale: string };
|
|
528
|
+
}) {
|
|
529
|
+
const { locale } = params;
|
|
530
|
+
|
|
531
|
+
// Set the active request locale for this server render (RSC)
|
|
532
|
+
unstable_setRequestLocale(locale);
|
|
533
|
+
|
|
534
|
+
// Messages are loaded server-side via src/i18n/request.ts
|
|
535
|
+
// (see next-intl docs). Here we only push a subset to the client
|
|
536
|
+
// that's needed for client components (payload optimization).
|
|
537
|
+
const messages = await getMessages();
|
|
538
|
+
const clientMessages = pick(messages, ["common", "about"]);
|
|
539
|
+
|
|
540
|
+
return (
|
|
541
|
+
<html lang={locale}>
|
|
542
|
+
<body>
|
|
543
|
+
<NextIntlClientProvider locale={locale} messages={clientMessages}>
|
|
544
|
+
{children}
|
|
545
|
+
</NextIntlClientProvider>
|
|
546
|
+
</body>
|
|
547
|
+
</html>
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
```tsx fileName="src/app/[locale]/about/page.tsx"
|
|
553
|
+
import { getTranslations } from "next-intl/server";
|
|
554
|
+
import { ClientComponent, ServerComponent } from "@components";
|
|
555
|
+
|
|
556
|
+
export default async function LandingPage({
|
|
557
|
+
params,
|
|
558
|
+
}: {
|
|
559
|
+
params: { locale: string };
|
|
560
|
+
}) {
|
|
561
|
+
// Chargement strictement côté serveur (pas hydraté au client)
|
|
562
|
+
const t = await getTranslations("about");
|
|
563
|
+
|
|
564
|
+
return (
|
|
565
|
+
<main>
|
|
566
|
+
<h1>{t("title")}</h1>
|
|
567
|
+
<ClientComponent />
|
|
568
|
+
<ServerComponent />
|
|
569
|
+
</main>
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
```
|
|
573
|
+
|
|
574
|
+
</TabItem>
|
|
575
|
+
<TabItem label="intlayer" value="intlayer">
|
|
576
|
+
|
|
577
|
+
```tsx fileName="intlayer.config.ts"
|
|
578
|
+
export default {
|
|
579
|
+
internationalization: {
|
|
580
|
+
locales: ["en", "fr", "es"],
|
|
581
|
+
defaultLocale: "en",
|
|
582
|
+
},
|
|
583
|
+
};
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
```tsx fileName="src/app/[locale]/layout.tsx"
|
|
587
|
+
import { getHTMLTextDir } from "intlayer";
|
|
588
|
+
import {
|
|
589
|
+
IntlayerClientProvider,
|
|
590
|
+
generateStaticParams,
|
|
591
|
+
type NextLayoutIntlayer,
|
|
592
|
+
} from "next-intlayer";
|
|
136
593
|
|
|
137
|
-
|
|
594
|
+
export const dynamic = "force-static";
|
|
138
595
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
596
|
+
const LandingLayout: NextLayoutIntlayer = async ({ children, params }) => {
|
|
597
|
+
const { locale } = await params;
|
|
598
|
+
|
|
599
|
+
return (
|
|
600
|
+
<html lang={locale} dir={getHTMLTextDir(locale)}>
|
|
601
|
+
<IntlayerClientProvider locale={locale}>
|
|
602
|
+
{children}
|
|
603
|
+
</IntlayerClientProvider>
|
|
604
|
+
</html>
|
|
605
|
+
);
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
export default LandingLayout;
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
```tsx fileName="src/app/[locale]/about/page.tsx"
|
|
612
|
+
import { PageContent } from "@components/PageContent";
|
|
613
|
+
import type { NextPageIntlayer } from "next-intlayer";
|
|
614
|
+
import { IntlayerServerProvider, useIntlayer } from "next-intlayer/server";
|
|
615
|
+
import { ClientComponent, ServerComponent } from "@components";
|
|
616
|
+
|
|
617
|
+
const LandingPage: NextPageIntlayer = async ({ params }) => {
|
|
618
|
+
const { locale } = await params;
|
|
619
|
+
const { title } = useIntlayer("about", locale);
|
|
620
|
+
|
|
621
|
+
return (
|
|
622
|
+
<IntlayerServerProvider locale={locale}>
|
|
623
|
+
<main>
|
|
624
|
+
<h1>{title}</h1>
|
|
625
|
+
<ClientComponent />
|
|
626
|
+
<ServerComponent />
|
|
627
|
+
</main>
|
|
628
|
+
</IntlayerServerProvider>
|
|
629
|
+
);
|
|
630
|
+
};
|
|
631
|
+
|
|
632
|
+
export default LandingPage;
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
</TabItem>
|
|
636
|
+
</Tab>
|
|
637
|
+
|
|
638
|
+
#### Comparison
|
|
639
|
+
|
|
640
|
+
All three support per-locale content loading and providers.
|
|
641
|
+
|
|
642
|
+
- With **next-intl/next-i18next**, you typically load selected messages/namespaces per route and place providers where needed.
|
|
643
|
+
|
|
644
|
+
- With **Intlayer**, adds build-time analysis to infer usage, which can reduce manual wiring and may allow a single root provider.
|
|
645
|
+
|
|
646
|
+
Choose between explicit control and automation based on team preference.
|
|
647
|
+
|
|
648
|
+
### Usage in a client component
|
|
649
|
+
|
|
650
|
+
Let's take an example of a client component rendering a counter.
|
|
651
|
+
|
|
652
|
+
<Tab defaultTab="next-intl" group='techno'>
|
|
653
|
+
<TabItem label="next-i18next" value="next-i18next">
|
|
654
|
+
|
|
655
|
+
**Translations (must be real JSON in `public/locales/...`)**
|
|
656
|
+
|
|
657
|
+
```json fileName="public/locales/en/about.json"
|
|
658
|
+
{
|
|
659
|
+
"counter": {
|
|
660
|
+
"label": "Counter",
|
|
661
|
+
"increment": "Increment"
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
```
|
|
665
|
+
|
|
666
|
+
```json fileName="public/locales/fr/about.json"
|
|
667
|
+
{
|
|
668
|
+
"counter": {
|
|
669
|
+
"label": "Compteur",
|
|
670
|
+
"increment": "Incrémenter"
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
**Client component**
|
|
676
|
+
|
|
677
|
+
```tsx fileName="src/components/ClientComponentExample.tsx"
|
|
678
|
+
"use client";
|
|
679
|
+
|
|
680
|
+
import React, { useMemo, useState } from "react";
|
|
681
|
+
import { useTranslation } from "next-i18next";
|
|
682
|
+
|
|
683
|
+
const ClientComponentExample = () => {
|
|
684
|
+
const { t, i18n } = useTranslation("about");
|
|
685
|
+
const [count, setCount] = useState(0);
|
|
686
|
+
|
|
687
|
+
// next-i18next doesn't expose useNumber; use Intl.NumberFormat
|
|
688
|
+
const numberFormat = new Intl.NumberFormat(i18n.language);
|
|
689
|
+
|
|
690
|
+
return (
|
|
691
|
+
<div>
|
|
692
|
+
<p>{numberFormat.format(count)}</p>
|
|
693
|
+
<button
|
|
694
|
+
aria-label={t("counter.label")}
|
|
695
|
+
onClick={() => setCount((count) => count + 1)}
|
|
696
|
+
>
|
|
697
|
+
{t("counter.increment")}
|
|
698
|
+
</button>
|
|
699
|
+
</div>
|
|
700
|
+
);
|
|
701
|
+
};
|
|
702
|
+
```
|
|
703
|
+
|
|
704
|
+
> Don't forget to add "about" namespace on the page serverSideTranslations
|
|
705
|
+
> We take here the version of react 19.x.x, but for lower versions, you will need to use useMemo to store the instance of the formatter as it's a heavy function
|
|
706
|
+
|
|
707
|
+
</TabItem>
|
|
708
|
+
<TabItem label="next-intl" value="next-intl">
|
|
709
|
+
|
|
710
|
+
**Translations (shape reused; load them into next-intl messages as you prefer)**
|
|
711
|
+
|
|
712
|
+
```json fileName="locales/en/about.json"
|
|
713
|
+
{
|
|
714
|
+
"counter": {
|
|
715
|
+
"label": "Counter",
|
|
716
|
+
"increment": "Increment"
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
```
|
|
720
|
+
|
|
721
|
+
```json fileName="locales/fr/about.json"
|
|
722
|
+
{
|
|
723
|
+
"counter": {
|
|
724
|
+
"label": "Compteur",
|
|
725
|
+
"increment": "Incrémenter"
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
```
|
|
729
|
+
|
|
730
|
+
**Client component**
|
|
731
|
+
|
|
732
|
+
```tsx fileName="src/components/ClientComponentExample.tsx"
|
|
733
|
+
"use client";
|
|
734
|
+
|
|
735
|
+
import React, { useState } from "react";
|
|
736
|
+
import { useTranslations, useFormatter } from "next-intl";
|
|
737
|
+
|
|
738
|
+
const ClientComponentExample = () => {
|
|
739
|
+
// Scope directly to the nested object
|
|
740
|
+
const t = useTranslations("about.counter");
|
|
741
|
+
const format = useFormatter();
|
|
742
|
+
const [count, setCount] = useState(0);
|
|
743
|
+
|
|
744
|
+
return (
|
|
745
|
+
<div>
|
|
746
|
+
<p>{format.number(count)}</p>
|
|
747
|
+
<button
|
|
748
|
+
aria-label={t("label")}
|
|
749
|
+
onClick={() => setCount((count) => count + 1)}
|
|
750
|
+
>
|
|
751
|
+
{t("increment")}
|
|
752
|
+
</button>
|
|
753
|
+
</div>
|
|
754
|
+
);
|
|
755
|
+
};
|
|
756
|
+
```
|
|
757
|
+
|
|
758
|
+
> Don't forget to add "about" message on the page client message
|
|
759
|
+
|
|
760
|
+
</TabItem>
|
|
761
|
+
<TabItem label="intlayer" value="intlayer">
|
|
762
|
+
|
|
763
|
+
**Content**
|
|
764
|
+
|
|
765
|
+
```ts fileName="src/components/ClientComponentExample/index.content.ts"
|
|
766
|
+
import { t, type Dictionary } from "intlayer";
|
|
767
|
+
|
|
768
|
+
const counterContent = {
|
|
769
|
+
key: "counter",
|
|
770
|
+
content: {
|
|
771
|
+
label: t({ en: "Counter", fr: "Compteur" }),
|
|
772
|
+
increment: t({ en: "Increment", fr: "Incrémenter" }),
|
|
773
|
+
},
|
|
774
|
+
} satisfies Dictionary;
|
|
775
|
+
|
|
776
|
+
export default counterContent;
|
|
777
|
+
```
|
|
778
|
+
|
|
779
|
+
**Client component**
|
|
780
|
+
|
|
781
|
+
```tsx fileName="src/components/ClientComponentExample/index.tsx"
|
|
782
|
+
"use client";
|
|
783
|
+
|
|
784
|
+
import React, { useState } from "react";
|
|
785
|
+
import { useNumber, useIntlayer } from "next-intlayer";
|
|
786
|
+
|
|
787
|
+
const ClientComponentExample = () => {
|
|
788
|
+
const [count, setCount] = useState(0);
|
|
789
|
+
const { label, increment } = useIntlayer("counter"); // returns strings
|
|
790
|
+
const { number } = useNumber();
|
|
791
|
+
|
|
792
|
+
return (
|
|
793
|
+
<div>
|
|
794
|
+
<p>{number(count)}</p>
|
|
795
|
+
<button aria-label={label} onClick={() => setCount((count) => count + 1)}>
|
|
796
|
+
{increment}
|
|
797
|
+
</button>
|
|
798
|
+
</div>
|
|
799
|
+
);
|
|
800
|
+
};
|
|
801
|
+
```
|
|
802
|
+
|
|
803
|
+
</TabItem>
|
|
804
|
+
</Tab>
|
|
805
|
+
|
|
806
|
+
#### Comparison
|
|
807
|
+
|
|
808
|
+
- **Number formatting**
|
|
809
|
+
- **next-i18next**: no `useNumber`; use `Intl.NumberFormat` (or i18next-icu).
|
|
810
|
+
- **next-intl**: `useFormatter().number(value)`.
|
|
811
|
+
- **Intlayer**: `useNumber()` built-in.
|
|
812
|
+
|
|
813
|
+
- **Keys**
|
|
814
|
+
- Keep a nested structure (`about.counter.label`) and scope your hook accordingly (`useTranslation("about")` + `t("counter.label")` or `useTranslations("about.counter")` + `t("label")`).
|
|
815
|
+
|
|
816
|
+
- **File locations**
|
|
817
|
+
- **next-i18next** expects JSON in `public/locales/{lng}/{ns}.json`.
|
|
818
|
+
- **next-intl** is flexible; load messages however you configure.
|
|
819
|
+
- **Intlayer** stores content in TS/JS dictionaries and resolves by key.
|
|
142
820
|
|
|
143
821
|
---
|
|
144
822
|
|
|
145
|
-
|
|
823
|
+
### Usage in a server component
|
|
824
|
+
|
|
825
|
+
We will take the case of a UI component. This component is a server component, and should be able to be inserted as a child of a client component. (page (server component) -> client component -> server component). As this component can be inserted as a child of a client component, it cannot be async.
|
|
826
|
+
|
|
827
|
+
<Tab defaultTab="next-intl" group='techno'>
|
|
828
|
+
<TabItem label="next-i18next" value="next-i18next">
|
|
829
|
+
|
|
830
|
+
```tsx fileName="src/pages/about.tsx"
|
|
831
|
+
import type { GetStaticProps } from "next";
|
|
832
|
+
import { useTranslation } from "next-i18next";
|
|
833
|
+
|
|
834
|
+
type ServerComponentProps = {
|
|
835
|
+
count: number;
|
|
836
|
+
};
|
|
837
|
+
|
|
838
|
+
const ServerComponent = ({ count }: ServerComponentProps) => {
|
|
839
|
+
const { t, i18n } = useTranslation("about");
|
|
840
|
+
const formatted = new Intl.NumberFormat(i18n.language).format(count);
|
|
841
|
+
|
|
842
|
+
return (
|
|
843
|
+
<div>
|
|
844
|
+
<p>{formatted}</p>
|
|
845
|
+
<button aria-label={t("counter.label")}>{t("counter.increment")}</button>
|
|
846
|
+
</div>
|
|
847
|
+
);
|
|
848
|
+
};
|
|
849
|
+
```
|
|
850
|
+
|
|
851
|
+
</TabItem>
|
|
852
|
+
<TabItem label="next-intl" value="next-intl">
|
|
853
|
+
|
|
854
|
+
```tsx fileName="src/components/ServerComponent.tsx"
|
|
855
|
+
type ServerComponentProps = {
|
|
856
|
+
count: number;
|
|
857
|
+
t: (key: string) => string;
|
|
858
|
+
};
|
|
859
|
+
|
|
860
|
+
const ServerComponent = ({ t, count }: ServerComponentProps) => {
|
|
861
|
+
const formatted = new Intl.NumberFormat(i18n.language).format(count);
|
|
862
|
+
|
|
863
|
+
return (
|
|
864
|
+
<div>
|
|
865
|
+
<p>{formatted}</p>
|
|
866
|
+
<button aria-label={t("label")}>{t("increment")}</button>
|
|
867
|
+
</div>
|
|
868
|
+
);
|
|
869
|
+
};
|
|
870
|
+
```
|
|
871
|
+
|
|
872
|
+
> As the server component cannot be async, you need to pass the translations and formatter function as props.
|
|
873
|
+
>
|
|
874
|
+
> In your page / layout:
|
|
875
|
+
>
|
|
876
|
+
> - `import { getTranslations, getFormatter } from "next-intl/server";`
|
|
877
|
+
> - `const t = await getTranslations("about.counter");`
|
|
878
|
+
> - `const format = await getFormatter();`
|
|
879
|
+
|
|
880
|
+
</TabItem>
|
|
881
|
+
<TabItem label="intlayer" value="intlayer">
|
|
882
|
+
|
|
883
|
+
```tsx fileName="src/components/ServerComponent.tsx"
|
|
884
|
+
import { useIntlayer, useNumber } from "next-intlayer/server";
|
|
885
|
+
|
|
886
|
+
type ServerComponentProps = {
|
|
887
|
+
count: number;
|
|
888
|
+
};
|
|
889
|
+
|
|
890
|
+
const ServerComponent = ({ count }: ServerComponentProps) => {
|
|
891
|
+
const { label, increment } = useIntlayer("counter");
|
|
892
|
+
const { number } = useNumber();
|
|
893
|
+
|
|
894
|
+
return (
|
|
895
|
+
<div>
|
|
896
|
+
<p>{number(count)}</p>
|
|
897
|
+
<button aria-label={label}>{increment}</button>
|
|
898
|
+
</div>
|
|
899
|
+
);
|
|
900
|
+
};
|
|
901
|
+
```
|
|
902
|
+
|
|
903
|
+
</TabItem>
|
|
904
|
+
</Tab>
|
|
905
|
+
|
|
906
|
+
> Intlayer exposes **server-safe** hooks via `next-intlayer/server`. To work, `useIntlayer` and `useNumber` use hooks-like syntax, similar to the client hooks, but depend under the hood on the server context (`IntlayerServerProvider`).
|
|
146
907
|
|
|
147
|
-
|
|
908
|
+
### Metadata / Sitemap / Robots
|
|
148
909
|
|
|
149
|
-
|
|
910
|
+
Translating content is great. But people usually forget that 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.
|
|
150
911
|
|
|
151
|
-
|
|
912
|
+
Here's a list of good practices regarding multilingual SEO.
|
|
913
|
+
|
|
914
|
+
- set hreflang meta tags in the `<head>` tag
|
|
915
|
+
> It helps search engines to understand what languages are available on the page
|
|
916
|
+
- list all pages translations in the sitemap.xml using `http://www.w3.org/1999/xhtml` XML schema
|
|
917
|
+
>
|
|
918
|
+
- do not forget to exclude prefixed pages from the robots.txt (e.g. `/dashboard`, and `/fr/dashboard`, `/es/dashboard`)
|
|
919
|
+
>
|
|
920
|
+
- use custom Link component to redirect to the most localized page (e.g. in french `<a href="/fr/about">A propos</a>` )
|
|
921
|
+
>
|
|
922
|
+
|
|
923
|
+
Developers often forget to properly reference their pages across locales.
|
|
924
|
+
|
|
925
|
+
<Tab defaultTab="next-intl" group='techno'>
|
|
926
|
+
|
|
927
|
+
<TabItem label="next-i18next" value="next-i18next">
|
|
928
|
+
|
|
929
|
+
```ts fileName="i18n.config.ts"
|
|
930
|
+
export const locales = ["en", "fr"] as const;
|
|
931
|
+
export type Locale = (typeof locales)[number];
|
|
932
|
+
export const defaultLocale: Locale = "en";
|
|
933
|
+
|
|
934
|
+
export function localizedPath(locale: string, path: string) {
|
|
935
|
+
return locale === defaultLocale ? path : "/" + locale + path;
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
const ORIGIN = "https://example.com";
|
|
939
|
+
export function abs(locale: string, path: string) {
|
|
940
|
+
return ORIGIN + localizedPath(locale, path);
|
|
941
|
+
}
|
|
942
|
+
```
|
|
943
|
+
|
|
944
|
+
```tsx fileName="src/app/[locale]/about/layout.tsx"
|
|
945
|
+
import type { Metadata } from "next";
|
|
946
|
+
import { locales, defaultLocale, localizedPath } from "@/i18n.config";
|
|
947
|
+
|
|
948
|
+
export async function generateMetadata({
|
|
949
|
+
params,
|
|
950
|
+
}: {
|
|
951
|
+
params: { locale: string };
|
|
952
|
+
}): Promise<Metadata> {
|
|
953
|
+
const { locale } = params;
|
|
954
|
+
|
|
955
|
+
// Dynamically import the correct JSON file
|
|
956
|
+
const messages = (
|
|
957
|
+
await import("@/../public/locales/" + locale + "/about.json")
|
|
958
|
+
).default;
|
|
959
|
+
|
|
960
|
+
const languages = Object.fromEntries(
|
|
961
|
+
locales.map((locale) => [locale, localizedPath(locale, "/about")])
|
|
962
|
+
);
|
|
963
|
+
|
|
964
|
+
return {
|
|
965
|
+
title: messages.title,
|
|
966
|
+
description: messages.description,
|
|
967
|
+
alternates: {
|
|
968
|
+
canonical: localizedPath(locale, "/about"),
|
|
969
|
+
languages: { ...languages, "x-default": "/about" },
|
|
970
|
+
},
|
|
971
|
+
};
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
export default async function AboutPage() {
|
|
975
|
+
return <h1>About</h1>;
|
|
976
|
+
}
|
|
977
|
+
```
|
|
978
|
+
|
|
979
|
+
```ts fileName="src/app/sitemap.ts"
|
|
980
|
+
import type { MetadataRoute } from "next";
|
|
981
|
+
import { locales, defaultLocale, abs } from "@/i18n.config";
|
|
982
|
+
|
|
983
|
+
export default function sitemap(): MetadataRoute.Sitemap {
|
|
984
|
+
const languages = Object.fromEntries(
|
|
985
|
+
locales.map((locale) => [locale, abs(locale, "/about")])
|
|
986
|
+
);
|
|
987
|
+
return [
|
|
988
|
+
{
|
|
989
|
+
url: abs(defaultLocale, "/about"),
|
|
990
|
+
lastModified: new Date(),
|
|
991
|
+
changeFrequency: "monthly",
|
|
992
|
+
priority: 0.7,
|
|
993
|
+
alternates: { languages },
|
|
994
|
+
},
|
|
995
|
+
];
|
|
996
|
+
}
|
|
997
|
+
```
|
|
998
|
+
|
|
999
|
+
```ts fileName="src/app/robots.ts"
|
|
1000
|
+
import type { MetadataRoute } from "next";
|
|
1001
|
+
import { locales, defaultLocale, localizedPath } from "@/i18n.config";
|
|
1002
|
+
|
|
1003
|
+
const ORIGIN = "https://example.com";
|
|
1004
|
+
|
|
1005
|
+
const expandAllLocales = (path: string) => [
|
|
1006
|
+
localizedPath(defaultLocale, path),
|
|
1007
|
+
...locales
|
|
1008
|
+
.filter((locale) => locale !== defaultLocale)
|
|
1009
|
+
.map((locale) => localizedPath(locale, path)),
|
|
1010
|
+
];
|
|
1011
|
+
|
|
1012
|
+
export default function robots(): MetadataRoute.Robots {
|
|
1013
|
+
const disallow = [
|
|
1014
|
+
...expandAllLocales("/dashboard"),
|
|
1015
|
+
...expandAllLocales("/admin"),
|
|
1016
|
+
];
|
|
1017
|
+
|
|
1018
|
+
return {
|
|
1019
|
+
rules: { userAgent: "*", allow: ["/"], disallow },
|
|
1020
|
+
host: ORIGIN,
|
|
1021
|
+
sitemap: ORIGIN + "/sitemap.xml",
|
|
1022
|
+
};
|
|
1023
|
+
}
|
|
1024
|
+
```
|
|
1025
|
+
|
|
1026
|
+
</TabItem>
|
|
1027
|
+
<TabItem label="next-intl" value="next-intl">
|
|
1028
|
+
|
|
1029
|
+
```tsx fileName="src/app/[locale]/about/layout.tsx"
|
|
1030
|
+
import type { Metadata } from "next";
|
|
1031
|
+
import { locales, defaultLocale } from "@/i18n";
|
|
1032
|
+
import { getTranslations } from "next-intl/server";
|
|
1033
|
+
|
|
1034
|
+
function localizedPath(locale: string, path: string) {
|
|
1035
|
+
return locale === defaultLocale ? path : "/" + locale + path;
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
export async function generateMetadata({
|
|
1039
|
+
params,
|
|
1040
|
+
}: {
|
|
1041
|
+
params: { locale: string };
|
|
1042
|
+
}): Promise<Metadata> {
|
|
1043
|
+
const { locale } = params;
|
|
1044
|
+
const t = await getTranslations({ locale, namespace: "about" });
|
|
1045
|
+
|
|
1046
|
+
const url = "/about";
|
|
1047
|
+
const languages = Object.fromEntries(
|
|
1048
|
+
locales.map((locale) => [locale, localizedPath(locale, url)])
|
|
1049
|
+
);
|
|
1050
|
+
|
|
1051
|
+
return {
|
|
1052
|
+
title: t("title"),
|
|
1053
|
+
description: t("description"),
|
|
1054
|
+
alternates: {
|
|
1055
|
+
canonical: localizedPath(locale, url),
|
|
1056
|
+
languages: { ...languages, "x-default": url },
|
|
1057
|
+
},
|
|
1058
|
+
};
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
// ... Rest of the page code
|
|
1062
|
+
```
|
|
1063
|
+
|
|
1064
|
+
```tsx fileName="src/app/sitemap.ts"
|
|
1065
|
+
import type { MetadataRoute } from "next";
|
|
1066
|
+
import { locales, defaultLocale } from "@/i18n";
|
|
1067
|
+
|
|
1068
|
+
const origin = "https://example.com";
|
|
1069
|
+
|
|
1070
|
+
const formatterLocalizedPath = (locale: string, path: string) =>
|
|
1071
|
+
locale === defaultLocale ? origin + path : origin + "/" + locale + path;
|
|
1072
|
+
|
|
1073
|
+
export default function sitemap(): MetadataRoute.Sitemap {
|
|
1074
|
+
const aboutLanguages = Object.fromEntries(
|
|
1075
|
+
locales.map((l) => [l, formatterLocalizedPath(l, "/about")])
|
|
1076
|
+
);
|
|
1077
|
+
|
|
1078
|
+
return [
|
|
1079
|
+
{
|
|
1080
|
+
url: formatterLocalizedPath(defaultLocale, "/about"),
|
|
1081
|
+
lastModified: new Date(),
|
|
1082
|
+
changeFrequency: "monthly",
|
|
1083
|
+
priority: 0.7,
|
|
1084
|
+
alternates: { languages: aboutLanguages },
|
|
1085
|
+
},
|
|
1086
|
+
];
|
|
1087
|
+
}
|
|
1088
|
+
```
|
|
1089
|
+
|
|
1090
|
+
```tsx fileName="src/app/robots.ts"
|
|
1091
|
+
import type { MetadataRoute } from "next";
|
|
1092
|
+
import { locales, defaultLocale } from "@/i18n";
|
|
1093
|
+
|
|
1094
|
+
const origin = "https://example.com";
|
|
1095
|
+
const withAllLocales = (path: string) => [
|
|
1096
|
+
path,
|
|
1097
|
+
...locales
|
|
1098
|
+
.filter((locale) => locale !== defaultLocale)
|
|
1099
|
+
.map((locale) => "/" + locale + path),
|
|
1100
|
+
];
|
|
1101
|
+
|
|
1102
|
+
export default function robots(): MetadataRoute.Robots {
|
|
1103
|
+
const disallow = [
|
|
1104
|
+
...withAllLocales("/dashboard"),
|
|
1105
|
+
...withAllLocales("/admin"),
|
|
1106
|
+
];
|
|
1107
|
+
|
|
1108
|
+
return {
|
|
1109
|
+
rules: { userAgent: "*", allow: ["/"], disallow },
|
|
1110
|
+
host: origin,
|
|
1111
|
+
sitemap: origin + "/sitemap.xml",
|
|
1112
|
+
};
|
|
1113
|
+
}
|
|
1114
|
+
```
|
|
1115
|
+
|
|
1116
|
+
</TabItem>
|
|
1117
|
+
<TabItem label="intlayer" value="intlayer">
|
|
1118
|
+
|
|
1119
|
+
```typescript fileName="src/app/[locale]/about/layout.tsx"
|
|
1120
|
+
import { getIntlayer, getMultilingualUrls } from "intlayer";
|
|
1121
|
+
import type { Metadata } from "next";
|
|
1122
|
+
import type { LocalPromiseParams } from "next-intlayer";
|
|
1123
|
+
|
|
1124
|
+
export const generateMetadata = async ({
|
|
1125
|
+
params,
|
|
1126
|
+
}: LocalPromiseParams): Promise<Metadata> => {
|
|
1127
|
+
const { locale } = await params;
|
|
1128
|
+
|
|
1129
|
+
const metadata = getIntlayer("page-metadata", locale);
|
|
1130
|
+
|
|
1131
|
+
const multilingualUrls = getMultilingualUrls("/about");
|
|
1132
|
+
|
|
1133
|
+
return {
|
|
1134
|
+
...metadata,
|
|
1135
|
+
alternates: {
|
|
1136
|
+
canonical: multilingualUrls[locale as keyof typeof multilingualUrls],
|
|
1137
|
+
languages: { ...multilingualUrls, "x-default": "/about" },
|
|
1138
|
+
},
|
|
1139
|
+
};
|
|
1140
|
+
};
|
|
1141
|
+
|
|
1142
|
+
// ... Rest of the page code
|
|
1143
|
+
```
|
|
1144
|
+
|
|
1145
|
+
```tsx fileName="src/app/sitemap.ts"
|
|
1146
|
+
import { getMultilingualUrls } from "intlayer";
|
|
1147
|
+
import type { MetadataRoute } from "next";
|
|
1148
|
+
|
|
1149
|
+
const sitemap = (): MetadataRoute.Sitemap => [
|
|
1150
|
+
{
|
|
1151
|
+
url: "https://example.com/about",
|
|
1152
|
+
alternates: {
|
|
1153
|
+
languages: { ...getMultilingualUrls("https://example.com/about") },
|
|
1154
|
+
},
|
|
1155
|
+
},
|
|
1156
|
+
];
|
|
1157
|
+
```
|
|
1158
|
+
|
|
1159
|
+
```tsx fileName="src/app/robots.ts"
|
|
1160
|
+
import { getMultilingualUrls } from "intlayer";
|
|
1161
|
+
import type { MetadataRoute } from "next";
|
|
1162
|
+
|
|
1163
|
+
const getAllMultilingualUrls = (urls: string[]) =>
|
|
1164
|
+
urls.flatMap((url) => Object.values(getMultilingualUrls(url)) as string[]);
|
|
1165
|
+
|
|
1166
|
+
const robots = (): MetadataRoute.Robots => ({
|
|
1167
|
+
rules: {
|
|
1168
|
+
userAgent: "*",
|
|
1169
|
+
allow: ["/"],
|
|
1170
|
+
disallow: getAllMultilingualUrls(["/dashboard"]),
|
|
1171
|
+
},
|
|
1172
|
+
host: "https://example.com",
|
|
1173
|
+
sitemap: "https://example.com/sitemap.xml",
|
|
1174
|
+
});
|
|
1175
|
+
|
|
1176
|
+
export default robots;
|
|
1177
|
+
```
|
|
1178
|
+
|
|
1179
|
+
</TabItem>
|
|
1180
|
+
</Tab>
|
|
1181
|
+
|
|
1182
|
+
> Intlayer provides a `getMultilingualUrls` function to generate multilingual URLs for your sitemap.
|
|
152
1183
|
|
|
153
1184
|
---
|
|
154
1185
|
|
|
1186
|
+
---
|
|
1187
|
+
|
|
1188
|
+
## And the winner is…
|
|
1189
|
+
|
|
1190
|
+
It’s not simple. Each option has trade-offs. Here’s how I see it:
|
|
1191
|
+
|
|
1192
|
+
<Columns>
|
|
1193
|
+
<Column>
|
|
1194
|
+
|
|
1195
|
+
**next-i18next**
|
|
1196
|
+
|
|
1197
|
+
- mature, full of features, lots of community plugins, but higher setup cost. If you need **i18next’s plugin ecosystem** (e.g., advanced ICU rules via plugins) and your team already knows i18next, accepting **more configuration** for flexibility.
|
|
1198
|
+
|
|
1199
|
+
</Column>
|
|
1200
|
+
<Column>
|
|
1201
|
+
|
|
1202
|
+
**next-intl**
|
|
1203
|
+
|
|
1204
|
+
- simplest, lightweight, fewer decisions forced on you. If you want a **minimal** solution, you’re comfortable with centralized catalogs, and your app is **small to mid-size**.
|
|
1205
|
+
|
|
1206
|
+
</Column>
|
|
1207
|
+
<Column>
|
|
1208
|
+
|
|
1209
|
+
**Intlayer**
|
|
1210
|
+
|
|
1211
|
+
- built for modern Next.js, with modular content, type safety, tooling, and less boilerplate. If you value **component-scoped content**, **strict TypeScript**, **build-time guarantees**, **tree-shaking**, and **batteries-included** routing/SEO/editor tooling - especially for **Next.js App Router**, design-systems and **large, modular codebases**.
|
|
1212
|
+
|
|
1213
|
+
</Column>
|
|
1214
|
+
</Columns>
|
|
1215
|
+
|
|
1216
|
+
If you prefer minimal setup and accept some manual wiring, next-intl is a good pick. If you need all the features and don't mind complexity, next-i18next works. But if you want a modern, scalable, modular solution with built tools, Intlayer aims to give you that out of the box.
|
|
1217
|
+
|
|
1218
|
+
> **Alternative for enterprise teams**: If you need a well-proven solution that works perfectly with established localization platforms like **Crowdin**, **Phrase**, or other professional translation management systems, consider **next-intl** or **next-i18next** for their mature ecosystem and proven integrations.
|
|
1219
|
+
|
|
1220
|
+
> **Future roadmap**: Intlayer also plans to develop plugins that work on top of **i18next** and **next-intl** solutions. This will give you the advantages of Intlayer for automation, syntax, and content management while keeping the security and stability provided by these established solutions in your application code.
|
|
1221
|
+
|
|
155
1222
|
## GitHub STARs
|
|
156
1223
|
|
|
157
1224
|
GitHub stars are a strong indicator of a project's popularity, community trust, and long-term relevance. While not a direct measure of technical quality, they reflect how many developers find the project useful, follow its progress, and are likely to adopt it. For estimating the value of a project, stars help compare traction across alternatives and provide insights into ecosystem growth.
|