@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.
- 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,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)
|