@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.
- 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 +67 -103
- package/blog/en/intlayer_with_next-i18next.md +69 -294
- package/blog/en/intlayer_with_next-intl.md +48 -300
- package/blog/en/intlayer_with_react-i18next.md +61 -289
- package/blog/en/intlayer_with_react-intl.md +61 -284
- package/blog/en/next-i18next_vs_next-intl_vs_intlayer.md +1 -1
- 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/dist/cjs/generated/blog.entry.cjs +13 -1
- package/dist/cjs/generated/blog.entry.cjs.map +1 -1
- package/dist/cjs/generated/docs.entry.cjs +13 -1
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/cjs/generated/frequentQuestions.entry.cjs +13 -1
- package/dist/cjs/generated/frequentQuestions.entry.cjs.map +1 -1
- package/dist/cjs/generated/legal.entry.cjs +13 -1
- package/dist/cjs/generated/legal.entry.cjs.map +1 -1
- package/dist/esm/generated/blog.entry.mjs +13 -2
- package/dist/esm/generated/blog.entry.mjs.map +1 -1
- package/dist/esm/generated/docs.entry.mjs +13 -2
- package/dist/esm/generated/docs.entry.mjs.map +1 -1
- package/dist/esm/generated/frequentQuestions.entry.mjs +13 -2
- package/dist/esm/generated/frequentQuestions.entry.mjs.map +1 -1
- package/dist/esm/generated/legal.entry.mjs +13 -2
- package/dist/esm/generated/legal.entry.mjs.map +1 -1
- package/dist/types/generated/blog.entry.d.ts.map +1 -1
- package/dist/types/generated/docs.entry.d.ts.map +1 -1
- package/dist/types/generated/frequentQuestions.entry.d.ts.map +1 -1
- package/dist/types/generated/legal.entry.d.ts.map +1 -1
- package/docs/ar/plugins/sync-json.md +244 -0
- package/docs/de/plugins/sync-json.md +244 -0
- package/docs/de/releases/v7.md +1 -18
- package/docs/en/CI_CD.md +1 -1
- package/docs/en/configuration.md +1 -1
- package/docs/en/formatters.md +1 -1
- package/docs/en/how_works_intlayer.md +1 -1
- package/docs/en/intlayer_CMS.md +1 -1
- package/docs/en/intlayer_cli.md +26 -1
- package/docs/en/intlayer_with_nextjs_14.md +3 -1
- package/docs/en/intlayer_with_nextjs_15.md +3 -1
- package/docs/en/intlayer_with_nextjs_16.md +3 -1
- package/docs/en/intlayer_with_nextjs_page_router.md +1 -1
- package/docs/en/intlayer_with_nuxt.md +1 -1
- package/docs/en/intlayer_with_react_native+expo.md +1 -1
- package/docs/en/intlayer_with_react_router_v7.md +1 -1
- package/docs/en/intlayer_with_tanstack.md +1 -1
- package/docs/en/intlayer_with_vite+preact.md +1 -1
- package/docs/en/intlayer_with_vite+react.md +1 -1
- package/docs/en/intlayer_with_vite+solid.md +1 -1
- package/docs/en/intlayer_with_vite+svelte.md +1 -1
- package/docs/en/intlayer_with_vite+vue.md +1 -1
- package/docs/en/plugins/sync-json.md +1 -1
- package/docs/en/roadmap.md +1 -1
- package/docs/en-GB/plugins/sync-json.md +244 -0
- package/docs/es/plugins/sync-json.md +244 -0
- package/docs/es/releases/v7.md +1 -18
- package/docs/fr/intlayer_with_nextjs_16.md +2 -51
- package/docs/fr/plugins/sync-json.md +244 -0
- package/docs/fr/releases/v7.md +1 -18
- package/docs/hi/intlayer_with_nextjs_16.md +3 -2
- package/docs/hi/plugins/sync-json.md +244 -0
- package/docs/id/plugins/sync-json.md +244 -0
- package/docs/id/releases/v7.md +1 -18
- package/docs/it/plugins/sync-json.md +244 -0
- package/docs/it/releases/v7.md +1 -18
- package/docs/ja/intlayer_with_nextjs_16.md +44 -205
- package/docs/ja/plugins/sync-json.md +244 -0
- package/docs/ja/releases/v7.md +1 -18
- package/docs/ko/plugins/sync-json.md +244 -0
- package/docs/ko/releases/v7.md +1 -18
- package/docs/pl/plugins/sync-json.md +244 -0
- package/docs/pt/intlayer_with_nextjs_16.md +1 -52
- 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
- package/src/generated/blog.entry.ts +26 -3
- package/src/generated/docs.entry.ts +26 -3
- package/src/generated/frequentQuestions.entry.ts +26 -3
- package/src/generated/legal.entry.ts +26 -3
|
@@ -1,325 +1,123 @@
|
|
|
1
1
|
---
|
|
2
2
|
createdAt: 2025-01-02
|
|
3
|
-
updatedAt: 2025-
|
|
4
|
-
title:
|
|
5
|
-
description:
|
|
3
|
+
updatedAt: 2025-10-29
|
|
4
|
+
title: Wie Sie Ihre react-intl JSON-Übersetzungen mit Intlayer automatisieren
|
|
5
|
+
description: Automatisieren Sie Ihre JSON-Übersetzungen mit Intlayer und react-intl für verbesserte Internationalisierung in React-Anwendungen.
|
|
6
6
|
keywords:
|
|
7
7
|
- react-intl
|
|
8
8
|
- Intlayer
|
|
9
9
|
- Internationalisierung
|
|
10
|
-
-
|
|
11
|
-
-
|
|
10
|
+
- Blog
|
|
11
|
+
- i18n
|
|
12
12
|
- JavaScript
|
|
13
13
|
- React
|
|
14
|
+
- FormatJS
|
|
14
15
|
slugs:
|
|
15
16
|
- blog
|
|
16
17
|
- intlayer-with-react-intl
|
|
18
|
+
history:
|
|
19
|
+
- version: 7.0.0
|
|
20
|
+
date: 2025-10-29
|
|
21
|
+
changes: Wechsel zum syncJSON-Plugin
|
|
17
22
|
---
|
|
18
23
|
|
|
19
|
-
#
|
|
24
|
+
# Wie Sie Ihre react-intl JSON-Übersetzungen mit Intlayer automatisieren
|
|
20
25
|
|
|
21
|
-
|
|
26
|
+
## Was ist Intlayer?
|
|
22
27
|
|
|
23
|
-
|
|
28
|
+
**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 React-Anwendungen.
|
|
24
29
|
|
|
25
|
-
|
|
26
|
-
- **react-intl** bietet React-Komponenten und Hooks (wie `<FormattedMessage>` und `useIntl()`), um lokalisierte Strings anzuzeigen.
|
|
30
|
+
Sehen Sie einen konkreten Vergleich mit react-intl in unserem Blogbeitrag [react-i18next vs. react-intl vs. Intlayer](https://github.com/aymericzip/intlayer/blob/main/docs/blog/de/react-i18next_vs_react-intl_vs_intlayer.md).
|
|
27
31
|
|
|
28
|
-
|
|
32
|
+
## Warum Intlayer mit react-intl kombinieren?
|
|
29
33
|
|
|
30
|
-
|
|
34
|
+
Während Intlayer eine hervorragende eigenständige i18n-Lösung bietet (siehe unseren [React-Integrationsleitfaden](https://github.com/aymericzip/intlayer/blob/main/docs/docs/de/intlayer_with_vite+react.md)), möchten Sie es möglicherweise aus mehreren Gründen mit react-intl kombinieren:
|
|
31
35
|
|
|
32
|
-
|
|
36
|
+
1. **Bestehender Codebestand**: Sie haben eine etablierte react-intl-Implementierung und möchten schrittweise auf die verbesserte Entwicklererfahrung von Intlayer umsteigen.
|
|
37
|
+
2. **Altsystemanforderungen**: Ihr Projekt erfordert Kompatibilität mit bestehenden react-intl-Plugins oder Workflows.
|
|
38
|
+
3. **Teamvertrautheit**: Ihr Team ist mit react-intl vertraut, möchte aber ein besseres Content-Management.
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
Intlayer-Inhaltsdeklarationsdateien können neben Ihren React-Komponenten leben, um „verwaiste“ Übersetzungen zu verhindern, wenn Komponenten verschoben oder entfernt werden. Zum Beispiel:
|
|
40
|
+
**Dafür kann Intlayer als Adapter für react-intl implementiert werden, um Ihre JSON-Übersetzungen in CLI- oder CI/CD-Pipelines zu automatisieren, Ihre Übersetzungen zu testen und mehr.**
|
|
36
41
|
|
|
37
|
-
|
|
38
|
-
.
|
|
39
|
-
└── src
|
|
40
|
-
└── components
|
|
41
|
-
└── MyComponent
|
|
42
|
-
├── index.content.ts # Intlayer Inhaltsdeklaration
|
|
43
|
-
└── index.tsx # React-Komponente
|
|
44
|
-
```
|
|
42
|
+
Dieser Leitfaden zeigt Ihnen, wie Sie das überlegene Content-Deklarationssystem von Intlayer nutzen können, während Sie die Kompatibilität mit react-intl beibehalten.
|
|
45
43
|
|
|
46
|
-
|
|
47
|
-
Jede Inhaltsdeklarationsdatei sammelt alle Übersetzungen, die eine Komponente benötigt. Dies ist besonders hilfreich in TypeScript-Projekten: Fehlende Übersetzungen können zur **Kompilierungszeit** gefangen werden.
|
|
44
|
+
## Inhaltsverzeichnis
|
|
48
45
|
|
|
49
|
-
|
|
50
|
-
Immer wenn Sie Übersetzungen hinzufügen oder aktualisieren, regeneriert Intlayer die Nachrichten-JSON-Dateien. Diese können Sie dann in react-intl's `<IntlProvider>` übergeben.
|
|
46
|
+
<TOC/>
|
|
51
47
|
|
|
52
|
-
|
|
48
|
+
## Schritt-für-Schritt-Anleitung zur Einrichtung von Intlayer mit react-intl
|
|
53
49
|
|
|
54
|
-
|
|
50
|
+
### Schritt 1: Abhängigkeiten installieren
|
|
55
51
|
|
|
56
|
-
|
|
52
|
+
Installieren Sie die notwendigen Pakete:
|
|
57
53
|
|
|
58
|
-
```bash
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
```bash packageManager="npm"
|
|
55
|
+
npm install intlayer @intlayer/sync-json-plugin
|
|
56
|
+
```
|
|
61
57
|
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
```bash packageManager="pnpm"
|
|
59
|
+
pnpm add intlayer @intlayer/sync-json-plugin
|
|
60
|
+
```
|
|
64
61
|
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
```bash packageManager="yarn"
|
|
63
|
+
yarn add intlayer @intlayer/sync-json-plugin
|
|
67
64
|
```
|
|
68
65
|
|
|
69
|
-
|
|
66
|
+
**Paketbeschreibungen:**
|
|
70
67
|
|
|
71
|
-
- **intlayer**:
|
|
72
|
-
-
|
|
68
|
+
- **intlayer**: Kernbibliothek für Internationalisierungsmanagement, Content-Deklaration und Build-Prozesse
|
|
69
|
+
- **@intlayer/sync-json-plugin**: Plugin zum Exportieren von Intlayer-Content-Deklarationen in ein mit react-intl kompatibles JSON-Format
|
|
73
70
|
|
|
74
|
-
|
|
71
|
+
### Schritt 2: Implementieren Sie das Intlayer-Plugin zum Verpacken des JSON
|
|
75
72
|
|
|
76
|
-
|
|
73
|
+
Erstellen Sie eine Intlayer-Konfigurationsdatei, um Ihre unterstützten Sprachen zu definieren:
|
|
77
74
|
|
|
78
|
-
|
|
75
|
+
**Wenn Sie auch JSON-Wörterbücher für react-intl exportieren möchten**, fügen Sie das `syncJSON`-Plugin hinzu:
|
|
79
76
|
|
|
80
|
-
```typescript
|
|
77
|
+
```typescript fileName="intlayer.config.ts"
|
|
81
78
|
import { Locales, type IntlayerConfig } from "intlayer";
|
|
79
|
+
import { syncJSON } from "@intlayer/sync-json-plugin";
|
|
82
80
|
|
|
83
81
|
const config: IntlayerConfig = {
|
|
84
82
|
internationalization: {
|
|
85
|
-
// Fügen Sie so viele lokale Sprachen hinzu, wie Sie möchten
|
|
86
83
|
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
87
84
|
defaultLocale: Locales.ENGLISH,
|
|
88
85
|
},
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
// Das Verzeichnis, in das Intlayer Ihre Nachrichten-JSON-Dateien schreiben wird
|
|
94
|
-
reactIntlMessagesDir: "./react-intl/messages",
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
export default config;
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
> **Hinweis**: Für andere Dateierweiterungen (`.mjs`, `.cjs`, `.js`) siehe die [Intlayer-Dokumentation](https://intlayer.org/de/doc/concept/configuration) für Nutzungsdetails.
|
|
102
|
-
|
|
103
|
-
---
|
|
104
|
-
|
|
105
|
-
## Erstellen Sie Ihre Intlayer Inhaltsdeklarationen
|
|
106
|
-
|
|
107
|
-
Intlayer scannt Ihren Code (standardmäßig unter `./src`) nach Dateien, die `*.content.{ts,tsx,js,jsx,mjs,mjx,cjs,cjx,json}` entsprechen.
|
|
108
|
-
Hier ist ein **TypeScript** Beispiel:
|
|
109
|
-
|
|
110
|
-
```typescript title="src/components/MyComponent/index.content.ts"
|
|
111
|
-
import { t, type Dictionary } from "intlayer";
|
|
112
|
-
|
|
113
|
-
const content = {
|
|
114
|
-
// "key" wird der obere Schlüssel der Nachricht in Ihrer react-intl JSON-Datei
|
|
115
|
-
key: "my-component",
|
|
116
|
-
|
|
117
|
-
content: {
|
|
118
|
-
// Jeder Aufruf von t() erklärt ein übersetzbares Feld
|
|
119
|
-
helloWorld: t({
|
|
120
|
-
en: "Hello World",
|
|
121
|
-
es: "Hola Mundo",
|
|
122
|
-
fr: "Bonjour le monde",
|
|
123
|
-
}),
|
|
124
|
-
description: t({
|
|
125
|
-
en: "This is a description",
|
|
126
|
-
fr: "Ceci est une description",
|
|
127
|
-
es: "Esta es una descripción",
|
|
86
|
+
plugins: [
|
|
87
|
+
syncJSON({
|
|
88
|
+
source: ({ key, locale }) => `./intl/messages/${locale}/${key}.json`,
|
|
128
89
|
}),
|
|
129
|
-
|
|
130
|
-
} satisfies Dictionary;
|
|
131
|
-
|
|
132
|
-
export default content;
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
Wenn Sie JSON oder verschiedene JS-Varianten (`.cjs`, `.mjs`) bevorzugen, bleibt die Struktur weitgehend gleich – siehe [Intlayer-Dokumentation zur Inhaltsdeklaration](https://intlayer.org/de/doc/concept/content).
|
|
136
|
-
|
|
137
|
-
---
|
|
138
|
-
|
|
139
|
-
## Erstellen der react-intl Nachrichten
|
|
140
|
-
|
|
141
|
-
Um die tatsächlichen Nachrichten-JSON-Dateien für **react-intl** zu generieren, führen Sie aus:
|
|
142
|
-
|
|
143
|
-
```bash
|
|
144
|
-
# mit npm
|
|
145
|
-
npx intlayer dictionaries build
|
|
146
|
-
|
|
147
|
-
# mit yarn
|
|
148
|
-
yarn intlayer build
|
|
149
|
-
|
|
150
|
-
# mit pnpm
|
|
151
|
-
pnpm intlayer build
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
Dies scannt alle `*.content.*` Dateien, kompiliert diese und schreibt die Ergebnisse in das Verzeichnis, das in Ihrer **`intlayer.config.ts`** angegeben ist – in diesem Beispiel `./react-intl/messages`.
|
|
155
|
-
Eine typische Ausgabe könnte wie folgt aussehen:
|
|
156
|
-
|
|
157
|
-
```bash
|
|
158
|
-
.
|
|
159
|
-
└── react-intl
|
|
160
|
-
└── messages
|
|
161
|
-
├── en.json
|
|
162
|
-
├── fr.json
|
|
163
|
-
└── es.json
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
Jede Datei ist ein JSON-Objekt, dessen **oberste Schlüssel** den jeweiligen **`content.key`** aus Ihren Deklarationen entsprechen. Die **Unter-Schlüssel** (wie `helloWorld`) spiegeln die innerhalb dieses Inhaltselements erklärten Übersetzungen wider.
|
|
167
|
-
|
|
168
|
-
Zum Beispiel könnte die **en.json** so aussehen:
|
|
169
|
-
|
|
170
|
-
```json fileName="react-intl/messages/en/my-component.json"
|
|
171
|
-
{
|
|
172
|
-
"helloWorld": "Hello World",
|
|
173
|
-
"description": "This is a description"
|
|
174
|
-
}
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
---
|
|
178
|
-
|
|
179
|
-
## Initialisieren von react-intl in Ihrer React-App
|
|
180
|
-
|
|
181
|
-
### 1. Laden Sie die generierten Nachrichten
|
|
182
|
-
|
|
183
|
-
Wo Sie die Wurzelkomponente Ihrer App konfigurieren (z.B. `src/main.tsx` oder `src/index.tsx`), müssen Sie:
|
|
184
|
-
|
|
185
|
-
1. **Importieren** Sie die generierten Nachrichten-Dateien (entweder statisch oder dynamisch).
|
|
186
|
-
2. **Bereitstellen** Sie sie an `<IntlProvider>` von `react-intl`.
|
|
187
|
-
|
|
188
|
-
Ein einfacher Ansatz ist, sie **statisch** zu importieren:
|
|
189
|
-
|
|
190
|
-
```typescript title="src/index.tsx"
|
|
191
|
-
import React from "react";
|
|
192
|
-
import ReactDOM from "react-dom/client";
|
|
193
|
-
import { IntlProvider } from "react-intl";
|
|
194
|
-
import App from "./App";
|
|
195
|
-
|
|
196
|
-
// Importieren der JSON-Dateien aus der Build-Ausgabe.
|
|
197
|
-
// Alternativ können Sie sie dynamisch basierend auf der vom Benutzer gewählten Sprache importieren.
|
|
198
|
-
import en from "../react-intl/messages/en.json";
|
|
199
|
-
import fr from "../react-intl/messages/fr.json";
|
|
200
|
-
import es from "../react-intl/messages/es.json";
|
|
201
|
-
|
|
202
|
-
// Wenn Sie einen Mechanismus haben, um die Sprache des Benutzers zu erkennen, setzen Sie sie hier.
|
|
203
|
-
// Zur Vereinfachung wählen wir Englisch.
|
|
204
|
-
const locale = "en";
|
|
205
|
-
|
|
206
|
-
// Nachrichten in einem Objekt zusammenfassen (oder sie dynamisch auswählen)
|
|
207
|
-
const messagesRecord: Record<string, Record<string, any>> = {
|
|
208
|
-
en,
|
|
209
|
-
fr,
|
|
210
|
-
es,
|
|
90
|
+
],
|
|
211
91
|
};
|
|
212
92
|
|
|
213
|
-
|
|
214
|
-
<React.StrictMode>
|
|
215
|
-
<IntlProvider locale={locale} messages={messagesRecord[locale]}>
|
|
216
|
-
<App />
|
|
217
|
-
</IntlProvider>
|
|
218
|
-
</React.StrictMode>
|
|
219
|
-
);
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
> **Tipp**: Für reale Projekte könnten Sie:
|
|
223
|
-
>
|
|
224
|
-
> - Die JSON-Nachrichten zur Laufzeit dynamisch laden.
|
|
225
|
-
> - Umweltbasierte, browserbasierte oder benutzerkontobasierte Lokalisierungserkennung verwenden.
|
|
226
|
-
|
|
227
|
-
### 2. Verwenden von `<FormattedMessage>` oder `useIntl()`
|
|
228
|
-
|
|
229
|
-
Sobald Ihre Nachrichten in `<IntlProvider>` geladen sind, kann jede Kindkomponente react-intl verwenden, um auf lokalisierte Strings zuzugreifen. Es gibt zwei Hauptansätze:
|
|
230
|
-
|
|
231
|
-
- **`<FormattedMessage>`** Komponente
|
|
232
|
-
- **`useIntl()`** Hook
|
|
233
|
-
|
|
234
|
-
---
|
|
235
|
-
|
|
236
|
-
## Verwendung von Übersetzungen in React-Komponenten
|
|
237
|
-
|
|
238
|
-
### Ansatz A: `<FormattedMessage>`
|
|
239
|
-
|
|
240
|
-
Für eine schnelle Inline-Nutzung:
|
|
241
|
-
|
|
242
|
-
```tsx title="src/components/MyComponent/index.tsx"
|
|
243
|
-
import React from "react";
|
|
244
|
-
import { FormattedMessage } from "react-intl";
|
|
245
|
-
|
|
246
|
-
export default function MyComponent() {
|
|
247
|
-
return (
|
|
248
|
-
<div>
|
|
249
|
-
<h1>
|
|
250
|
-
{/* “my-component.helloWorld” verweist auf den Schlüssel aus en.json, fr.json usw. */}
|
|
251
|
-
<FormattedMessage id="my-component.helloWorld" />
|
|
252
|
-
</h1>
|
|
253
|
-
|
|
254
|
-
<p>
|
|
255
|
-
<FormattedMessage id="my-component.description" />
|
|
256
|
-
</p>
|
|
257
|
-
</div>
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
> Die **`id`**-Eigenschaft in `<FormattedMessage>` muss mit dem **obersten Schlüssel** (`my-component`) plus allen Unter-Schlüsseln (`helloWorld`) übereinstimmen.
|
|
263
|
-
|
|
264
|
-
### Ansatz B: `useIntl()`
|
|
265
|
-
|
|
266
|
-
Für dynamischere Nutzung:
|
|
267
|
-
|
|
268
|
-
```tsx title="src/components/MyComponent/index.tsx"
|
|
269
|
-
import React from "react";
|
|
270
|
-
import { useIntl } from "react-intl";
|
|
271
|
-
|
|
272
|
-
export default function MyComponent() {
|
|
273
|
-
const intl = useIntl();
|
|
274
|
-
|
|
275
|
-
return (
|
|
276
|
-
<div>
|
|
277
|
-
<h1>{intl.formatMessage({ id: "my-component.helloWorld" })}</h1>
|
|
278
|
-
<p>{intl.formatMessage({ id: "my-component.description" })}</p>
|
|
279
|
-
</div>
|
|
280
|
-
);
|
|
281
|
-
}
|
|
93
|
+
export default config;
|
|
282
94
|
```
|
|
283
95
|
|
|
284
|
-
|
|
96
|
+
Das `syncJSON`-Plugin umschließt das JSON automatisch. Es liest und schreibt die JSON-Dateien, ohne die Inhaltsarchitektur zu verändern.
|
|
285
97
|
|
|
286
|
-
|
|
98
|
+
Wenn Sie möchten, dass dieses JSON zusammen mit Intlayer-Content-Deklarationsdateien (`.content`-Dateien) koexistiert, geht Intlayer folgendermaßen vor:
|
|
287
99
|
|
|
288
|
-
|
|
100
|
+
1. Lädt sowohl JSON- als auch Content-Deklarationsdateien und transformiert sie in ein Intlayer-Wörterbuch.
|
|
289
101
|
|
|
290
|
-
|
|
291
|
-
2. Führen Sie `intlayer build` erneut aus, um die JSON-Dateien im Verzeichnis `./react-intl/messages` zu regenerieren.
|
|
292
|
-
3. React (und react-intl) werden die Updates beim nächsten Mal, wenn Sie Ihre Anwendung neu erstellen oder neu laden, erkennen.
|
|
102
|
+
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).
|
|
293
103
|
|
|
294
|
-
|
|
104
|
+
Wenn Änderungen über die CLI zur Übersetzung des JSON oder über das CMS vorgenommen werden, aktualisiert Intlayer die JSON-Datei mit den neuen Übersetzungen.
|
|
295
105
|
|
|
296
|
-
|
|
106
|
+
Für weitere Details zum `syncJSON`-Plugin siehe bitte die [syncJSON Plugin-Dokumentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/de/plugins/sync-json.md).
|
|
297
107
|
|
|
298
|
-
|
|
108
|
+
## Git-Konfiguration
|
|
299
109
|
|
|
300
|
-
|
|
110
|
+
Es wird empfohlen, automatisch generierte Intlayer-Dateien zu ignorieren:
|
|
301
111
|
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
// ...
|
|
306
|
-
},
|
|
307
|
-
"include": ["src", "types"],
|
|
308
|
-
}
|
|
112
|
+
```plaintext fileName=".gitignore"
|
|
113
|
+
# Dateien, die von Intlayer generiert werden, ignorieren
|
|
114
|
+
.intlayer
|
|
309
115
|
```
|
|
310
116
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
---
|
|
314
|
-
|
|
315
|
-
## Git-Konfiguration
|
|
117
|
+
Diese Dateien können während Ihres Build-Prozesses neu generiert werden und müssen nicht in die Versionskontrolle übernommen werden.
|
|
316
118
|
|
|
317
|
-
|
|
119
|
+
### VS Code Erweiterung
|
|
318
120
|
|
|
319
|
-
|
|
320
|
-
# Ignoriere intlayer-Build-Artefakte
|
|
321
|
-
.intlayer
|
|
322
|
-
react-intl
|
|
323
|
-
```
|
|
121
|
+
Für eine verbesserte Entwicklererfahrung installieren Sie die offizielle **Intlayer VS Code Erweiterung**:
|
|
324
122
|
|
|
325
|
-
|
|
123
|
+
[Installation aus dem VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
createdAt: 2024-12-24
|
|
3
|
-
updatedAt: 2025-
|
|
4
|
-
title:
|
|
5
|
-
description:
|
|
3
|
+
updatedAt: 2025-10-29
|
|
4
|
+
title: How to automate your i18next JSON translations using Intlayer
|
|
5
|
+
description: Automate your JSON translations with Intlayer and i18next for enhanced internationalization in JavaScript applications.
|
|
6
6
|
keywords:
|
|
7
7
|
- Intlayer
|
|
8
8
|
- i18next
|
|
@@ -14,149 +14,113 @@ keywords:
|
|
|
14
14
|
- Next.js
|
|
15
15
|
- JavaScript
|
|
16
16
|
- TypeScript
|
|
17
|
+
- Migration
|
|
18
|
+
- Integration
|
|
17
19
|
slugs:
|
|
18
20
|
- blog
|
|
19
21
|
- intlayer-with-i18next
|
|
22
|
+
history:
|
|
23
|
+
- version: 7.0.0
|
|
24
|
+
date: 2025-10-29
|
|
25
|
+
changes: Change to syncJSON plugin
|
|
20
26
|
---
|
|
21
27
|
|
|
22
|
-
#
|
|
28
|
+
# How to automate your i18next JSON translations using Intlayer
|
|
23
29
|
|
|
24
|
-
|
|
30
|
+
## What is Intlayer?
|
|
25
31
|
|
|
26
|
-
Intlayer is
|
|
32
|
+
**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 JavaScript applications.
|
|
27
33
|
|
|
28
|
-
|
|
34
|
+
See a concrete comparison with i18next 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.
|
|
29
35
|
|
|
30
|
-
|
|
36
|
+
## Why Combine Intlayer with i18next?
|
|
31
37
|
|
|
32
|
-
|
|
38
|
+
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 i18next for several reasons:
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
1. **Existing codebase**: You have an established i18next implementation and want to gradually migrate to Intlayer's improved developer experience.
|
|
41
|
+
2. **Legacy requirements**: Your project requires compatibility with existing i18next plugins or workflows.
|
|
42
|
+
3. **Team familiarity**: Your team is comfortable with i18next but wants better content management.
|
|
36
43
|
|
|
37
|
-
|
|
44
|
+
**For that, Intlayer can be implemented as an adapter for i18next to help automating your JSON translations in CLI or CI/CD pipelines, testing your translations, and more.**
|
|
38
45
|
|
|
39
|
-
|
|
46
|
+
This guide shows you how to leverage Intlayer's superior content declaration system while maintaining compatibility with i18next.
|
|
40
47
|
|
|
41
|
-
|
|
48
|
+
## Table of Contents
|
|
42
49
|
|
|
43
|
-
|
|
50
|
+
<TOC/>
|
|
44
51
|
|
|
45
|
-
|
|
52
|
+
## Step-by-Step Guide to Set Up Intlayer with i18next
|
|
46
53
|
|
|
47
|
-
|
|
54
|
+
### Step 1: Install Dependencies
|
|
48
55
|
|
|
49
|
-
|
|
56
|
+
Install the necessary packages:
|
|
50
57
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
```bash packageManager="npm"
|
|
59
|
+
npm install intlayer @intlayer/sync-json-plugin
|
|
60
|
+
```
|
|
54
61
|
|
|
55
|
-
|
|
62
|
+
```bash packageManager="pnpm"
|
|
63
|
+
pnpm add intlayer @intlayer/sync-json-plugin
|
|
64
|
+
```
|
|
56
65
|
|
|
57
|
-
|
|
66
|
+
```bash packageManager="yarn"
|
|
67
|
+
yarn add intlayer @intlayer/sync-json-plugin
|
|
68
|
+
```
|
|
58
69
|
|
|
59
|
-
|
|
70
|
+
**Package descriptions:**
|
|
60
71
|
|
|
61
|
-
|
|
72
|
+
- **intlayer**: Core library for internationalization management, content declaration, and building
|
|
73
|
+
- **@intlayer/sync-json-plugin**: Plugin to export Intlayer content declarations to i18next compatible JSON format
|
|
62
74
|
|
|
63
|
-
|
|
64
|
-
import { Locales, type IntlayerConfig } from "intlayer";
|
|
75
|
+
### Step 2: Implement the Intlayer plugin to wrap the JSON
|
|
65
76
|
|
|
66
|
-
|
|
67
|
-
content: {
|
|
68
|
-
// Indicate that Intlayer will export both Intlayer and i18next dictionaries
|
|
69
|
-
dictionaryOutput: ["intlayer", "i18next"],
|
|
70
|
-
// Relative path from the project root to the directory where i18n dictionaries will be exported
|
|
71
|
-
i18nextResourcesDir: "./i18next/dictionaries",
|
|
72
|
-
},
|
|
73
|
-
};
|
|
77
|
+
Create an Intlayer configuration file to define your supported locales:
|
|
74
78
|
|
|
75
|
-
export
|
|
76
|
-
```
|
|
79
|
+
**If you want to also export JSON dictionaries for i18next**, add the `syncJSON` plugin:
|
|
77
80
|
|
|
78
|
-
```
|
|
79
|
-
import { Locales } from "intlayer";
|
|
81
|
+
```typescript fileName="intlayer.config.ts"
|
|
82
|
+
import { Locales, type IntlayerConfig } from "intlayer";
|
|
83
|
+
import { syncJSON } from "@intlayer/sync-json-plugin";
|
|
80
84
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
dictionaryOutput: ["intlayer", "i18next"],
|
|
86
|
-
// Relative path from the project root to the directory where i18n dictionaries will be exported
|
|
87
|
-
i18nextResourcesDir: "./i18next/dictionaries",
|
|
85
|
+
const config: IntlayerConfig = {
|
|
86
|
+
internationalization: {
|
|
87
|
+
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
88
|
+
defaultLocale: Locales.ENGLISH,
|
|
88
89
|
},
|
|
90
|
+
plugins: [
|
|
91
|
+
syncJSON({
|
|
92
|
+
source: ({ key, locale }) => `./intl/messages/${locale}/${key}.json`,
|
|
93
|
+
}),
|
|
94
|
+
],
|
|
89
95
|
};
|
|
90
96
|
|
|
91
97
|
export default config;
|
|
92
98
|
```
|
|
93
99
|
|
|
94
|
-
|
|
95
|
-
const { Locales } = require("intlayer");
|
|
96
|
-
|
|
97
|
-
/** @type {import('intlayer').IntlayerConfig} */
|
|
98
|
-
const config = {
|
|
99
|
-
content: {
|
|
100
|
-
// Indicate that Intlayer will export both Intlayer and i18next dictionaries
|
|
101
|
-
dictionaryOutput: ["intlayer", "i18next"],
|
|
102
|
-
// Relative path from the project root to the directory where i18n dictionaries will be exported
|
|
103
|
-
i18nextResourcesDir: "./i18next/dictionaries",
|
|
104
|
-
},
|
|
105
|
-
};
|
|
100
|
+
The `syncJSON` plugin will automatically wrap the JSON. It will read and write the JSON files without changing the content architecture.
|
|
106
101
|
|
|
107
|
-
|
|
108
|
-
```
|
|
102
|
+
If you want to make coexist that JSON with intlayer content declaration files (`.content` files), Intlayer will proceed this way:
|
|
109
103
|
|
|
110
|
-
|
|
104
|
+
1. load both JSON and content declaration files and transform them into a intlayer dictionary.
|
|
105
|
+
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).
|
|
111
106
|
|
|
112
|
-
|
|
107
|
+
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.
|
|
113
108
|
|
|
114
|
-
To
|
|
109
|
+
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).
|
|
115
110
|
|
|
116
|
-
|
|
117
|
-
// i18n/client.ts
|
|
111
|
+
## Git Configuration
|
|
118
112
|
|
|
119
|
-
|
|
120
|
-
import resourcesToBackend from "i18next-resources-to-backend";
|
|
113
|
+
It's recommended to ignore auto-generated Intlayer files:
|
|
121
114
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
resourcesToBackend(
|
|
126
|
-
(language: string, namespace: string) =>
|
|
127
|
-
import(`../i18next/dictionaries/${language}/${namespace}.json`)
|
|
128
|
-
)
|
|
129
|
-
);
|
|
115
|
+
```plaintext fileName=".gitignore"
|
|
116
|
+
# Ignore files generated by Intlayer
|
|
117
|
+
.intlayer
|
|
130
118
|
```
|
|
131
119
|
|
|
132
|
-
|
|
133
|
-
// i18n/client.mjs
|
|
134
|
-
|
|
135
|
-
import i18next from "i18next";
|
|
136
|
-
import resourcesToBackend from "i18next-resources-to-backend";
|
|
120
|
+
These files can be regenerated during your build process and don't need to be committed to version control.
|
|
137
121
|
|
|
138
|
-
|
|
139
|
-
// Your i18next configuration
|
|
140
|
-
.use(
|
|
141
|
-
resourcesToBackend(
|
|
142
|
-
(language, namespace) =>
|
|
143
|
-
import(`../i18next/dictionaries/${language}/${namespace}.json`)
|
|
144
|
-
)
|
|
145
|
-
);
|
|
146
|
-
```
|
|
122
|
+
### VS Code Extension
|
|
147
123
|
|
|
148
|
-
|
|
149
|
-
// i18n/client.cjs
|
|
124
|
+
For improved developer experience, install the official **Intlayer VS Code Extension**:
|
|
150
125
|
|
|
151
|
-
|
|
152
|
-
const resourcesToBackend = require("i18next-resources-to-backend");
|
|
153
|
-
|
|
154
|
-
i18next
|
|
155
|
-
// Your i18next configuration
|
|
156
|
-
.use(
|
|
157
|
-
resourcesToBackend(
|
|
158
|
-
(language, namespace) =>
|
|
159
|
-
import(`../i18next/dictionaries/${language}/${namespace}.json`)
|
|
160
|
-
)
|
|
161
|
-
);
|
|
162
|
-
```
|
|
126
|
+
[Install from the VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|