@intlayer/docs 7.0.4-canary.0 → 7.0.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/intlayer_with_i18next.md +68 -106
- package/blog/ar/intlayer_with_next-i18next.md +84 -288
- package/blog/ar/intlayer_with_next-intl.md +58 -337
- package/blog/ar/intlayer_with_react-i18next.md +68 -290
- package/blog/ar/intlayer_with_react-intl.md +63 -266
- package/blog/de/intlayer_with_i18next.md +77 -97
- package/blog/de/intlayer_with_next-i18next.md +69 -296
- package/blog/de/intlayer_with_next-intl.md +59 -340
- package/blog/de/intlayer_with_react-i18next.md +68 -290
- package/blog/de/intlayer_with_react-intl.md +62 -264
- package/blog/en/intlayer_with_i18next.md +36 -1638
- package/blog/en/intlayer_with_next-i18next.md +22 -847
- package/blog/en/intlayer_with_next-intl.md +32 -1053
- package/blog/en/intlayer_with_react-i18next.md +38 -764
- package/blog/en/intlayer_with_react-intl.md +42 -1018
- package/blog/en-GB/intlayer_with_i18next.md +67 -103
- package/blog/en-GB/intlayer_with_next-i18next.md +71 -292
- package/blog/en-GB/intlayer_with_next-intl.md +58 -337
- package/blog/en-GB/intlayer_with_react-i18next.md +67 -289
- package/blog/en-GB/intlayer_with_react-intl.md +61 -264
- package/blog/es/intlayer_with_i18next.md +67 -103
- package/blog/es/intlayer_with_next-i18next.md +71 -296
- package/blog/es/intlayer_with_next-intl.md +57 -338
- package/blog/es/intlayer_with_react-i18next.md +68 -290
- package/blog/es/intlayer_with_react-intl.md +62 -265
- package/blog/fr/intlayer_with_i18next.md +66 -104
- package/blog/fr/intlayer_with_next-i18next.md +82 -285
- package/blog/fr/intlayer_with_next-intl.md +57 -338
- package/blog/fr/intlayer_with_react-i18next.md +67 -289
- package/blog/fr/intlayer_with_react-intl.md +61 -264
- package/blog/hi/intlayer_with_i18next.md +68 -104
- package/blog/hi/intlayer_with_next-i18next.md +74 -299
- package/blog/hi/intlayer_with_next-intl.md +57 -239
- package/blog/hi/intlayer_with_react-i18next.md +69 -291
- package/blog/hi/intlayer_with_react-intl.md +65 -268
- package/blog/id/intlayer_with_i18next.md +126 -0
- package/blog/id/intlayer_with_next-i18next.md +142 -0
- package/blog/id/intlayer_with_next-intl.md +113 -0
- package/blog/id/intlayer_with_react-i18next.md +124 -0
- package/blog/id/intlayer_with_react-intl.md +122 -0
- package/blog/it/intlayer_with_i18next.md +67 -103
- package/blog/it/intlayer_with_next-i18next.md +71 -296
- package/blog/it/intlayer_with_next-intl.md +57 -338
- package/blog/it/intlayer_with_react-i18next.md +68 -290
- package/blog/it/intlayer_with_react-intl.md +62 -265
- package/blog/ja/intlayer_with_i18next.md +68 -103
- package/blog/ja/intlayer_with_next-i18next.md +85 -283
- package/blog/ja/intlayer_with_next-intl.md +58 -336
- package/blog/ja/intlayer_with_react-i18next.md +68 -290
- package/blog/ja/intlayer_with_react-intl.md +62 -264
- package/blog/ko/intlayer_with_i18next.md +80 -96
- package/blog/ko/intlayer_with_next-i18next.md +85 -287
- package/blog/ko/intlayer_with_next-intl.md +68 -327
- package/blog/ko/intlayer_with_react-i18next.md +68 -290
- package/blog/ko/intlayer_with_react-intl.md +64 -266
- package/blog/pl/intlayer_with_i18next.md +126 -0
- package/blog/pl/intlayer_with_next-i18next.md +142 -0
- package/blog/pl/intlayer_with_next-intl.md +111 -0
- package/blog/pl/intlayer_with_react-i18next.md +124 -0
- package/blog/pl/intlayer_with_react-intl.md +122 -0
- package/blog/pt/intlayer_with_i18next.md +67 -103
- package/blog/pt/intlayer_with_next-i18next.md +72 -293
- package/blog/pt/intlayer_with_next-intl.md +57 -256
- package/blog/pt/intlayer_with_react-i18next.md +104 -78
- package/blog/pt/intlayer_with_react-intl.md +62 -266
- package/blog/ru/intlayer_with_i18next.md +66 -104
- package/blog/ru/intlayer_with_next-i18next.md +71 -296
- package/blog/ru/intlayer_with_next-intl.md +58 -337
- package/blog/ru/intlayer_with_react-i18next.md +68 -290
- package/blog/ru/intlayer_with_react-intl.md +62 -265
- package/blog/tr/intlayer_with_i18next.md +71 -107
- package/blog/tr/intlayer_with_next-i18next.md +72 -297
- package/blog/tr/intlayer_with_next-intl.md +58 -339
- package/blog/tr/intlayer_with_react-i18next.md +69 -291
- package/blog/tr/intlayer_with_react-intl.md +63 -285
- package/blog/vi/intlayer_with_i18next.md +126 -0
- package/blog/vi/intlayer_with_next-i18next.md +142 -0
- package/blog/vi/intlayer_with_next-intl.md +111 -0
- package/blog/vi/intlayer_with_react-i18next.md +124 -0
- package/blog/vi/intlayer_with_react-intl.md +122 -0
- package/blog/zh/intlayer_with_i18next.md +67 -102
- package/blog/zh/intlayer_with_next-i18next.md +72 -296
- package/blog/zh/intlayer_with_next-intl.md +58 -336
- package/blog/zh/intlayer_with_react-i18next.md +68 -290
- package/blog/zh/intlayer_with_react-intl.md +63 -106
- package/docs/ar/plugins/sync-json.md +244 -0
- package/docs/de/plugins/sync-json.md +244 -0
- package/docs/en/intlayer_cli.md +25 -0
- package/docs/en/intlayer_with_nextjs_14.md +2 -0
- package/docs/en/intlayer_with_nextjs_15.md +2 -0
- package/docs/en/intlayer_with_nextjs_16.md +2 -0
- package/docs/en/plugins/sync-json.md +1 -1
- package/docs/en-GB/plugins/sync-json.md +244 -0
- package/docs/es/plugins/sync-json.md +244 -0
- package/docs/fr/plugins/sync-json.md +244 -0
- package/docs/hi/plugins/sync-json.md +244 -0
- package/docs/id/plugins/sync-json.md +244 -0
- package/docs/it/plugins/sync-json.md +244 -0
- package/docs/ja/plugins/sync-json.md +244 -0
- package/docs/ko/plugins/sync-json.md +244 -0
- package/docs/pl/plugins/sync-json.md +244 -0
- package/docs/pt/plugins/sync-json.md +244 -0
- package/docs/ru/plugins/sync-json.md +244 -0
- package/docs/tr/plugins/sync-json.md +245 -0
- package/docs/vi/plugins/sync-json.md +244 -0
- package/docs/zh/plugins/sync-json.md +244 -0
- package/package.json +14 -14
|
@@ -1,367 +1,140 @@
|
|
|
1
1
|
---
|
|
2
2
|
createdAt: 2025-08-23
|
|
3
|
-
updatedAt: 2025-
|
|
3
|
+
updatedAt: 2025-10-29
|
|
4
4
|
title: Intlayer und next-i18next
|
|
5
|
-
description:
|
|
5
|
+
description: Integration von Intlayer mit next-i18next für eine umfassende Internationalisierungslösung in Next.js
|
|
6
6
|
keywords:
|
|
7
7
|
- i18next
|
|
8
8
|
- next-i18next
|
|
9
9
|
- Intlayer
|
|
10
10
|
- Internationalisierung
|
|
11
|
-
-
|
|
11
|
+
- Blog
|
|
12
12
|
- Next.js
|
|
13
13
|
- JavaScript
|
|
14
14
|
- React
|
|
15
15
|
slugs:
|
|
16
16
|
- blog
|
|
17
17
|
- intlayer-with-next-i18next
|
|
18
|
+
history:
|
|
19
|
+
- version: 7.0.0
|
|
20
|
+
date: 2025-10-29
|
|
21
|
+
changes: Wechsel zum syncJSON-Plugin und umfassende Überarbeitung
|
|
18
22
|
---
|
|
19
23
|
|
|
20
24
|
# Next.js Internationalisierung (i18n) mit next-i18next und Intlayer
|
|
21
25
|
|
|
22
|
-
|
|
26
|
+
## Inhaltsverzeichnis
|
|
23
27
|
|
|
24
|
-
|
|
28
|
+
<TOC/>
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
- Im Falle von `i18next` als `resource` bezeichnet, ist die Inhaltsdeklaration ein strukturiertes JSON-Objekt, das Schlüssel-Wert-Paare für Übersetzungen in einer oder mehreren Sprachen enthält. Siehe [i18next-Dokumentation](https://www.i18next.com/translation-function/essentials) für weitere Informationen.
|
|
28
|
-
- Im Falle von `Intlayer` als `content declaration file` bezeichnet, kann die Inhaltsdeklaration eine JSON-, JS- oder TS-Datei sein, die die strukturierten Daten exportiert. Siehe [Intlayer-Dokumentation](https://intlayer.org/fr/doc/concept/content) für weitere Informationen.
|
|
30
|
+
## Was ist next-i18next?
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
**next-i18next** ist eines der beliebtesten Internationalisierungs- (i18n) Frameworks für Next.js-Anwendungen. Es basiert auf dem leistungsstarken **i18next**-Ökosystem und bietet eine umfassende Lösung zur Verwaltung von Übersetzungen, Lokalisierung und Sprachwechsel in Next.js-Projekten.
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
Allerdings bringt next-i18next einige Herausforderungen mit sich:
|
|
33
35
|
|
|
34
|
-
|
|
36
|
+
- **Komplexe Konfiguration**: Die Einrichtung von next-i18next erfordert mehrere Konfigurationsdateien und eine sorgfältige Einrichtung der i18n-Instanzen auf Server- und Client-Seite.
|
|
37
|
+
- **Verstreute Übersetzungen**: Übersetzungsdateien werden typischerweise in separaten Verzeichnissen von den Komponenten gespeichert, was die Konsistenz erschwert.
|
|
38
|
+
- **Manuelle Namespace-Verwaltung**: Entwickler müssen Namespaces manuell verwalten und sicherstellen, dass die Übersetzungsressourcen korrekt geladen werden.
|
|
39
|
+
- **Begrenzte Typsicherheit**: Die TypeScript-Unterstützung erfordert zusätzliche Konfiguration und bietet keine automatische Typgenerierung für Übersetzungen.
|
|
35
40
|
|
|
36
|
-
|
|
41
|
+
## Was ist Intlayer?
|
|
37
42
|
|
|
38
|
-
|
|
43
|
+
**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.
|
|
39
44
|
|
|
40
|
-
|
|
45
|
+
Eine konkrete Gegenüberstellung mit next-intl finden Sie 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).
|
|
41
46
|
|
|
42
|
-
|
|
47
|
+
## Warum Intlayer mit next-i18next kombinieren?
|
|
43
48
|
|
|
44
|
-
|
|
49
|
+
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-i18next kombinieren:
|
|
45
50
|
|
|
46
|
-
|
|
51
|
+
1. **Bestehender Codebestand**: Sie haben eine etablierte next-i18next-Implementierung und möchten schrittweise zur verbesserten Entwicklererfahrung von Intlayer migrieren.
|
|
52
|
+
2. **Altsystemanforderungen**: Ihr Projekt erfordert Kompatibilität mit bestehenden i18next-Plugins oder Workflows.
|
|
53
|
+
3. **Teamvertrautheit**: Ihr Team ist mit next-i18next vertraut, möchte aber ein besseres Content-Management.
|
|
47
54
|
|
|
48
|
-
|
|
49
|
-
.
|
|
50
|
-
└── src
|
|
51
|
-
└── components
|
|
52
|
-
└── MyComponent
|
|
53
|
-
├── index.content.ts # Inhaltsdeklarationsdatei
|
|
54
|
-
└── index.tsx
|
|
55
|
-
```
|
|
55
|
+
**Dafür kann Intlayer als Adapter für next-i18next implementiert werden, um Ihre JSON-Übersetzungen in CLI- oder CI/CD-Pipelines zu automatisieren, Ihre Übersetzungen zu testen und mehr.**
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
.
|
|
59
|
-
└── src
|
|
60
|
-
└── components
|
|
61
|
-
└── MyComponent
|
|
62
|
-
├── index.content.mjs # Inhaltsdeklarationsdatei
|
|
63
|
-
└── index.mjx
|
|
64
|
-
```
|
|
57
|
+
Dieser Leitfaden zeigt Ihnen, wie Sie das überlegene Inhaltsdeklarationssystem von Intlayer nutzen können, während Sie die Kompatibilität mit next-i18next beibehalten.
|
|
65
58
|
|
|
66
|
-
|
|
67
|
-
.
|
|
68
|
-
└── src
|
|
69
|
-
└── components
|
|
70
|
-
└── MyComponent
|
|
71
|
-
├── index.content.cjs # Inhaltsdeklarationsdatei
|
|
72
|
-
└── index.cjx
|
|
73
|
-
```
|
|
59
|
+
---
|
|
74
60
|
|
|
75
|
-
|
|
76
|
-
.
|
|
77
|
-
└── src
|
|
78
|
-
└── components
|
|
79
|
-
└── MyComponent
|
|
80
|
-
├── index.content.json # Inhaltsdeklarationsdatei
|
|
81
|
-
└── index.jsx
|
|
82
|
-
```
|
|
61
|
+
## Schritt-für-Schritt-Anleitung zur Einrichtung von Intlayer mit next-i18next
|
|
83
62
|
|
|
84
|
-
|
|
63
|
+
### Schritt 1: Abhängigkeiten installieren
|
|
85
64
|
|
|
86
|
-
|
|
65
|
+
Installieren Sie die notwendigen Pakete mit Ihrem bevorzugten Paketmanager:
|
|
87
66
|
|
|
88
67
|
```bash packageManager="npm"
|
|
89
|
-
npm install intlayer
|
|
68
|
+
npm install intlayer @intlayer/sync-json-plugin
|
|
90
69
|
```
|
|
91
70
|
|
|
92
|
-
```bash packageManager="
|
|
93
|
-
|
|
71
|
+
```bash packageManager="pnpm"
|
|
72
|
+
pnpm add intlayer @intlayer/sync-json-plugin
|
|
94
73
|
```
|
|
95
74
|
|
|
96
|
-
```bash packageManager="
|
|
97
|
-
|
|
75
|
+
```bash packageManager="yarn"
|
|
76
|
+
yarn add intlayer @intlayer/sync-json-plugin
|
|
98
77
|
```
|
|
99
78
|
|
|
100
|
-
|
|
79
|
+
**Paket-Erklärungen:**
|
|
80
|
+
|
|
81
|
+
- **intlayer**: Kernbibliothek für Inhaltsdeklaration und -verwaltung
|
|
82
|
+
- **next-intlayer**: Next.js-Integrationsschicht mit Build-Plugins
|
|
83
|
+
- **i18next**: Kern-i18n-Framework
|
|
84
|
+
- **next-i18next**: Next.js-Wrapper für i18next
|
|
85
|
+
- **i18next-resources-to-backend**: Dynamisches Ressourcenladen für i18next
|
|
86
|
+
- **@intlayer/sync-json-plugin**: Plugin zum Synchronisieren von Intlayer-Inhaltsdeklarationen im i18next JSON-Format
|
|
101
87
|
|
|
102
|
-
|
|
88
|
+
### Schritt 2: Implementieren Sie das Intlayer-Plugin zum Verpacken des JSON
|
|
103
89
|
|
|
104
|
-
|
|
90
|
+
Erstellen Sie eine Intlayer-Konfigurationsdatei, um Ihre unterstützten Sprachen zu definieren:
|
|
105
91
|
|
|
106
|
-
|
|
92
|
+
**Wenn Sie auch JSON-Wörterbücher für i18next exportieren möchten**, fügen Sie das `syncJSON`-Plugin hinzu:
|
|
93
|
+
|
|
94
|
+
```typescript fileName="intlayer.config.ts"
|
|
107
95
|
import { Locales, type IntlayerConfig } from "intlayer";
|
|
96
|
+
import { syncJSON } from "@intlayer/sync-json-plugin";
|
|
108
97
|
|
|
109
98
|
const config: IntlayerConfig = {
|
|
110
99
|
internationalization: {
|
|
111
100
|
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
112
101
|
defaultLocale: Locales.ENGLISH,
|
|
113
102
|
},
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
103
|
+
plugins: [
|
|
104
|
+
syncJSON({
|
|
105
|
+
source: ({ key, locale }) => `./messages/${locale}/${key}.json`,
|
|
106
|
+
}),
|
|
107
|
+
],
|
|
118
108
|
};
|
|
119
109
|
|
|
120
110
|
export default config;
|
|
121
111
|
```
|
|
122
112
|
|
|
123
|
-
|
|
124
|
-
import { Locales } from "intlayer";
|
|
113
|
+
Das `syncJSON`-Plugin wird das JSON automatisch umschließen. Es liest und schreibt die JSON-Dateien, ohne die Inhaltsarchitektur zu verändern.
|
|
125
114
|
|
|
126
|
-
|
|
127
|
-
const config = {
|
|
128
|
-
internationalization: {
|
|
129
|
-
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
130
|
-
defaultLocale: Locales.ENGLISH,
|
|
131
|
-
},
|
|
132
|
-
content: {
|
|
133
|
-
dictionaryOutput: ["i18next"],
|
|
134
|
-
i18nextResourcesDir: "./i18next/resources",
|
|
135
|
-
},
|
|
136
|
-
};
|
|
115
|
+
Wenn Sie möchten, dass dieses JSON zusammen mit Intlayer-Inhaltsdeklarationsdateien (`.content`-Dateien) koexistiert, wird Intlayer folgendermaßen vorgehen:
|
|
137
116
|
|
|
138
|
-
|
|
139
|
-
|
|
117
|
+
1. Lädt sowohl JSON- als auch Inhaltsdeklarationsdateien und transformiert sie in ein Intlayer-Wörterbuch.
|
|
118
|
+
2. Wenn es Konflikte zwischen den JSON- und den Inhaltsdeklarationsdateien gibt, wird Intlayer alle Wörterbücher zusammenführen. Dies geschieht abhängig von der Priorität der Plugins und der der Inhaltsdeklarationsdatei (alle sind konfigurierbar).
|
|
140
119
|
|
|
141
|
-
|
|
142
|
-
const { Locales } = require("intlayer");
|
|
143
|
-
|
|
144
|
-
/** @type {import('intlayer').IntlayerConfig} */
|
|
145
|
-
const config = {
|
|
146
|
-
internationalization: {
|
|
147
|
-
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
148
|
-
defaultLocale: Locales.ENGLISH,
|
|
149
|
-
},
|
|
150
|
-
content: {
|
|
151
|
-
dictionaryOutput: ["i18next"],
|
|
152
|
-
i18nextResourcesDir: "./i18next/resources",
|
|
153
|
-
},
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
module.exports = config;
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
Hier ist die Fortsetzung und Korrektur der verbleibenden Teile Ihres Dokuments:
|
|
120
|
+
Wenn Änderungen über die CLI zur Übersetzung der JSON-Dateien oder über das CMS vorgenommen werden, aktualisiert Intlayer die JSON-Datei mit den neuen Übersetzungen.
|
|
160
121
|
|
|
161
122
|
---
|
|
162
123
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
Um die generierten Ressourcen in Ihre i18next-Konfiguration zu importieren, verwenden Sie `i18next-resources-to-backend`. Nachfolgend einige Beispiele:
|
|
166
|
-
|
|
167
|
-
```typescript fileName="i18n/client.ts" codeFormat="typescript"
|
|
168
|
-
import i18next from "i18next";
|
|
169
|
-
import resourcesToBackend from "i18next-resources-to-backend";
|
|
170
|
-
|
|
171
|
-
i18next.use(
|
|
172
|
-
resourcesToBackend(
|
|
173
|
-
(language: string, namespace: string) =>
|
|
174
|
-
import(`../i18next/resources/${language}/${namespace}.json`)
|
|
175
|
-
)
|
|
176
|
-
);
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
```javascript fileName="i18n/client.mjs" codeFormat="esm"
|
|
180
|
-
import i18next from "i18next";
|
|
181
|
-
import resourcesToBackend from "i18next-resources-to-backend";
|
|
182
|
-
|
|
183
|
-
i18next.use(
|
|
184
|
-
resourcesToBackend(
|
|
185
|
-
(language, namespace) =>
|
|
186
|
-
import(`../i18next/resources/${language}/${namespace}.json`)
|
|
187
|
-
)
|
|
188
|
-
);
|
|
189
|
-
```
|
|
124
|
+
## Git-Konfiguration
|
|
190
125
|
|
|
191
|
-
|
|
192
|
-
const i18next = require("i18next");
|
|
193
|
-
const resourcesToBackend = require("i18next-resources-to-backend");
|
|
126
|
+
Schließen Sie generierte Dateien von der Versionskontrolle aus:
|
|
194
127
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
)
|
|
200
|
-
);
|
|
128
|
+
```plaintext fileName=".gitignore"
|
|
129
|
+
# Ignoriere von Intlayer generierte Dateien
|
|
130
|
+
.intlayer
|
|
131
|
+
intl
|
|
201
132
|
```
|
|
202
133
|
|
|
203
|
-
|
|
134
|
+
Diese Dateien werden während des Build-Prozesses automatisch neu generiert und müssen nicht in Ihr Repository eingecheckt werden.
|
|
204
135
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
```typescript fileName="**/*.content.ts" contentDeclarationFormat="typescript"
|
|
208
|
-
import { t, type Dictionary } from "intlayer";
|
|
209
|
-
|
|
210
|
-
const content = {
|
|
211
|
-
key: "my-content",
|
|
212
|
-
content: {
|
|
213
|
-
myTranslatedContent: t({
|
|
214
|
-
en: "Hello World",
|
|
215
|
-
es: "Hola Mundo",
|
|
216
|
-
fr: "Bonjour le monde",
|
|
217
|
-
}),
|
|
218
|
-
},
|
|
219
|
-
} satisfies Dictionary;
|
|
220
|
-
|
|
221
|
-
export default content;
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
```javascript fileName="**/*.content.mjs" contentDeclarationFormat="esm"
|
|
225
|
-
import { t } from "intlayer";
|
|
226
|
-
|
|
227
|
-
/** @type {import('intlayer').Dictionary} */
|
|
228
|
-
const content = {
|
|
229
|
-
key: "my-content",
|
|
230
|
-
content: {
|
|
231
|
-
myTranslatedContent: t({
|
|
232
|
-
en: "Hello World",
|
|
233
|
-
es: "Hola Mundo",
|
|
234
|
-
fr: "Bonjour le monde",
|
|
235
|
-
}),
|
|
236
|
-
},
|
|
237
|
-
};
|
|
238
|
-
```
|
|
136
|
+
### VS Code Erweiterung
|
|
239
137
|
|
|
240
|
-
|
|
241
|
-
const { t } = require("intlayer");
|
|
138
|
+
Für eine verbesserte Entwicklererfahrung installieren Sie die offizielle **Intlayer VS Code Erweiterung**:
|
|
242
139
|
|
|
243
|
-
|
|
244
|
-
key: "my-content",
|
|
245
|
-
content: {
|
|
246
|
-
myTranslatedContent: t({
|
|
247
|
-
en: "Hello World",
|
|
248
|
-
es: "Hola Mundo",
|
|
249
|
-
fr: "Bonjour le monde",
|
|
250
|
-
}),
|
|
251
|
-
},
|
|
252
|
-
};
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
```json fileName="**/*.content.json" contentDeclarationFormat="json"
|
|
256
|
-
{
|
|
257
|
-
"$schema": "https://intlayer.org/schema.json",
|
|
258
|
-
"key": "my-content",
|
|
259
|
-
"content": {
|
|
260
|
-
"myTranslatedContent": {
|
|
261
|
-
"nodeType": "translation",
|
|
262
|
-
"translation": {
|
|
263
|
-
"en": "Hello World",
|
|
264
|
-
"fr": "Bonjour le monde",
|
|
265
|
-
"es": "Hola Mundo"
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
### Erstellen der next-i18next Ressourcen
|
|
273
|
-
|
|
274
|
-
Um die next-i18next Ressourcen zu erstellen, führen Sie den folgenden Befehl aus:
|
|
275
|
-
|
|
276
|
-
```bash packageManager="npm"
|
|
277
|
-
npx run intlayer build
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
```bash packageManager="yarn"
|
|
281
|
-
yarn intlayer build
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
```bash packageManager="pnpm"
|
|
285
|
-
pnpm intlayer build
|
|
286
|
-
```
|
|
287
|
-
|
|
288
|
-
Dies generiert Ressourcen im Verzeichnis `./i18next/resources`. Die erwartete Ausgabe:
|
|
289
|
-
|
|
290
|
-
```bash
|
|
291
|
-
.
|
|
292
|
-
└── i18next
|
|
293
|
-
└── resources
|
|
294
|
-
└── en
|
|
295
|
-
└── my-content.json
|
|
296
|
-
└── fr
|
|
297
|
-
└── my-content.json
|
|
298
|
-
└── es
|
|
299
|
-
└── my-content.json
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
Hinweis: Der i18next-Namespace entspricht dem Intlayer-Deklarationsschlüssel.
|
|
303
|
-
|
|
304
|
-
### Next.js-Plugin implementieren
|
|
305
|
-
|
|
306
|
-
Sobald konfiguriert, implementieren Sie das Next.js-Plugin, um Ihre i18next-Ressourcen neu zu erstellen, wann immer die Intlayer-Inhaltsdeklarationsdateien aktualisiert werden.
|
|
307
|
-
|
|
308
|
-
```typescript fileName="next.config.mjs"
|
|
309
|
-
import { withIntlayer } from "next-intlayer/server";
|
|
310
|
-
|
|
311
|
-
/** @type {import('next').NextConfig} */
|
|
312
|
-
const nextConfig = {};
|
|
313
|
-
|
|
314
|
-
export default withIntlayer(nextConfig);
|
|
315
|
-
```
|
|
316
|
-
|
|
317
|
-
### Verwendung von Inhalten in Next.js-Komponenten
|
|
318
|
-
|
|
319
|
-
Nachdem Sie das Next.js-Plugin implementiert haben, können Sie den Inhalt in Ihren Komponenten verwenden:
|
|
320
|
-
|
|
321
|
-
```typescript fileName="src/components/myComponent/index.tsx" codeFormat="typescript"
|
|
322
|
-
import type { FC } from "react";
|
|
323
|
-
import { useTranslation } from "react-i18next";
|
|
324
|
-
|
|
325
|
-
const IndexPage: FC = () => {
|
|
326
|
-
const { t } = useTranslation();
|
|
327
|
-
|
|
328
|
-
return (
|
|
329
|
-
<div>
|
|
330
|
-
<h1>{t("my-content.title")}</h1>
|
|
331
|
-
<p>{t("my-content.description")}</p>
|
|
332
|
-
</div>
|
|
333
|
-
);
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
export default IndexPage;
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
```jsx fileName="src/components/myComponent/index.mjx" codeFormat="esm"
|
|
340
|
-
import { useTranslation } from "react-i18next";
|
|
341
|
-
|
|
342
|
-
const IndexPage = () => {
|
|
343
|
-
const { t } = useTranslation();
|
|
344
|
-
|
|
345
|
-
return (
|
|
346
|
-
<div>
|
|
347
|
-
<h1>{t("my-content.title")}</h1>
|
|
348
|
-
<p>{t("my-content.description")}</p>
|
|
349
|
-
</div>
|
|
350
|
-
);
|
|
351
|
-
};
|
|
352
|
-
```
|
|
353
|
-
|
|
354
|
-
```jsx fileName="src/components/myComponent/index.cjx" codeFormat="commonjs"
|
|
355
|
-
const { useTranslation } = require("react-i18next");
|
|
356
|
-
|
|
357
|
-
const IndexPage = () => {
|
|
358
|
-
const { t } = useTranslation();
|
|
359
|
-
|
|
360
|
-
return (
|
|
361
|
-
<div>
|
|
362
|
-
<h1>{t("my-content.title")}</h1>
|
|
363
|
-
<p>{t("my-content.description")}</p>
|
|
364
|
-
</div>
|
|
365
|
-
);
|
|
366
|
-
};
|
|
367
|
-
```
|
|
140
|
+
[Installation aus dem VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|