@intlayer/docs 7.0.4-canary.0 → 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 (107) 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 +36 -1638
  12. package/blog/en/intlayer_with_next-i18next.md +22 -847
  13. package/blog/en/intlayer_with_next-intl.md +32 -1053
  14. package/blog/en/intlayer_with_react-i18next.md +38 -764
  15. package/blog/en/intlayer_with_react-intl.md +42 -1018
  16. package/blog/en-GB/intlayer_with_i18next.md +67 -103
  17. package/blog/en-GB/intlayer_with_next-i18next.md +71 -292
  18. package/blog/en-GB/intlayer_with_next-intl.md +58 -337
  19. package/blog/en-GB/intlayer_with_react-i18next.md +67 -289
  20. package/blog/en-GB/intlayer_with_react-intl.md +61 -264
  21. package/blog/es/intlayer_with_i18next.md +67 -103
  22. package/blog/es/intlayer_with_next-i18next.md +71 -296
  23. package/blog/es/intlayer_with_next-intl.md +57 -338
  24. package/blog/es/intlayer_with_react-i18next.md +68 -290
  25. package/blog/es/intlayer_with_react-intl.md +62 -265
  26. package/blog/fr/intlayer_with_i18next.md +66 -104
  27. package/blog/fr/intlayer_with_next-i18next.md +82 -285
  28. package/blog/fr/intlayer_with_next-intl.md +57 -338
  29. package/blog/fr/intlayer_with_react-i18next.md +67 -289
  30. package/blog/fr/intlayer_with_react-intl.md +61 -264
  31. package/blog/hi/intlayer_with_i18next.md +68 -104
  32. package/blog/hi/intlayer_with_next-i18next.md +74 -299
  33. package/blog/hi/intlayer_with_next-intl.md +57 -239
  34. package/blog/hi/intlayer_with_react-i18next.md +69 -291
  35. package/blog/hi/intlayer_with_react-intl.md +65 -268
  36. package/blog/id/intlayer_with_i18next.md +126 -0
  37. package/blog/id/intlayer_with_next-i18next.md +142 -0
  38. package/blog/id/intlayer_with_next-intl.md +113 -0
  39. package/blog/id/intlayer_with_react-i18next.md +124 -0
  40. package/blog/id/intlayer_with_react-intl.md +122 -0
  41. package/blog/it/intlayer_with_i18next.md +67 -103
  42. package/blog/it/intlayer_with_next-i18next.md +71 -296
  43. package/blog/it/intlayer_with_next-intl.md +57 -338
  44. package/blog/it/intlayer_with_react-i18next.md +68 -290
  45. package/blog/it/intlayer_with_react-intl.md +62 -265
  46. package/blog/ja/intlayer_with_i18next.md +68 -103
  47. package/blog/ja/intlayer_with_next-i18next.md +85 -283
  48. package/blog/ja/intlayer_with_next-intl.md +58 -336
  49. package/blog/ja/intlayer_with_react-i18next.md +68 -290
  50. package/blog/ja/intlayer_with_react-intl.md +62 -264
  51. package/blog/ko/intlayer_with_i18next.md +80 -96
  52. package/blog/ko/intlayer_with_next-i18next.md +85 -287
  53. package/blog/ko/intlayer_with_next-intl.md +68 -327
  54. package/blog/ko/intlayer_with_react-i18next.md +68 -290
  55. package/blog/ko/intlayer_with_react-intl.md +64 -266
  56. package/blog/pl/intlayer_with_i18next.md +126 -0
  57. package/blog/pl/intlayer_with_next-i18next.md +142 -0
  58. package/blog/pl/intlayer_with_next-intl.md +111 -0
  59. package/blog/pl/intlayer_with_react-i18next.md +124 -0
  60. package/blog/pl/intlayer_with_react-intl.md +122 -0
  61. package/blog/pt/intlayer_with_i18next.md +67 -103
  62. package/blog/pt/intlayer_with_next-i18next.md +72 -293
  63. package/blog/pt/intlayer_with_next-intl.md +57 -256
  64. package/blog/pt/intlayer_with_react-i18next.md +104 -78
  65. package/blog/pt/intlayer_with_react-intl.md +62 -266
  66. package/blog/ru/intlayer_with_i18next.md +66 -104
  67. package/blog/ru/intlayer_with_next-i18next.md +71 -296
  68. package/blog/ru/intlayer_with_next-intl.md +58 -337
  69. package/blog/ru/intlayer_with_react-i18next.md +68 -290
  70. package/blog/ru/intlayer_with_react-intl.md +62 -265
  71. package/blog/tr/intlayer_with_i18next.md +71 -107
  72. package/blog/tr/intlayer_with_next-i18next.md +72 -297
  73. package/blog/tr/intlayer_with_next-intl.md +58 -339
  74. package/blog/tr/intlayer_with_react-i18next.md +69 -291
  75. package/blog/tr/intlayer_with_react-intl.md +63 -285
  76. package/blog/vi/intlayer_with_i18next.md +126 -0
  77. package/blog/vi/intlayer_with_next-i18next.md +142 -0
  78. package/blog/vi/intlayer_with_next-intl.md +111 -0
  79. package/blog/vi/intlayer_with_react-i18next.md +124 -0
  80. package/blog/vi/intlayer_with_react-intl.md +122 -0
  81. package/blog/zh/intlayer_with_i18next.md +67 -102
  82. package/blog/zh/intlayer_with_next-i18next.md +72 -296
  83. package/blog/zh/intlayer_with_next-intl.md +58 -336
  84. package/blog/zh/intlayer_with_react-i18next.md +68 -290
  85. package/blog/zh/intlayer_with_react-intl.md +63 -106
  86. package/docs/ar/plugins/sync-json.md +244 -0
  87. package/docs/de/plugins/sync-json.md +244 -0
  88. package/docs/en/intlayer_cli.md +25 -0
  89. package/docs/en/intlayer_with_nextjs_14.md +2 -0
  90. package/docs/en/intlayer_with_nextjs_15.md +2 -0
  91. package/docs/en/intlayer_with_nextjs_16.md +2 -0
  92. package/docs/en/plugins/sync-json.md +1 -1
  93. package/docs/en-GB/plugins/sync-json.md +244 -0
  94. package/docs/es/plugins/sync-json.md +244 -0
  95. package/docs/fr/plugins/sync-json.md +244 -0
  96. package/docs/hi/plugins/sync-json.md +244 -0
  97. package/docs/id/plugins/sync-json.md +244 -0
  98. package/docs/it/plugins/sync-json.md +244 -0
  99. package/docs/ja/plugins/sync-json.md +244 -0
  100. package/docs/ko/plugins/sync-json.md +244 -0
  101. package/docs/pl/plugins/sync-json.md +244 -0
  102. package/docs/pt/plugins/sync-json.md +244 -0
  103. package/docs/ru/plugins/sync-json.md +244 -0
  104. package/docs/tr/plugins/sync-json.md +245 -0
  105. package/docs/vi/plugins/sync-json.md +244 -0
  106. package/docs/zh/plugins/sync-json.md +244 -0
  107. package/package.json +14 -14
