@intlayer/docs 7.0.3 → 7.0.4

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.
Files changed (159) hide show
  1. package/blog/ar/intlayer_with_i18next.md +68 -106
  2. package/blog/ar/intlayer_with_next-i18next.md +84 -288
  3. package/blog/ar/intlayer_with_next-intl.md +58 -337
  4. package/blog/ar/intlayer_with_react-i18next.md +68 -290
  5. package/blog/ar/intlayer_with_react-intl.md +63 -266
  6. package/blog/de/intlayer_with_i18next.md +77 -97
  7. package/blog/de/intlayer_with_next-i18next.md +69 -296
  8. package/blog/de/intlayer_with_next-intl.md +59 -340
  9. package/blog/de/intlayer_with_react-i18next.md +68 -290
  10. package/blog/de/intlayer_with_react-intl.md +62 -264
  11. package/blog/en/intlayer_with_i18next.md +67 -103
  12. package/blog/en/intlayer_with_next-i18next.md +69 -294
  13. package/blog/en/intlayer_with_next-intl.md +48 -300
  14. package/blog/en/intlayer_with_react-i18next.md +61 -289
  15. package/blog/en/intlayer_with_react-intl.md +61 -284
  16. package/blog/en/next-i18next_vs_next-intl_vs_intlayer.md +1 -1
  17. package/blog/en-GB/intlayer_with_i18next.md +67 -103
  18. package/blog/en-GB/intlayer_with_next-i18next.md +71 -292
  19. package/blog/en-GB/intlayer_with_next-intl.md +58 -337
  20. package/blog/en-GB/intlayer_with_react-i18next.md +67 -289
  21. package/blog/en-GB/intlayer_with_react-intl.md +61 -264
  22. package/blog/es/intlayer_with_i18next.md +67 -103
  23. package/blog/es/intlayer_with_next-i18next.md +71 -296
  24. package/blog/es/intlayer_with_next-intl.md +57 -338
  25. package/blog/es/intlayer_with_react-i18next.md +68 -290
  26. package/blog/es/intlayer_with_react-intl.md +62 -265
  27. package/blog/fr/intlayer_with_i18next.md +66 -104
  28. package/blog/fr/intlayer_with_next-i18next.md +82 -285
  29. package/blog/fr/intlayer_with_next-intl.md +57 -338
  30. package/blog/fr/intlayer_with_react-i18next.md +67 -289
  31. package/blog/fr/intlayer_with_react-intl.md +61 -264
  32. package/blog/hi/intlayer_with_i18next.md +68 -104
  33. package/blog/hi/intlayer_with_next-i18next.md +74 -299
  34. package/blog/hi/intlayer_with_next-intl.md +57 -239
  35. package/blog/hi/intlayer_with_react-i18next.md +69 -291
  36. package/blog/hi/intlayer_with_react-intl.md +65 -268
  37. package/blog/id/intlayer_with_i18next.md +126 -0
  38. package/blog/id/intlayer_with_next-i18next.md +142 -0
  39. package/blog/id/intlayer_with_next-intl.md +113 -0
  40. package/blog/id/intlayer_with_react-i18next.md +124 -0
  41. package/blog/id/intlayer_with_react-intl.md +122 -0
  42. package/blog/it/intlayer_with_i18next.md +67 -103
  43. package/blog/it/intlayer_with_next-i18next.md +71 -296
  44. package/blog/it/intlayer_with_next-intl.md +57 -338
  45. package/blog/it/intlayer_with_react-i18next.md +68 -290
  46. package/blog/it/intlayer_with_react-intl.md +62 -265
  47. package/blog/ja/intlayer_with_i18next.md +68 -103
  48. package/blog/ja/intlayer_with_next-i18next.md +85 -283
  49. package/blog/ja/intlayer_with_next-intl.md +58 -336
  50. package/blog/ja/intlayer_with_react-i18next.md +68 -290
  51. package/blog/ja/intlayer_with_react-intl.md +62 -264
  52. package/blog/ko/intlayer_with_i18next.md +80 -96
  53. package/blog/ko/intlayer_with_next-i18next.md +85 -287
  54. package/blog/ko/intlayer_with_next-intl.md +68 -327
  55. package/blog/ko/intlayer_with_react-i18next.md +68 -290
  56. package/blog/ko/intlayer_with_react-intl.md +64 -266
  57. package/blog/pl/intlayer_with_i18next.md +126 -0
  58. package/blog/pl/intlayer_with_next-i18next.md +142 -0
  59. package/blog/pl/intlayer_with_next-intl.md +111 -0
  60. package/blog/pl/intlayer_with_react-i18next.md +124 -0
  61. package/blog/pl/intlayer_with_react-intl.md +122 -0
  62. package/blog/pt/intlayer_with_i18next.md +67 -103
  63. package/blog/pt/intlayer_with_next-i18next.md +72 -293
  64. package/blog/pt/intlayer_with_next-intl.md +57 -256
  65. package/blog/pt/intlayer_with_react-i18next.md +104 -78
  66. package/blog/pt/intlayer_with_react-intl.md +62 -266
  67. package/blog/ru/intlayer_with_i18next.md +66 -104
  68. package/blog/ru/intlayer_with_next-i18next.md +71 -296
  69. package/blog/ru/intlayer_with_next-intl.md +58 -337
  70. package/blog/ru/intlayer_with_react-i18next.md +68 -290
  71. package/blog/ru/intlayer_with_react-intl.md +62 -265
  72. package/blog/tr/intlayer_with_i18next.md +71 -107
  73. package/blog/tr/intlayer_with_next-i18next.md +72 -297
  74. package/blog/tr/intlayer_with_next-intl.md +58 -339
  75. package/blog/tr/intlayer_with_react-i18next.md +69 -291
  76. package/blog/tr/intlayer_with_react-intl.md +63 -285
  77. package/blog/vi/intlayer_with_i18next.md +126 -0
  78. package/blog/vi/intlayer_with_next-i18next.md +142 -0
  79. package/blog/vi/intlayer_with_next-intl.md +111 -0
  80. package/blog/vi/intlayer_with_react-i18next.md +124 -0
  81. package/blog/vi/intlayer_with_react-intl.md +122 -0
  82. package/blog/zh/intlayer_with_i18next.md +67 -102
  83. package/blog/zh/intlayer_with_next-i18next.md +72 -296
  84. package/blog/zh/intlayer_with_next-intl.md +58 -336
  85. package/blog/zh/intlayer_with_react-i18next.md +68 -290
  86. package/blog/zh/intlayer_with_react-intl.md +63 -106
  87. package/dist/cjs/generated/blog.entry.cjs +13 -1
  88. package/dist/cjs/generated/blog.entry.cjs.map +1 -1
  89. package/dist/cjs/generated/docs.entry.cjs +13 -1
  90. package/dist/cjs/generated/docs.entry.cjs.map +1 -1
  91. package/dist/cjs/generated/frequentQuestions.entry.cjs +13 -1
  92. package/dist/cjs/generated/frequentQuestions.entry.cjs.map +1 -1
  93. package/dist/cjs/generated/legal.entry.cjs +13 -1
  94. package/dist/cjs/generated/legal.entry.cjs.map +1 -1
  95. package/dist/esm/generated/blog.entry.mjs +13 -2
  96. package/dist/esm/generated/blog.entry.mjs.map +1 -1
  97. package/dist/esm/generated/docs.entry.mjs +13 -2
  98. package/dist/esm/generated/docs.entry.mjs.map +1 -1
  99. package/dist/esm/generated/frequentQuestions.entry.mjs +13 -2
  100. package/dist/esm/generated/frequentQuestions.entry.mjs.map +1 -1
  101. package/dist/esm/generated/legal.entry.mjs +13 -2
  102. package/dist/esm/generated/legal.entry.mjs.map +1 -1
  103. package/dist/types/generated/blog.entry.d.ts.map +1 -1
  104. package/dist/types/generated/docs.entry.d.ts.map +1 -1
  105. package/dist/types/generated/frequentQuestions.entry.d.ts.map +1 -1
  106. package/dist/types/generated/legal.entry.d.ts.map +1 -1
  107. package/docs/ar/plugins/sync-json.md +244 -0
  108. package/docs/de/plugins/sync-json.md +244 -0
  109. package/docs/de/releases/v7.md +1 -18
  110. package/docs/en/CI_CD.md +1 -1
  111. package/docs/en/configuration.md +1 -1
  112. package/docs/en/formatters.md +1 -1
  113. package/docs/en/how_works_intlayer.md +1 -1
  114. package/docs/en/intlayer_CMS.md +1 -1
  115. package/docs/en/intlayer_cli.md +26 -1
  116. package/docs/en/intlayer_with_nextjs_14.md +3 -1
  117. package/docs/en/intlayer_with_nextjs_15.md +3 -1
  118. package/docs/en/intlayer_with_nextjs_16.md +3 -1
  119. package/docs/en/intlayer_with_nextjs_page_router.md +1 -1
  120. package/docs/en/intlayer_with_nuxt.md +1 -1
  121. package/docs/en/intlayer_with_react_native+expo.md +1 -1
  122. package/docs/en/intlayer_with_react_router_v7.md +1 -1
  123. package/docs/en/intlayer_with_tanstack.md +1 -1
  124. package/docs/en/intlayer_with_vite+preact.md +1 -1
  125. package/docs/en/intlayer_with_vite+react.md +1 -1
  126. package/docs/en/intlayer_with_vite+solid.md +1 -1
  127. package/docs/en/intlayer_with_vite+svelte.md +1 -1
  128. package/docs/en/intlayer_with_vite+vue.md +1 -1
  129. package/docs/en/plugins/sync-json.md +1 -1
  130. package/docs/en/roadmap.md +1 -1
  131. package/docs/en-GB/plugins/sync-json.md +244 -0
  132. package/docs/es/plugins/sync-json.md +244 -0
  133. package/docs/es/releases/v7.md +1 -18
  134. package/docs/fr/intlayer_with_nextjs_16.md +2 -51
  135. package/docs/fr/plugins/sync-json.md +244 -0
  136. package/docs/fr/releases/v7.md +1 -18
  137. package/docs/hi/intlayer_with_nextjs_16.md +3 -2
  138. package/docs/hi/plugins/sync-json.md +244 -0
  139. package/docs/id/plugins/sync-json.md +244 -0
  140. package/docs/id/releases/v7.md +1 -18
  141. package/docs/it/plugins/sync-json.md +244 -0
  142. package/docs/it/releases/v7.md +1 -18
  143. package/docs/ja/intlayer_with_nextjs_16.md +44 -205
  144. package/docs/ja/plugins/sync-json.md +244 -0
  145. package/docs/ja/releases/v7.md +1 -18
  146. package/docs/ko/plugins/sync-json.md +244 -0
  147. package/docs/ko/releases/v7.md +1 -18
  148. package/docs/pl/plugins/sync-json.md +244 -0
  149. package/docs/pt/intlayer_with_nextjs_16.md +1 -52
  150. package/docs/pt/plugins/sync-json.md +244 -0
  151. package/docs/ru/plugins/sync-json.md +244 -0
  152. package/docs/tr/plugins/sync-json.md +245 -0
  153. package/docs/vi/plugins/sync-json.md +244 -0
  154. package/docs/zh/plugins/sync-json.md +244 -0
  155. package/package.json +14 -14
  156. package/src/generated/blog.entry.ts +26 -3
  157. package/src/generated/docs.entry.ts +26 -3
  158. package/src/generated/frequentQuestions.entry.ts +26 -3
  159. package/src/generated/legal.entry.ts +26 -3
@@ -1,16 +1,8 @@
1
1
  ---
2
2
  createdAt: 2025-01-02
3
3
  updatedAt: 2025-10-29
4
- title: Intlayer and next-intl
5
- description: Integrate Intlayer with next-intl for the internationalization (i18n) of a React app
6
- keywords:
7
- - next-intl
8
- - Intlayer
9
- - Internationalization
10
- - Blog
11
- - Next.js
12
- - JavaScript
13
- - React
4
+ title: How to automate your next-intl JSON translations using Intlayer
5
+ description: Automate your JSON translations with Intlayer and next-intl for enhanced internationalization in Next.js applications.
14
6
  slugs:
15
7
  - blog
16
8
  - intlayer-with-next-intl
@@ -20,100 +12,62 @@ history:
20
12
  changes: Change to syncJSON plugin
21
13
  ---
22
14
 
23
- # Next.js Internationalization (i18n) with next-intl and Intlayer
15
+ # How to automate your next-intl JSON translations using Intlayer
24
16
 
25
- Both next-intl and Intlayer are open-source internationalization (i18n) frameworks designed for Next.js applications. They are widely used for managing translations, localization, and language switching in software projects.
17
+ ## What is Intlayer?
26
18
 
27
- They share three principal notions:
19
+ **Intlayer** is an innovative, open-source internationalization library designed to address the shortcomings of traditional i18n solutions. It offers a modern approach to content management in Next.js applications.
28
20
 