@@ -1,393 +1,112 @@
1
1
  ---
2
2
  createdAt: 2025-01-02
3
- updatedAt: 2025-06-29
4
- title: Intlayer und next-intl
5
- description: Integrieren Sie Intlayer mit next-intl für die Internationalisierung (i18n) einer React-App
6
- keywords:
7
- - next-intl
8
- - Intlayer
9
- - Internationalisierung
10
- - Dokumentation
11
- - Next.js
12
- - JavaScript
13
- - React
3
+ updatedAt: 2025-10-29
4
+ title: Wie Sie Ihre next-intl JSON-Übersetzungen mit Intlayer automatisieren
5
+ description: Automatisieren Sie Ihre JSON-Übersetzungen mit Intlayer und next-intl für eine verbesserte Internationalisierung in Next.js-Anwendungen.
14
6
  slugs:
15
7
  - blog
16
8
  - intlayer-with-next-intl
9
+ history:
10
+ - version: 7.0.0
11
+ date: 2025-10-29
12
+ changes: Wechsel zum syncJSON-Plugin
17
13
  ---
18
14
 
19
- # Next.js Internationalisierung (i18n) mit next-intl und Intlayer
15
+ # Wie Sie Ihre next-intl JSON-Übersetzungen mit Intlayer automatisieren
20
16
 
21
- Sowohl next-intl als auch Intlayer sind Open-Source-Internationalisierungsframeworks (i18n), die für Next.js-Anwendungen entwickelt wurden. Sie werden häufig für die Verwaltung von Übersetzungen, Lokalisierung und Sprachwechsel in Softwareprojekten eingesetzt.
17
+ ## Was ist Intlayer?
22
18
 
23
- Sie teilen drei Hauptkonzepte:
19
+ **Intlayer** ist eine innovative, Open-Source-Internationalisierungsbibliothek, die entwickelt wurde, um die Schwächen traditioneller i18n-Lösungen zu beheben. Sie bietet einen modernen Ansatz für das Content-Management in Next.js-Anwendungen.
24
20
 
25
- 1. **Inhaltsdeklaration**: Die Methode zur Definition des übersetzbaren Inhalts Ihrer Anwendung.
21
+ Sehen Sie einen konkreten Vergleich mit next-intl in unserem Blogbeitrag [next-i18next vs. next-intl vs. Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/blog/de/next-i18next_vs_next-intl_vs_intlayer.md).
26
22
 
27
- - Genannt `content declaration file` in Intlayer, welches eine JSON-, JS- oder TS-Datei sein kann, die die strukturierten Daten exportiert. Siehe [Intlayer-Dokumentation](https://intlayer.org/fr/doc/concept/content) für weitere Informationen.
28
- - Genannt `messages` oder `locale messages` in next-intl, normalerweise in JSON-Dateien. Siehe [next-intl-Dokumentation](https://github.com/amannn/next-intl) für weitere Informationen.
23
+ ## Warum Intlayer mit next-intl kombinieren?
29
24
 
30
- 2. **Hilfsprogramme**: Werkzeuge zum Erstellen und Interpretieren von Inhaltsdeklarationen in der Anwendung, wie `useIntlayer()` oder `useLocale()` für Intlayer und `useTranslations()` für next-intl.
25
+ Während Intlayer eine ausgezeichnete eigenständige i18n-Lösung bietet (siehe unseren [Next.js-Integrationsleitfaden](https://github.com/aymericzip/intlayer/blob/main/docs/docs/de/intlayer_with_nextjs_16.md)), möchten Sie es möglicherweise aus mehreren Gründen mit next-intl kombinieren:
31
26
 
32
- 3. **Plugins und Middleware**: Funktionen zur Verwaltung von URL-Weiterleitungen, Optimierung der Bundles und mehr z.B. `intlayerMiddleware` für Intlayer oder [`createMiddleware`](https://github.com/amannn/next-intl) für next-intl.
27
+ 1. **Bestehender Codebestand**: Sie haben eine etablierte next-intl-Implementierung und möchten schrittweise zur verbesserten Entwicklererfahrung von Intlayer migrieren.
28
+ 2. **Altsystemanforderungen**: Ihr Projekt erfordert Kompatibilität mit bestehenden next-intl-Plugins oder Workflows.
29
+ 3. **Teamvertrautheit**: Ihr Team ist mit next-intl vertraut, möchte aber ein besseres Content-Management.
33
30
 
34
- ## Intlayer vs. next-intl: Wichtige Unterschiede
31
+ **Dafür kann Intlayer als Adapter für next-intl implementiert werden, um Ihre JSON-Übersetzungen in CLI- oder CI/CD-Pipelines zu automatisieren, Ihre Übersetzungen zu testen und mehr.**
35
32
 
36
- Für eine tiefere Analyse, wie Intlayer mit anderen i18n-Bibliotheken für Next.js (wie next-intl) verglichen wird, lesen Sie den [next-i18next vs. next-intl vs. Intlayer Blogbeitrag](https://github.com/aymericzip/intlayer/blob/main/docs/blog/de/i18next_vs_next-intl_vs_intlayer.md).
33
+ Dieser Leitfaden zeigt Ihnen, wie Sie das überlegene Content-Deklarationssystem von Intlayer nutzen und gleichzeitig die Kompatibilität mit next-intl beibehalten.
37
34
 
38
- ## Wie man next-intl-Nachrichten mit Intlayer generiert
35
+ ## Inhaltsverzeichnis
39
36
 
40
- ### Warum Intlayer mit next-intl verwenden?
37
+ <TOC/>
41
38
 
42
- Intlayer-Inhaltsdeklarationsdateien bieten im Allgemeinen eine bessere Entwicklererfahrung. Sie sind flexibler und wartbarer aufgrund zweier Hauptvorteile:
39
+ ## Schritt-für-Schritt-Anleitung zur Einrichtung von Intlayer mit next-intl
43
40
 
44
- 1. **Flexibele Platzierung**: Sie können eine Intlayer-Inhaltsdeklarationsdatei überall im Dateibaum Ihrer Anwendung platzieren. Das erleichtert das Umbenennen oder Löschen von Komponenten, ohne ungenutzte oder nicht mehr benötigte Nachrichten-Dateien zu hinterlassen.
41
+ ### Schritt 1: Abhängigkeiten installieren
45
42
 
46
- Beispiel-Dateistrukturen:
47
-
48
- ```bash codeFormat="typescript"
49
- .
50
- └── src
51
- └── components
52
- └── MyComponent
53
- ├── index.content.ts # Inhaltsdeklarationsdatei
54
- └── index.tsx
55
- ```
56
-
57
- ```bash codeFormat="esm"
58
- .
59
- └── src
60
- └── components
61
- └── MyComponent
62
- ├── index.content.mjs # Inhaltsdeklarationsdatei
63
- └── index.mjx
64
- ```
65
-
66
- ```bash codeFormat="cjs"
67
- .
68
- └── src
69
- └── components
70
- └── MyComponent
71
- ├── index.content.cjs # Inhaltsdeklarationsdatei
72
- └── index.cjx
73
- ```
74
-
75
- ```bash codeFormat="json"
76
- .
77
- └── src
78
- └── components
79
- └── MyComponent
80
- ├── index.content.json # Inhaltsdeklarationsdatei
81
- └── index.jsx
82
- ```
83
-
84
- 2. **Zentralisierte Übersetzungen**: Intlayer speichert alle Übersetzungen in einer einzigen Inhaltsdeklaration, sodass keine Übersetzung fehlt. In TypeScript-Projekten werden fehlende Übersetzungen automatisch als Typfehler markiert, was den Entwicklern sofortiges Feedback gibt.
85
-
86
- ### Installation
87
-
88
- Um Intlayer und next-intl zusammen zu verwenden, installieren Sie beide Bibliotheken:
43
+ Installieren Sie die erforderlichen Pakete:
89
44
 
90
45
  ```bash packageManager="npm"
91
- npm install intlayer next-intl
92
- ```
93
-
94
- ```bash packageManager="yarn"
95
- yarn add intlayer next-intl
46
+ npm install intlayer @intlayer/sync-json-plugin
96
47
  ```
97
48
 
98
49
  ```bash packageManager="pnpm"
99
- pnpm add intlayer next-intl
50
+ pnpm add intlayer @intlayer/sync-json-plugin
100
51
  ```
101
52
 
102
- ### Konfigurieren von Intlayer zur Ausgabe von next-intl-Nachrichten
103
-
104
- > **Hinweis:** Die Ausgabe von Nachrichten von Intlayer für next-intl kann geringfügige Unterschiede in der Struktur mit sich bringen. Halten Sie, wenn möglich, einen nur Intlayer- oder nur next-intl-Workflow, um die Integration zu vereinfachen. Wenn Sie next-intl-Nachrichten von Intlayer generieren müssen, befolgen Sie die folgenden Schritte.
105
-
106
- Erstellen oder aktualisieren Sie eine `intlayer.config.ts`-Datei (oder `.mjs` / `.cjs`) im Stammverzeichnis Ihres Projekts:
107
-
108
- ```typescript fileName="intlayer.config.ts" codeFormat="typescript"
109
- import { Locales, type IntlayerConfig } from "intlayer";
110
-
111
- const config: IntlayerConfig = {
112
- internationalization: {
113
- locales: [Locales.GERMAN, Locales.FRENCH, Locales.SPANISH],
114
- defaultLocale: Locales.GERMAN,
115
- },
116
- content: {
117
- dictionaryOutput: ["next-intl"], // Verwenden Sie die next-intl-Ausgabe
118
- nextIntlMessagesDir: "./intl/messages", // Wo die next-intl-Nachrichten gespeichert werden
119
- },
120
- };
121
-
122
- export default config;
53
+ ```bash packageManager="yarn"
54
+ yarn add intlayer @intlayer/sync-json-plugin
123
55
  ```
124
56
 
125
- ```javascript fileName="intlayer.config.mjs" codeFormat="esm"
126
- import { Locales } from "intlayer";
57
+ **Paketbeschreibungen:**
127
58
 
128
- /** @type {import('intlayer').IntlayerConfig} */
129
- const config = {
130
- internationalization: {
131
- locales: [Locales.GERMAN, Locales.FRENCH, Locales.SPANISH],
132
- defaultLocale: Locales.GERMAN,
133
- },
134
- content: {
135
- dictionaryOutput: ["react-intl"],
136
- nextIntlMessagesDir: "./intl/messages",
137
- },
138
- };
59
+ - **intlayer**: Kernbibliothek für Internationalisierungsmanagement, Content-Deklaration und Build-Prozesse
60
+ - **@intlayer/sync-json-plugin**: Plugin zum Exportieren von Intlayer-Content-Deklarationen in ein next-intl-kompatibles JSON-Format
139
61
 
140
- export default config;
141
- ```
62
+ ### Schritt 2: Implementieren Sie das Intlayer-Plugin zum Verpacken des JSON
142
63
 
143
- ```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
144
- const { Locales } = require("intlayer");
64
+ Erstellen Sie eine Intlayer-Konfigurationsdatei, um Ihre unterstützten Sprachen zu definieren:
145
65
 
146
- /** @type {import('intlayer').IntlayerConfig} */
147
- const config = {
148
- internationalization: {
149
- locales: [Locales.GERMAN, Locales.FRENCH, Locales.SPANISH],
150
- defaultLocale: Locales.GERMAN,
151
- },
152
- content: {
153
- dictionaryOutput: ["next-intl"],
154
- nextIntlMessagesDir: "./intl/messages",
155
- },
156
- };
157
-
158
- module.exports = config;
159
- ```
160
-
161
- ### Inhaltsdeklaration
66
+ **Wenn Sie auch JSON-Wörterbücher für next-intl exportieren möchten**, fügen Sie das `syncJSON`-Plugin hinzu:
162
67
 
163
- Nachfolgend Beispiele für Inhaltsdeklarationsdateien in mehreren Formaten. Intlayer wird diese in Nachrichten-Dateien kompilieren, die next-intl konsumieren kann.
164
-
165
- ```typescript fileName="**/*.content.ts" contentDeclarationFormat="typescript"
166
- import { t, type Dictionary } from "intlayer";
68
+ ```typescript fileName="intlayer.config.ts"
69
+ import { Locales, type IntlayerConfig } from "intlayer";
70
+ import { syncJSON } from "@intlayer/sync-json-plugin";
167
71
 
168
- const content = {
169
- key: "my-component",
170
- content: {
171
- helloWorld: t({
172
- de: "Hallo Welt",
173
- fr: "Bonjour le monde",
174
- es: "Hola Mundo",
175
- }),
72
+ const config: IntlayerConfig = {
73
+ internationalization: {
74
+ locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
75
+ defaultLocale: Locales.ENGLISH,
176
76
  },
177
- } satisfies Dictionary;
178
-
179
- export default content;
180
- ```
181
-
182
- ```javascript fileName="**/*.content.mjs" contentDeclarationFormat="esm"
183
- import { t } from "intlayer";
184
-
185
- /** @type {import('intlayer').Dictionary} */
186
- const content = {
187
- key: "my-component",
188
- content: {
189
- helloWorld: t({
190
- de: "Hallo Welt",
191
- fr: "Bonjour le monde",
192
- es: "Hola Mundo",
77
+ plugins: [
78
+ syncJSON({
79
+ source: ({ key, locale }) => `./messages/${locale}/${key}.json`,
193
80
  }),
194
- },
81
+ ],
195
82
  };
196
83
 
197
- export default content;
198
- ```
199
-
200
- ```javascript fileName="**/*.content.cjs" contentDeclarationFormat="commonjs"
201
- const { t } = require("intlayer");
202
-
203
- module.exports = {
204
- key: "my-component",
205
- content: {
206
- helloWorld: t({
207
- de: "Hallo Welt",
208
- fr: "Bonjour le monde",
209
- es: "Hola Mundo",
210
- }),
211
- },
212
- };
84
+ export default config;
213
85
  ```
214
86
 
215
- ```json fileName="**/*.content.json" contentDeclarationFormat="json"
216
- {
217
- "$schema": "https://intlayer.org/schema.json",
218
- "key": "my-component",
219
- "content": {
220
- "helloWorld": {
221
- "nodeType": "translation",
222
- "translation": {
223
- "de": "Hallo Welt",
224
- "fr": "Bonjour le monde",
225
- "es": "Hola Mundo"
226
- }
227
- }
228
- }
229
- }
230
- ```
87
+ Das `syncJSON`-Plugin verpackt das JSON automatisch. Es liest und schreibt die JSON-Dateien, ohne die Inhaltsarchitektur zu verändern.
231
88
 
232
- ### Erstellen der next-intl-Nachrichten
89
+ Wenn Sie möchten, dass dieses JSON zusammen mit Intlayer-Content-Deklarationsdateien (`.content`-Dateien) koexistiert, geht Intlayer folgendermaßen vor:
233
90
 
234
- Um die Nachrichten-Dateien für next-intl zu erstellen, führen Sie aus:
91
+ 1. Lädt sowohl JSON- als auch Content-Deklarationsdateien und transformiert sie in ein Intlayer-Wörterbuch.
235
92
 
236
- ```bash packageManager="npm"
237
- npx intlayer dictionaries build
238
- ```
93
+ 2. Wenn es Konflikte zwischen den JSON- und den Inhaltsdeklarationsdateien gibt, wird Intlayer alle Wörterbücher zusammenführen. Dies hängt von der Priorität der Plugins und der der Inhaltsdeklarationsdatei ab (alle sind konfigurierbar).
239
94
 
240
- ```bash packageManager="yarn"
241
- yarn intlayer build
242
- ```
95
+ Wenn Änderungen über die CLI zur Übersetzung des JSON vorgenommen werden oder das CMS verwendet wird, aktualisiert Intlayer die JSON-Datei mit den neuen Übersetzungen.
243
96
 
244
- ```bash packageManager="pnpm"
245
- pnpm intlayer build
246
- ```
97
+ ## Git-Konfiguration
247
98
 
248
- Dies generiert Ressourcen im `./intl/messages`-Verzeichnis (wie in `intlayer.config.*` konfiguriert). Die erwartete Ausgabe:
249
-
250
- ```bash
251
- .
252
- └── intl
253
- └── messages
254
- └── de
255
- └── my-content.json
256
- └── fr
257
- └── my-content.json
258
- └── es
259
- └── my-content.json
260
- ```
99
+ Es wird empfohlen, automatisch generierte Intlayer-Dateien zu ignorieren:
261
100
 
262
- Jede Datei enthält kompilierte Nachrichten aus allen Intlayer-Inhaltsdeklarationen. Die obersten Schlüssel entsprechen typischerweise Ihren `content.key`-Feldern.
263
-
264
- ### Verwendung von next-intl in Ihrer Next.js-App
265
-
266
- > Für weitere Details siehe die offiziellen [next-intl-Nutzungsdokumente](https://github.com/amannn/next-intl#readme).
267
-
268
- 1. **Middleware erstellen (optional):**
269
- Wenn Sie die automatische Lokalisierung oder Weiterleitung verwalten möchten, verwenden Sie next-intls [createMiddleware](https://github.com/amannn/next-intl#createMiddleware).
270
-
271
- ```typescript fileName="middleware.ts"
272
- import createMiddleware from "next-intl/middleware";
273
- import { NextResponse } from "next/server";
274
-
275
- export default createMiddleware({
276
- locales: ["de", "fr", "es"],
277
- defaultLocale: "de",
278
- });
279
-
280
- export const config = {
281
- matcher: ["/((?!api|_next|.*\\..*).*)"],
282
- };
283
- ```
284
-
285
- 2. **Erstellen Sie eine `layout.tsx` oder `_app.tsx`, um Nachrichten zu laden:**
286
- Wenn Sie den App-Router verwenden (Next.js 13+), erstellen Sie ein Layout:
287
-
288
- ```typescript fileName="app/[locale]/layout.tsx"
289
- import { NextIntlClientProvider } from 'next-intl';
290
- import { notFound } from 'next/navigation';
291
- import React, { ReactNode } from 'react';
292
-
293
-
294
- export default async function RootLayout({
295
- children,
296
- params
297
- }: {
298
- children: ReactNode;
299
- params: { locale: string };
300
- }) {
301
- let messages;
302
- try {
303
- messages = (await import(`../../intl/messages/${params.locale}.json`)).default;
304
- } catch (error) {
305
- notFound();
306
- }
307
-
308
- return (
309
- <html lang={params.locale}>
310
- <body>
311
- <NextIntlClientProvider locale={params.locale} messages={messages}>
312
- {children}
313
- </NextIntlClientProvider>
314
- </body>
315
- </html>
316
- );
317
- }
318
- ```
319
-
320
- Wenn Sie den Pages-Router verwenden (Next.js 12 oder früher), laden Sie die Nachrichten in `_app.tsx`:
321
-
322
- ```typescript fileName="pages/_app.tsx"
323
- import type { AppProps } from 'next/app';
324
- import { NextIntlProvider } from 'next-intl';
325
-
326
- function MyApp({ Component, pageProps }: AppProps) {
327
- return (
328
- <NextIntlProvider locale={pageProps.locale} messages={pageProps.messages}>
329
- <Component {...pageProps} />
330
- </NextIntlProvider>
331
- );
332
- }
333
-
334
- export default MyApp;
335
- ```
336
-
337
- 3. **Nachrichten serverseitig abrufen (Pages Router-Beispiel):**
338
-
339
- ```typescript fileName="pages/index.tsx"
340
- import { GetServerSideProps } from "next";
341
- import HomePage from "../components/HomePage";
342
-
343
- export default HomePage;
344
-
345
- export const getServerSideProps: GetServerSideProps = async ({ locale }) => {
346
- const messages = (await import(`../intl/messages/${locale}.json`)).default;
347
-
348
- return {
349
- props: {
350
- locale,
351
- messages,
352
- },
353
- };
354
- };
355
- ```
356
-
357
- ### Verwendung von Inhalten in Next.js-Komponenten
358
-
359
- Sobald die Nachrichten in next-intl geladen sind, können Sie sie in Ihren Komponenten über den `useTranslations()`-Hook verwenden:
360
-
361
- ```typescript fileName="src/components/MyComponent/index.tsx" codeFormat="typescript"
362
- import type { FC } from "react";
363
- import { useTranslations } from 'next-intl';
364
-
365
- const MyComponent: FC = () => {
366
- const t = useTranslations('my-component');
367
- // 'my-component' entspricht dem Inhaltskey in Intlayer
368
-
369
- return (
370
- <div>
371
- <h1>{t('helloWorld')}</h1>
372
- </div>
373
- );
374
- };
375
-
376
- export default MyComponent;
101
+ ```plaintext fileName=".gitignore"
102
+ # Dateien, die von Intlayer generiert werden, ignorieren
103
+ .intlayer
377
104
  ```
378
105
 
379
- ```jsx fileName="src/components/MyComponent/index.jsx" codeFormat="esm"
380
- import { useTranslations } from "next-intl";
106
+ Diese Dateien können während Ihres Build-Prozesses neu generiert werden und müssen nicht in die Versionskontrolle aufgenommen werden.
381
107
 
382
- export default function MyComponent() {
383
- const t = useTranslations("my-component");
108
+ ### VS Code Erweiterung
384
109
 
385
- return (
386
- <div>
387
- <h1>{t("helloWorld")}</h1>
388
- </div>
389
- );
390
- }
391
- ```
110
+ Für eine verbesserte Entwicklererfahrung installieren Sie die offizielle **Intlayer VS Code Erweiterung**:
392
111
 
393
- **Das war's!** Jedes Mal, wenn Sie Intlayer-Inhaltsdeklarationsdateien aktualisieren oder hinzufügen, führen Sie den Befehl `intlayer build` erneut aus, um Ihre next-intl JSON-Nachrichten neu zu generieren. next-intl wird den aktualisierten Inhalt automatisch erkennen.
112
+ [Installation aus dem VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)