29
- 1. **Dictionary**: The method for defining the translatable content of your application.
30
- - Named `content declaration file` in Intlayer, which can be a JSON, JS, or TS file exporting the structured data. See [Intlayer documentation](https://intlayer.org/fr/doc/concept/content) for more information.
31
- - Named `messages` or `locale messages` in next-intl, usually in JSON files. See [next-intl documentation](https://github.com/amannn/next-intl) for more information.
21
+ See a concrete comparison with next-intl in our [next-i18next vs. next-intl vs. Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/blog/en/next-i18next_vs_next-intl_vs_intlayer.md) blog post.
32
22
 
33
- 2. **Utilities**: Tools to build and interpret content declarations in the application, such as `useIntlayer()` or `useLocale()` for Intlayer, and `useTranslations()` for next-intl.
23
+ ## Why Combine Intlayer with next-intl?
34
24
 
35
- 3. **Plugins and Middlewares**: Features for managing URL redirection, bundling optimization, and more e.g., `intlayerMiddleware` for Intlayer or [`createMiddleware`](https://github.com/amannn/next-intl) for next-intl.
25
+ While Intlayer provides an excellent standalone i18n solution (see our [Next.js integration guide](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/intlayer_with_nextjs_16.md)), you might want to combine it with next-intl for several reasons:
36
26
 
37
- ## Table of Contents
38
-
39
- <TOC>
40
-
41
- ## Intlayer vs. next-intl: Key Differences
42
-
43
- For a deeper analysis of how Intlayer compares to other i18n libraries for Next.js (such as next-intl), check out the [next-i18next vs. next-intl vs. Intlayer blog post](https://github.com/aymericzip/intlayer/blob/main/docs/blog/en/i18next_vs_next-intl_vs_intlayer.md).
44
-
45
- ## How to Generate next-intl Messages with Intlayer
46
-
47
- ### Why Use Intlayer with next-intl?
27
+ 1. **Existing codebase**: You have an established next-intl implementation and want to gradually migrate to Intlayer's improved developer experience.
28
+ 2. **Legacy requirements**: Your project requires compatibility with existing next-intl plugins or workflows.
29
+ 3. **Team familiarity**: Your team is comfortable with next-intl but wants better content management.
48
30
 
49
- Intlayer content declaration files generally offer a better developer experience. They are more flexible and maintainable due to two main advantages:
31
+ **For that, Intlayer can be implemented as an adapter for next-intl to help automating your JSON translations in CLI or CI/CD pipelines, testing your translations, and more.**
50
32
 
51
- 1. **Flexible Placement**: You can place an Intlayer content declaration file anywhere in your application’s file tree. This makes it easy to rename or delete components without leaving unused or dangling message files.
33
+ This guide shows you how to leverage Intlayer's superior content declaration system while maintaining compatibility with next-intl.
52
34
 
53
- Example file structures:
54
-
55
- ```bash codeFormat="typescript"
56
- .
57
- └── src
58
- └── components
59
- └── MyComponent
60
- ├── index.content.ts # Content declaration file
61
- └── index.tsx
62
- ```
63
-
64
- ```bash codeFormat="esm"
65
- .
66
- └── src
67
- └── components
68
- └── MyComponent
69
- ├── index.content.mjs # Content declaration file
70
- └── index.mjx
71
- ```
72
-
73
- ```bash codeFormat="cjs"
74
- .
75
- └── src
76
- └── components
77
- └── MyComponent
78
- ├── index.content.cjs # Content declaration file
79
- └── index.cjx
80
- ```
35
+ ## Table of Contents
81
36
 
82
- ```bash codeFormat="json"
83
- .
84
- └── src
85
- └── components
86
- └── MyComponent
87
- ├── index.content.json # Content declaration file
88
- └── index.jsx
89
- ```
37
+ <TOC/>
90
38
 
91
- 2. **Centralized Translations**: Intlayer stores all translations in a single content declaration, ensuring no translation is missing. In TypeScript projects, missing translations are flagged automatically as type errors, providing immediate feedback to developers.
39
+ ## Step-by-Step Guide to Set Up Intlayer with next-intl
92
40
 
93
- ### Installation
41
+ ### Step 1: Install Dependencies
94
42
 
95
- To use Intlayer and next-intl together, install both libraries:
43
+ Install the necessary packages:
96
44
 
97
45
  ```bash packageManager="npm"
98
- npm install intlayer next-intl @intlayer/sync-json-plugin
46
+ npm install intlayer @intlayer/sync-json-plugin
99
47
  ```
100
48
 
101
- ```bash packageManager="yarn"
102
- yarn add intlayer next-intl @intlayer/sync-json-plugin
49
+ ```bash packageManager="pnpm"
50
+ pnpm add intlayer @intlayer/sync-json-plugin
103
51
  ```
104
52
 
105
- ```bash packageManager="pnpm"
106
- pnpm add intlayer next-intl @intlayer/sync-json-plugin
53
+ ```bash packageManager="yarn"
54
+ yarn add intlayer @intlayer/sync-json-plugin
107
55
  ```
108
56
 
109
- ### Configuring Intlayer to Export next-intl Messages
57
+ **Package descriptions:**
58
+
59
+ - **intlayer**: Core library for internationalization management, content declaration, and building
60
+ - **@intlayer/sync-json-plugin**: Plugin to export Intlayer content declarations to next-intl compatible JSON format
110
61
 
111
- > **Note:** Exporting messages from Intlayer for next-intl can introduce slight differences in structure. If possible, keep an Intlayer-only or next-intl-only flow to simplify the integration. If you do need to generate next-intl messages from Intlayer, follow the steps below.
62
+ ### Step 2: Implement the Intlayer plugin to wrap the JSON
112
63
 
113
- Create or update an `intlayer.config.ts` file (or `.mjs` / `.cjs`) in the root of your project:
64
+ Create an Intlayer configuration file to define your supported locales:
65
+
66
+ **If you want to also export JSON dictionaries for next-intl**, add the `syncJSON` plugin:
114
67
 
115
68
  ```typescript fileName="intlayer.config.ts"
116
69
  import { Locales, type IntlayerConfig } from "intlayer";
70
+ import { syncJSON } from "@intlayer/sync-json-plugin";
117
71
 
118
72
  const config: IntlayerConfig = {
119
73
  internationalization: {
@@ -122,7 +76,7 @@ const config: IntlayerConfig = {
122
76
  },
123
77
  plugins: [
124
78
  syncJSON({
125
- source: ({ key, locale }) => `./intl/messages/${locale}/${key}.json`,
79
+ source: ({ key, locale }) => `./messages/${locale}/${key}.json`,
126
80
  }),
127
81
  ],
128
82
  };
@@ -130,236 +84,30 @@ const config: IntlayerConfig = {
130
84
  export default config;
131
85
  ```
132
86
 
133
- ### Dictionary
134
-
135
- Below are examples of content declaration files in multiple formats. Intlayer will compile these into message files that next-intl can consume.
87
+ The `syncJSON` plugin will automatically wrap the JSON. It will read and write the JSON files without changing the content architecture.
136
88
 
137
- ```typescript fileName="**/*.content.ts" contentDeclarationFormat="typescript"
138
- import { t, type Dictionary } from "intlayer";
89
+ If you want to make coexist that JSON with intlayer content declaration files (`.content` files), Intlayer will proceed this way:
139
90
 
140
- const content = {
141
- key: "my-component",
142
- content: {
143
- helloWorld: t({
144
- en: "Hello World",
145
- es: "Hola Mundo",
146
- fr: "Bonjour le monde",
147
- }),
148
- },
149
- } satisfies Dictionary;
91
+ 1. load both JSON and content declaration files and transform them into a intlayer dictionary.
92
+ 2. if there is conflicts between the JSON and the content declaration files, Intlayer will process to the merge of that all dictionaries. Depending of the priority of the plugins, and the one of the content declaration file (all are configurable).
150
93
 
151
- export default content;
152
- ```
94
+ If changes are made using the CLI to translate the JSON, or using the CMS, Intlayer will update the JSON file with the new translations.
153
95
 
154
- ```javascript fileName="**/*.content.mjs" contentDeclarationFormat="esm"
155
- import { t } from "intlayer";
156
-
157
- /** @type {import('intlayer').Dictionary} */
158
- const content = {
159
- key: "my-component",
160
- content: {
161
- helloWorld: t({
162
- en: "Hello World",
163
- es: "Hola Mundo",
164
- fr: "Bonjour le monde",
165
- }),
166
- },
167
- };
96
+ To see more details about the `syncJSON` plugin, please refer to the [syncJSON plugin documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/plugins/sync-json.md).
168
97
 
169
- export default content;
170
- ```
98
+ ## Git Configuration
171
99
 
172
- ```javascript fileName="**/*.content.cjs" contentDeclarationFormat="commonjs"
173
- const { t } = require("intlayer");
100
+ It's recommended to ignore auto-generated Intlayer files:
174
101
 
175
- module.exports = {
176
- key: "my-component",
177
- content: {
178
- helloWorld: t({
179
- en: "Hello World",
180
- es: "Hola Mundo",
181
- fr: "Bonjour le monde",
182
- }),
183
- },
184
- };
102
+ ```plaintext fileName=".gitignore"
103
+ # Ignore files generated by Intlayer
104
+ .intlayer
185
105
  ```
186
106
 
187
- ```json fileName="**/*.content.json" contentDeclarationFormat="json"
188
- {
189
- "$schema": "https://intlayer.org/schema.json",
190
- "key": "my-component",
191
- "content": {
192
- "helloWorld": {
193
- "nodeType": "translation",
194
- "translation": {
195
- "en": "Hello World",
196
- "fr": "Bonjour le monde",
197
- "es": "Hola Mundo"
198
- }
199
- }
200
- }
201
- }
202
- ```
203
-
204
- ### Build the next-intl Messages
205
-
206
- To build the message files for next-intl, run:
107
+ These files can be regenerated during your build process and don't need to be committed to version control.
207
108
 
208
- ```bash packageManager="npm"
209
- npx intlayer build
210
- ```
211
-
212
- ```bash packageManager="yarn"
213
- yarn intlayer build
214
- ```
109
+ ### VS Code Extension
215
110
 
216
- ```bash packageManager="pnpm"
217
- pnpm intlayer build
218
- ```
219
-
220
- This will generate resources in the `./intl/messages` directory (as configured in `intlayer.config.*`). The expected output:
221
-
222
- ```bash
223
- .
224
- └── intl
225
- └── messages
226
- └── en
227
- └── my-content.json
228
- └── fr
229
- └── my-content.json
230
- └── es
231
- └── my-content.json
232
- ```
233
-
234
- Each file includes compiled messages from all Intlayer content declarations. The top-level keys typically match your `content.key` fields.
235
-
236
- ### Using next-intl in Your Next.js App
237
-
238
- > For more details, see the official [next-intl usage docs](https://github.com/amannn/next-intl#readme).
239
-
240
- 1. **Create a Middleware (optional):**
241
- If you want to manage automatic locale detection or redirection, use next-intl’s [createMiddleware](https://github.com/amannn/next-intl#createMiddleware).
242
-
243
- ```typescript fileName="middleware.ts"
244
- import createMiddleware from "next-intl/middleware";
245
- import { NextResponse } from "next/server";
246
-
247
- export default createMiddleware({
248
- locales: ["en", "fr", "es"],
249
- defaultLocale: "en",
250
- });
251
-
252
- export const config = {
253
- matcher: ["/((?!api|_next|.*\\..*).*)"],
254
- };
255
- ```
256
-
257
- 2. **Create a `layout.tsx` or `_app.tsx` to Load Messages:**
258
- If you’re using the App Router (Next.js 13+), create a layout:
259
-
260
- ```typescript fileName="app/[locale]/layout.tsx"
261
- import { NextIntlClientProvider } from 'next-intl';
262
- import { notFound } from 'next/navigation';
263
- import React, { ReactNode } from 'react';
264
-
265
-
266
- export default async function RootLayout({
267
- children,
268
- params
269
- }: {
270
- children: ReactNode;
271
- params: { locale: string };
272
- }) {
273
- let messages;
274
- try {
275
- messages = (await import(`../../intl/messages/${params.locale}.json`)).default;
276
- } catch (error) {
277
- notFound();
278
- }
279
-
280
- return (
281
- <html lang={params.locale}>
282
- <body>
283
- <NextIntlClientProvider locale={params.locale} messages={messages}>
284
- {children}
285
- </NextIntlClientProvider>
286
- </body>
287
- </html>
288
- );
289
- }
290
- ```
291
-
292
- If you’re using the Pages Router (Next.js 12 or below), load messages in `_app.tsx`:
293
-
294
- ```typescript fileName="pages/_app.tsx"
295
- import type { AppProps } from 'next/app';
296
- import { NextIntlProvider } from 'next-intl';
297
-
298
- function MyApp({ Component, pageProps }: AppProps) {
299
- return (
300
- <NextIntlProvider locale={pageProps.locale} messages={pageProps.messages}>
301
- <Component {...pageProps} />
302
- </NextIntlProvider>
303
- );
304
- }
305
-
306
- export default MyApp;
307
- ```
308
-
309
- 3. **Fetch Messages Server-Side (Pages Router example):**
310
-
311
- ```typescript fileName="pages/index.tsx"
312
- import { GetServerSideProps } from "next";
313
- import HomePage from "../components/HomePage";
314
-
315
- export default HomePage;
316
-
317
- export const getServerSideProps: GetServerSideProps = async ({ locale }) => {
318
- const messages = (await import(`../intl/messages/${locale}.json`)).default;
319
-
320
- return {
321
- props: {
322
- locale,
323
- messages,
324
- },
325
- };
326
- };
327
- ```
328
-
329
- ### Using Content in Next.js Components
330
-
331
- Once the messages are loaded into next-intl, you can use them in your components via the `useTranslations()` hook:
332
-
333
- ```typescript fileName="src/components/MyComponent/index.tsx" codeFormat="typescript"
334
- import type { FC } from "react";
335
- import { useTranslations } from 'next-intl';
336
-
337
- const MyComponent: FC = () => {
338
- const t = useTranslations('my-component');
339
- // 'my-component' corresponds to the content key in Intlayer
340
-
341
- return (
342
- <div>
343
- <h1>{t('helloWorld')}</h1>
344
- </div>
345
- );
346
- };
347
-
348
- export default MyComponent;
349
- ```
350
-
351
- ```jsx fileName="src/components/MyComponent/index.jsx" codeFormat="esm"
352
- import { useTranslations } from "next-intl";
353
-
354
- export default function MyComponent() {
355
- const t = useTranslations("my-component");
356
-
357
- return (
358
- <div>
359
- <h1>{t("helloWorld")}</h1>
360
- </div>
361
- );
362
- }
363
- ```
111
+ For improved developer experience, install the official **Intlayer VS Code Extension**:
364
112
 
365
- **That’s it!** Whenever you update or add new Intlayer content declaration files, re-run the `intlayer build` command to regenerate your next-intl JSON messages. next-intl will pick up the updated content automatically.
113
+ [Install from the VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)