@intlayer/docs 7.3.14 → 7.4.0
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 +3 -0
- package/blog/ar/intlayer_with_next-i18next.md +3 -0
- package/blog/ar/intlayer_with_next-intl.md +3 -0
- package/blog/ar/intlayer_with_react-i18next.md +3 -0
- package/blog/ar/intlayer_with_react-intl.md +3 -0
- package/blog/ar/intlayer_with_vue-i18n.md +3 -0
- package/blog/de/intlayer_with_i18next.md +3 -0
- package/blog/de/intlayer_with_next-i18next.md +3 -0
- package/blog/de/intlayer_with_next-intl.md +3 -0
- package/blog/de/intlayer_with_react-i18next.md +3 -0
- package/blog/de/intlayer_with_react-intl.md +3 -0
- package/blog/de/intlayer_with_vue-i18n.md +3 -0
- package/blog/en/intlayer_with_i18next.md +7 -0
- package/blog/en/intlayer_with_next-i18next.md +3 -0
- package/blog/en/intlayer_with_next-intl.md +7 -0
- package/blog/en/intlayer_with_react-i18next.md +3 -0
- package/blog/en/intlayer_with_react-intl.md +3 -0
- package/blog/en/intlayer_with_vue-i18n.md +3 -0
- package/blog/en-GB/intlayer_with_i18next.md +3 -0
- package/blog/en-GB/intlayer_with_next-i18next.md +3 -0
- package/blog/en-GB/intlayer_with_next-intl.md +3 -0
- package/blog/en-GB/intlayer_with_react-i18next.md +3 -0
- package/blog/en-GB/intlayer_with_react-intl.md +3 -0
- package/blog/en-GB/intlayer_with_vue-i18n.md +3 -0
- package/blog/es/intlayer_with_i18next.md +3 -0
- package/blog/es/intlayer_with_next-i18next.md +3 -0
- package/blog/es/intlayer_with_next-intl.md +3 -0
- package/blog/es/intlayer_with_react-i18next.md +3 -0
- package/blog/es/intlayer_with_react-intl.md +3 -0
- package/blog/es/intlayer_with_vue-i18n.md +3 -0
- package/blog/fr/intlayer_with_i18next.md +3 -0
- package/blog/fr/intlayer_with_next-i18next.md +3 -0
- package/blog/fr/intlayer_with_next-intl.md +3 -0
- package/blog/fr/intlayer_with_react-i18next.md +3 -0
- package/blog/fr/intlayer_with_react-intl.md +3 -0
- package/blog/fr/intlayer_with_vue-i18n.md +3 -0
- package/blog/hi/intlayer_with_i18next.md +3 -0
- package/blog/hi/intlayer_with_next-i18next.md +3 -0
- package/blog/hi/intlayer_with_next-intl.md +3 -0
- package/blog/hi/intlayer_with_react-i18next.md +3 -0
- package/blog/hi/intlayer_with_react-intl.md +3 -0
- package/blog/hi/intlayer_with_vue-i18n.md +3 -0
- package/blog/id/intlayer_with_i18next.md +3 -0
- package/blog/id/intlayer_with_next-i18next.md +3 -0
- package/blog/id/intlayer_with_next-intl.md +3 -0
- package/blog/id/intlayer_with_react-i18next.md +3 -0
- package/blog/id/intlayer_with_react-intl.md +3 -0
- package/blog/id/intlayer_with_vue-i18n.md +3 -0
- package/blog/it/intlayer_with_i18next.md +3 -0
- package/blog/it/intlayer_with_next-i18next.md +3 -0
- package/blog/it/intlayer_with_next-intl.md +3 -0
- package/blog/it/intlayer_with_react-i18next.md +3 -0
- package/blog/it/intlayer_with_react-intl.md +3 -0
- package/blog/it/intlayer_with_vue-i18n.md +3 -0
- package/blog/ja/intlayer_with_i18next.md +3 -0
- package/blog/ja/intlayer_with_next-i18next.md +3 -0
- package/blog/ja/intlayer_with_next-intl.md +3 -0
- package/blog/ja/intlayer_with_react-i18next.md +3 -0
- package/blog/ja/intlayer_with_react-intl.md +3 -0
- package/blog/ja/intlayer_with_vue-i18n.md +3 -0
- package/blog/ko/intlayer_with_i18next.md +3 -0
- package/blog/ko/intlayer_with_next-i18next.md +3 -0
- package/blog/ko/intlayer_with_next-intl.md +3 -0
- package/blog/ko/intlayer_with_react-i18next.md +3 -0
- package/blog/ko/intlayer_with_react-intl.md +3 -0
- package/blog/ko/intlayer_with_vue-i18n.md +3 -0
- package/blog/pl/intlayer_with_i18next.md +3 -0
- package/blog/pl/intlayer_with_next-i18next.md +3 -0
- package/blog/pl/intlayer_with_next-intl.md +3 -0
- package/blog/pl/intlayer_with_react-i18next.md +3 -0
- package/blog/pl/intlayer_with_react-intl.md +3 -0
- package/blog/pl/intlayer_with_vue-i18n.md +3 -0
- package/blog/pt/intlayer_with_i18next.md +3 -0
- package/blog/pt/intlayer_with_next-i18next.md +3 -0
- package/blog/pt/intlayer_with_next-intl.md +3 -0
- package/blog/pt/intlayer_with_react-i18next.md +3 -0
- package/blog/pt/intlayer_with_react-intl.md +3 -0
- package/blog/pt/intlayer_with_vue-i18n.md +3 -0
- package/blog/ru/intlayer_with_i18next.md +3 -0
- package/blog/ru/intlayer_with_next-i18next.md +3 -0
- package/blog/ru/intlayer_with_next-intl.md +3 -0
- package/blog/ru/intlayer_with_react-i18next.md +3 -0
- package/blog/ru/intlayer_with_react-intl.md +3 -0
- package/blog/ru/intlayer_with_vue-i18n.md +3 -0
- package/blog/tr/intlayer_with_i18next.md +3 -0
- package/blog/tr/intlayer_with_next-i18next.md +3 -0
- package/blog/tr/intlayer_with_next-intl.md +3 -0
- package/blog/tr/intlayer_with_react-i18next.md +3 -0
- package/blog/tr/intlayer_with_vue-i18n.md +3 -0
- package/blog/vi/intlayer_with_i18next.md +3 -0
- package/blog/vi/intlayer_with_next-i18next.md +3 -0
- package/blog/vi/intlayer_with_next-intl.md +3 -0
- package/blog/vi/intlayer_with_react-i18next.md +3 -0
- package/blog/vi/intlayer_with_react-intl.md +3 -0
- package/blog/vi/intlayer_with_vue-i18n.md +3 -0
- package/blog/zh/intlayer_with_i18next.md +3 -0
- package/blog/zh/intlayer_with_next-i18next.md +3 -0
- package/blog/zh/intlayer_with_next-intl.md +3 -0
- package/blog/zh/intlayer_with_react-i18next.md +3 -0
- package/blog/zh/intlayer_with_react-intl.md +3 -0
- package/blog/zh/intlayer_with_vue-i18n.md +3 -0
- package/docs/ar/intlayer_with_lynx+react.md +1 -1
- package/docs/ar/intlayer_with_tanstack.md +132 -2
- package/docs/ar/intlayer_with_vite+react.md +99 -331
- package/docs/ar/plugins/sync-json.md +3 -0
- package/docs/de/intlayer_with_lynx+react.md +1 -1
- package/docs/de/intlayer_with_tanstack.md +132 -2
- package/docs/de/intlayer_with_vite+react.md +116 -380
- package/docs/de/plugins/sync-json.md +3 -0
- package/docs/en/intlayer_with_tanstack.md +131 -1
- package/docs/en/intlayer_with_vite+react.md +6 -10
- package/docs/en/plugins/sync-json.md +3 -0
- package/docs/en-GB/intlayer_with_tanstack.md +131 -1
- package/docs/en-GB/intlayer_with_vite+react.md +62 -74
- package/docs/en-GB/plugins/sync-json.md +3 -0
- package/docs/es/intlayer_with_tanstack.md +132 -2
- package/docs/es/intlayer_with_vite+react.md +101 -333
- package/docs/es/plugins/sync-json.md +3 -0
- package/docs/fr/intlayer_with_tanstack.md +132 -2
- package/docs/fr/intlayer_with_vite+react.md +101 -357
- package/docs/fr/plugins/sync-json.md +3 -0
- package/docs/hi/intlayer_with_tanstack.md +132 -2
- package/docs/hi/intlayer_with_vite+react.md +120 -333
- package/docs/hi/plugins/sync-json.md +3 -0
- package/docs/id/intlayer_with_tanstack.md +132 -2
- package/docs/id/intlayer_with_vite+react.md +7 -13
- package/docs/id/plugins/sync-json.md +3 -0
- package/docs/it/intlayer_with_lynx+react.md +1 -1
- package/docs/it/intlayer_with_tanstack.md +132 -2
- package/docs/it/intlayer_with_vite+react.md +121 -393
- package/docs/it/plugins/sync-json.md +3 -0
- package/docs/ja/intlayer_with_tanstack.md +132 -2
- package/docs/ja/intlayer_with_vite+react.md +106 -378
- package/docs/ja/plugins/sync-json.md +3 -0
- package/docs/ko/intlayer_with_lynx+react.md +1 -1
- package/docs/ko/intlayer_with_tanstack.md +132 -2
- package/docs/ko/intlayer_with_vite+react.md +90 -322
- package/docs/ko/plugins/sync-json.md +3 -0
- package/docs/pl/intlayer_with_tanstack.md +132 -2
- package/docs/pl/intlayer_with_vite+react.md +25 -21
- package/docs/pl/plugins/sync-json.md +3 -0
- package/docs/pt/intlayer_with_tanstack.md +132 -2
- package/docs/pt/intlayer_with_vite+react.md +96 -328
- package/docs/pt/plugins/sync-json.md +3 -0
- package/docs/ru/intlayer_with_lynx+react.md +1 -1
- package/docs/ru/intlayer_with_tanstack.md +132 -2
- package/docs/ru/intlayer_with_vite+react.md +109 -362
- package/docs/ru/plugins/sync-json.md +3 -0
- package/docs/tr/intlayer_with_tanstack.md +132 -2
- package/docs/tr/intlayer_with_vite+react.md +132 -366
- package/docs/tr/plugins/sync-json.md +3 -0
- package/docs/vi/intlayer_with_tanstack.md +132 -2
- package/docs/vi/intlayer_with_vite+react.md +16 -19
- package/docs/vi/plugins/sync-json.md +3 -0
- package/docs/zh/intlayer_with_tanstack.md +133 -3
- package/docs/zh/intlayer_with_vite+react.md +91 -374
- package/docs/zh/plugins/sync-json.md +3 -0
- package/frequent_questions/ar/customized_locale_list.md +1 -1
- package/frequent_questions/de/customized_locale_list.md +1 -1
- package/frequent_questions/en/customized_locale_list.md +1 -1
- package/frequent_questions/en-GB/customized_locale_list.md +1 -1
- package/frequent_questions/es/customized_locale_list.md +1 -1
- package/frequent_questions/fr/customized_locale_list.md +1 -1
- package/frequent_questions/hi/customized_locale_list.md +1 -1
- package/frequent_questions/id/customized_locale_list.md +1 -1
- package/frequent_questions/it/customized_locale_list.md +1 -1
- package/frequent_questions/ja/customized_locale_list.md +1 -1
- package/frequent_questions/ko/customized_locale_list.md +1 -1
- package/frequent_questions/pl/customized_locale_list.md +1 -1
- package/frequent_questions/pt/customized_locale_list.md +1 -1
- package/frequent_questions/ru/customized_locale_list.md +1 -1
- package/frequent_questions/tr/customized_locale_list.md +1 -1
- package/frequent_questions/vi/customized_locale_list.md +1 -1
- package/frequent_questions/zh/customized_locale_list.md +1 -1
- package/package.json +6 -6
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
createdAt: 2024-03-07
|
|
3
|
-
updatedAt:
|
|
4
|
-
title: Wie Sie Ihre Vite
|
|
3
|
+
updatedAt: 2025-12-10
|
|
4
|
+
title: Wie Sie Ihre Vite- und React-Anwendung übersetzen – i18n-Leitfaden 2025
|
|
5
5
|
description: Erfahren Sie, wie Sie Internationalisierung (i18n) zu Ihrer Vite- und React-Anwendung mit Intlayer hinzufügen. Folgen Sie dieser Anleitung, um Ihre App mehrsprachig zu machen.
|
|
6
6
|
keywords:
|
|
7
7
|
- Internationalisierung
|
|
@@ -16,26 +16,22 @@ slugs:
|
|
|
16
16
|
- environment
|
|
17
17
|
- vite-and-react
|
|
18
18
|
applicationTemplate: https://github.com/aymericzip/intlayer-vite-react-template
|
|
19
|
-
youtubeVideo: https://www.youtube.com/watch?v=dS9L7uJeak4
|
|
19
|
+
youtubeVideo: https://www.youtube.com/watch?v=dS9L7uJeak4
|
|
20
20
|
history:
|
|
21
21
|
- version: 5.5.10
|
|
22
22
|
date: 2025-06-29
|
|
23
23
|
changes: Historie initialisiert
|
|
24
24
|
---
|
|
25
25
|
|
|
26
|
-
#
|
|
26
|
+
# Übersetzen Sie Ihre Vite- und React-Website mit Intlayer | Internationalisierung (i18n)
|
|
27
27
|
|
|
28
28
|
## Inhaltsverzeichnis
|
|
29
29
|
|
|
30
30
|
<TOC/>
|
|
31
31
|
|
|
32
|
-
<iframe title="The best i18n solution for Vite and React? Discover Intlayer" class="m-auto aspect-[16/9] w-full overflow-hidden rounded-lg border-0" allow="autoplay; gyroscope;" loading="lazy" width="1080" height="auto" src="https://www.youtube.com/embed/dS9L7uJeak4?si=VaKmrYMmXjo3xpk2"/>
|
|
33
|
-
|
|
34
|
-
Siehe [Application Template](https://github.com/aymericzip/intlayer-vite-react-template) auf GitHub.
|
|
35
|
-
|
|
36
32
|
## Was ist Intlayer?
|
|
37
33
|
|
|
38
|
-
**Intlayer** ist eine innovative, Open-Source
|
|
34
|
+
**Intlayer** ist eine innovative, Open-Source-Internationalisierungsbibliothek (i18n), die entwickelt wurde, um die mehrsprachige Unterstützung in modernen Webanwendungen zu vereinfachen.
|
|
39
35
|
|
|
40
36
|
Mit Intlayer können Sie:
|
|
41
37
|
|
|
@@ -48,6 +44,27 @@ Mit Intlayer können Sie:
|
|
|
48
44
|
|
|
49
45
|
## Schritt-für-Schritt-Anleitung zur Einrichtung von Intlayer in einer Vite- und React-Anwendung
|
|
50
46
|
|
|
47
|
+
<Tab defaultTab="video">
|
|
48
|
+
<TabItem label="Video" value="video">
|
|
49
|
+
|
|
50
|
+
<iframe title="The best i18n solution for Vite and React? Discover Intlayer" class="m-auto aspect-[16/9] w-full overflow-hidden rounded-lg border-0" allow="autoplay; gyroscope;" loading="lazy" width="1080" height="auto" src="https://www.youtube.com/embed/dS9L7uJeak4?si=VaKmrYMmXjo3xpk2"/>
|
|
51
|
+
|
|
52
|
+
</TabItem>
|
|
53
|
+
<TabItem label="Code" value="code">
|
|
54
|
+
|
|
55
|
+
<iframe
|
|
56
|
+
src="https://stackblitz.com/github/aymericzip/intlayer-vite-react-template?embed=1&ctl=1&file=intlayer.config.ts"
|
|
57
|
+
className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
|
|
58
|
+
title="Demo CodeSandbox - How to Internationalize your application using Intlayer"
|
|
59
|
+
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
|
|
60
|
+
loading="lazy"
|
|
61
|
+
/>
|
|
62
|
+
|
|
63
|
+
</TabItem>
|
|
64
|
+
</Tab>
|
|
65
|
+
|
|
66
|
+
Siehe [Application Template](https://github.com/aymericzip/intlayer-vite-react-template) auf GitHub.
|
|
67
|
+
|
|
51
68
|
### Schritt 1: Abhängigkeiten installieren
|
|
52
69
|
|
|
53
70
|
Installieren Sie die notwendigen Pakete mit npm:
|
|
@@ -69,7 +86,7 @@ yarn add vite-intlayer --save-dev
|
|
|
69
86
|
|
|
70
87
|
- **intlayer**
|
|
71
88
|
|
|
72
|
-
|
|
89
|
+
Das Kernpaket, das Internationalisierungswerkzeuge für Konfigurationsmanagement, Übersetzung, [Inhaltserklärung](https://github.com/aymericzip/intlayer/blob/main/docs/docs/de/dictionary/content_file.md), Transpilierung und [CLI-Befehle](https://github.com/aymericzip/intlayer/blob/main/docs/docs/de/cli/index.md) bereitstellt.
|
|
73
90
|
|
|
74
91
|
- **react-intlayer**
|
|
75
92
|
Das Paket, das Intlayer in React-Anwendungen integriert. Es stellt Kontext-Provider und Hooks für die Internationalisierung in React bereit.
|
|
@@ -141,7 +158,7 @@ module.exports = config;
|
|
|
141
158
|
|
|
142
159
|
### Schritt 3: Integrieren Sie Intlayer in Ihre Vite-Konfiguration
|
|
143
160
|
|
|
144
|
-
Fügen Sie das
|
|
161
|
+
Fügen Sie das intlayer-Plugin in Ihre Konfiguration ein.
|
|
145
162
|
|
|
146
163
|
```typescript fileName="vite.config.ts" codeFormat="typescript"
|
|
147
164
|
import { defineConfig } from "vite";
|
|
@@ -193,11 +210,13 @@ const appContent = {
|
|
|
193
210
|
en: "Vite logo",
|
|
194
211
|
fr: "Logo Vite",
|
|
195
212
|
es: "Logo Vite",
|
|
213
|
+
de: "Vite-Logo",
|
|
196
214
|
}),
|
|
197
215
|
reactLogo: t({
|
|
198
216
|
en: "React logo",
|
|
199
217
|
fr: "Logo React",
|
|
200
218
|
es: "Logo React",
|
|
219
|
+
de: "React-Logo",
|
|
201
220
|
}),
|
|
202
221
|
|
|
203
222
|
title: "Vite + React",
|
|
@@ -206,13 +225,13 @@ const appContent = {
|
|
|
206
225
|
en: "count is ",
|
|
207
226
|
fr: "le compte est ",
|
|
208
227
|
es: "el recuento es ",
|
|
228
|
+
de: "Der Zähler ist ",
|
|
209
229
|
}),
|
|
210
230
|
|
|
211
231
|
edit: t<ReactNode>({
|
|
212
232
|
en: (
|
|
213
233
|
<>
|
|
214
|
-
|
|
215
|
-
testen
|
|
234
|
+
Edit <code>src/App.tsx</code> and save to test HMR
|
|
216
235
|
</>
|
|
217
236
|
),
|
|
218
237
|
fr: (
|
|
@@ -225,12 +244,19 @@ const appContent = {
|
|
|
225
244
|
Edita <code>src/App.tsx</code> y guarda para probar HMR
|
|
226
245
|
</>
|
|
227
246
|
),
|
|
247
|
+
de: (
|
|
248
|
+
<>
|
|
249
|
+
Bearbeiten Sie <code>src/App.tsx</code> und speichern Sie, um HMR zu
|
|
250
|
+
testen
|
|
251
|
+
</>
|
|
252
|
+
),
|
|
228
253
|
}),
|
|
229
254
|
|
|
230
255
|
readTheDocs: t({
|
|
231
|
-
en: "
|
|
256
|
+
en: "Click on the Vite and React logos to learn more",
|
|
232
257
|
fr: "Cliquez sur les logos Vite et React pour en savoir plus",
|
|
233
258
|
es: "Haga clic en los logotipos de Vite y React para obtener más información",
|
|
259
|
+
de: "Klicken Sie auf die Vite- und React-Logos, um mehr zu erfahren",
|
|
234
260
|
}),
|
|
235
261
|
},
|
|
236
262
|
} satisfies Dictionary;
|
|
@@ -287,7 +313,7 @@ const appContent = {
|
|
|
287
313
|
},
|
|
288
314
|
|
|
289
315
|
readTheDocs: t({
|
|
290
|
-
en: "
|
|
316
|
+
en: "Click on the Vite and React logos to learn more",
|
|
291
317
|
fr: "Cliquez sur les logos Vite et React pour en savoir plus",
|
|
292
318
|
es: "Haga clic en los logotipos de Vite y React para obtener más información",
|
|
293
319
|
}),
|
|
@@ -340,8 +366,7 @@ const appContent = {
|
|
|
340
366
|
),
|
|
341
367
|
es: (
|
|
342
368
|
<>
|
|
343
|
-
|
|
344
|
-
testen
|
|
369
|
+
Edita <code>src/App.tsx</code> y guarda para probar HMR
|
|
345
370
|
</>
|
|
346
371
|
),
|
|
347
372
|
},
|
|
@@ -418,9 +443,9 @@ module.exports = appContent;
|
|
|
418
443
|
}
|
|
419
444
|
```
|
|
420
445
|
|
|
421
|
-
|
|
446
|
+
Ihre Inhaltsdeklarationen können überall in Ihrer Anwendung definiert werden, sobald sie in das `contentDir`-Verzeichnis (standardmäßig `./src`) aufgenommen werden. Und die Dateiendung der Inhaltsdeklaration muss übereinstimmen (standardmäßig `.content.{json,ts,tsx,js,jsx,mjs,mjx,cjs,cjx}`).
|
|
422
447
|
|
|
423
|
-
> Für weitere Details siehe die [Dokumentation zur Inhaltsdeklaration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/de/dictionary/
|
|
448
|
+
> Für weitere Details siehe die [Dokumentation zur Inhaltsdeklaration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/de/dictionary/content_file.md).
|
|
424
449
|
|
|
425
450
|
> Wenn Ihre Inhaltsdatei TSX-Code enthält, sollten Sie in Ihrer Inhaltsdatei `import React from "react";` importieren.
|
|
426
451
|
|
|
@@ -569,19 +594,13 @@ const App = () => (
|
|
|
569
594
|
module.exports = App;
|
|
570
595
|
```
|
|
571
596
|
|
|
572
|
-
> Wenn Sie Ihren Inhalt in einem `string`-Attribut verwenden möchten, wie z.B. `alt`, `title`, `href`, `aria-label` usw., müssen Sie den Wert der Funktion aufrufen,
|
|
597
|
+
> Wenn Sie Ihren Inhalt in einem `string`-Attribut verwenden möchten, wie z. B. `alt`, `title`, `href`, `aria-label` usw., müssen Sie den Wert der Funktion aufrufen, zum Beispiel:
|
|
573
598
|
|
|
574
599
|
> ```jsx
|
|
575
600
|
> <img src={content.image.src.value} alt={content.image.value} />
|
|
576
601
|
> ```
|
|
577
602
|
|
|
578
|
-
>
|
|
579
|
-
|
|
580
|
-
> ```jsx
|
|
581
|
-
> <img src={content.image.src.value} alt={content.image.value} />
|
|
582
|
-
> ```
|
|
583
|
-
|
|
584
|
-
> Um mehr über den `useIntlayer` Hook zu erfahren, lesen Sie die [Dokumentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/de/packages/react-intlayer/useIntlayer.md).
|
|
603
|
+
> Um mehr über den `useIntlayer` Hook zu erfahren, lesen Sie die [Dokumentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/react-intlayer/useIntlayer.md).
|
|
585
604
|
|
|
586
605
|
### (Optional) Schritt 6: Ändern Sie die Sprache Ihres Inhalts
|
|
587
606
|
|
|
@@ -633,7 +652,7 @@ const LocaleSwitcher = () => {
|
|
|
633
652
|
};
|
|
634
653
|
```
|
|
635
654
|
|
|
636
|
-
> Um mehr über den `useLocale` Hook zu erfahren, lesen Sie die [Dokumentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/
|
|
655
|
+
> Um mehr über den `useLocale` Hook zu erfahren, lesen Sie die [Dokumentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/react-intlayer/useLocale.md).
|
|
637
656
|
|
|
638
657
|
### (Optional) Schritt 7: Lokalisierte Routen zu Ihrer Anwendung hinzufügen
|
|
639
658
|
|
|
@@ -651,82 +670,10 @@ Beispiel:
|
|
|
651
670
|
Um lokalisierte Routen in Ihre Anwendung hinzuzufügen, können Sie eine `LocaleRouter`-Komponente erstellen, die die Routen Ihrer Anwendung umschließt und die sprachabhängige Navigation verwaltet. Hier ist ein Beispiel unter Verwendung von [React Router](https://reactrouter.com/home):
|
|
652
671
|
|
|
653
672
|
```tsx fileName="src/components/LocaleRouter.tsx" codeFormat="typescript"
|
|
654
|
-
|
|
655
|
-
import { type Locales, configuration, getPathWithoutLocale } from "intlayer"; // Dienstprogramme und Typen von 'intlayer'
|
|
673
|
+
import { localeMap } from "intlayer"; // Dienstprogramme und Typen von 'intlayer'
|
|
656
674
|
import type { FC, PropsWithChildren } from "react"; // React-Typen für funktionale Komponenten und Props
|
|
657
675
|
import { IntlayerProvider } from "react-intlayer"; // Provider für Internationalisierungskontext
|
|
658
|
-
import {
|
|
659
|
-
BrowserRouter,
|
|
660
|
-
Routes,
|
|
661
|
-
Route,
|
|
662
|
-
Navigate,
|
|
663
|
-
useLocation,
|
|
664
|
-
} from "react-router-dom"; // Router-Komponenten zur Verwaltung der Navigation
|
|
665
|
-
|
|
666
|
-
// Destrukturierung der Konfiguration von Intlayer
|
|
667
|
-
const { internationalization, middleware } = configuration;
|
|
668
|
-
const { locales, defaultLocale } = internationalization;
|
|
669
|
-
|
|
670
|
-
/**
|
|
671
|
-
* Eine Komponente, die die Lokalisierung verwaltet und Kinder mit dem entsprechenden Locale-Kontext umschließt.
|
|
672
|
-
* Sie verwaltet die URL-basierte Lokalerkennung und -validierung.
|
|
673
|
-
*/
|
|
674
|
-
const AppLocalized: FC<PropsWithChildren<{ locale: Locales }>> = ({
|
|
675
|
-
children,
|
|
676
|
-
locale,
|
|
677
|
-
}) => {
|
|
678
|
-
const { pathname, search } = useLocation(); // Aktuellen URL-Pfad abrufen
|
|
679
|
-
|
|
680
|
-
// Bestimmen der aktuellen Locale, Standardwert verwenden, falls nicht angegeben
|
|
681
|
-
const currentLocale = locale ?? defaultLocale;
|
|
682
|
-
|
|
683
|
-
// Entfernen des Locale-Präfixes aus dem Pfad, um einen Basis-Pfad zu erstellen
|
|
684
|
-
const pathWithoutLocale = getPathWithoutLocale(
|
|
685
|
-
pathname // Aktueller URL-Pfad
|
|
686
|
-
);
|
|
687
|
-
|
|
688
|
-
/**
|
|
689
|
-
* Wenn middleware.prefixDefault true ist, sollte die Standard-Locale immer vorangestellt werden.
|
|
690
|
-
*/
|
|
691
|
-
if (middleware.prefixDefault) {
|
|
692
|
-
// Locale validieren
|
|
693
|
-
if (!locale || !locales.includes(locale)) {
|
|
694
|
-
// Weiterleitung zur Standard-Locale mit aktualisiertem Pfad
|
|
695
|
-
return (
|
|
696
|
-
<Navigate
|
|
697
|
-
to={`/${defaultLocale}/${pathWithoutLocale}${search}`}
|
|
698
|
-
replace // Ersetzt den aktuellen Eintrag im Verlauf durch den neuen
|
|
699
|
-
/>
|
|
700
|
-
);
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
// Umschließt die Kinder mit dem IntlayerProvider und setzt die aktuelle Locale
|
|
704
|
-
return (
|
|
705
|
-
<IntlayerProvider locale={currentLocale}>{children}</IntlayerProvider>
|
|
706
|
-
);
|
|
707
|
-
} else {
|
|
708
|
-
/**
|
|
709
|
-
* Wenn middleware.prefixDefault false ist, wird die Standardsprache nicht mit einem Präfix versehen.
|
|
710
|
-
* Stellen Sie sicher, dass die aktuelle Locale gültig ist und nicht die Standardsprache ist.
|
|
711
|
-
*/
|
|
712
|
-
if (
|
|
713
|
-
currentLocale.toString() !== defaultLocale.toString() &&
|
|
714
|
-
!locales
|
|
715
|
-
.filter(
|
|
716
|
-
(locale) => locale.toString() !== defaultLocale.toString() // Schließt die Standardsprache aus
|
|
717
|
-
)
|
|
718
|
-
.includes(currentLocale) // Überprüfen, ob die aktuelle Locale in der Liste der gültigen Locales enthalten ist
|
|
719
|
-
) {
|
|
720
|
-
// Weiterleitung zum Pfad ohne Locale-Präfix
|
|
721
|
-
return <Navigate to={`${pathWithoutLocale}${search}`} replace />;
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
// Kinder mit dem IntlayerProvider umschließen und die aktuelle Locale setzen
|
|
725
|
-
return (
|
|
726
|
-
<IntlayerProvider locale={currentLocale}>{children}</IntlayerProvider>
|
|
727
|
-
);
|
|
728
|
-
}
|
|
729
|
-
};
|
|
676
|
+
import { BrowserRouter, Route, Routes } from "react-router-dom"; // Router-Komponenten zur Verwaltung der Navigation
|
|
730
677
|
|
|
731
678
|
/**
|
|
732
679
|
* Eine Router-Komponente, die locale-spezifische Routen einrichtet.
|
|
@@ -735,257 +682,81 @@ const AppLocalized: FC<PropsWithChildren<{ locale: Locales }>> = ({
|
|
|
735
682
|
export const LocaleRouter: FC<PropsWithChildren> = ({ children }) => (
|
|
736
683
|
<BrowserRouter>
|
|
737
684
|
<Routes>
|
|
738
|
-
{
|
|
739
|
-
|
|
740
|
-
(
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
/>
|
|
749
|
-
))}
|
|
750
|
-
|
|
751
|
-
{
|
|
752
|
-
// Wenn das Präfix für die Standard-Locale deaktiviert ist, werden die Kinder direkt im Stammverzeichnis gerendert
|
|
753
|
-
!middleware.prefixDefault && (
|
|
754
|
-
<Route
|
|
755
|
-
path="*"
|
|
756
|
-
element={
|
|
757
|
-
<AppLocalized locale={defaultLocale}>{children}</AppLocalized>
|
|
758
|
-
} // Umschließt die Kinder mit der Locale-Verwaltung
|
|
759
|
-
/>
|
|
760
|
-
)
|
|
761
|
-
}
|
|
685
|
+
{localeMap(({ locale, urlPrefix }) => (
|
|
686
|
+
<Route
|
|
687
|
+
// Routenmuster zur Erfassung der Locale (z. B. /en/, /fr/) und zum Abgleich aller nachfolgenden Pfade
|
|
688
|
+
path={`${urlPrefix}/*`}
|
|
689
|
+
key={locale}
|
|
690
|
+
element={
|
|
691
|
+
<IntlayerProvider locale={locale}>{children}</IntlayerProvider>
|
|
692
|
+
} // Umschließt die Kinder mit der Locale-Verwaltung
|
|
693
|
+
/>
|
|
694
|
+
))}
|
|
762
695
|
</Routes>
|
|
763
696
|
</BrowserRouter>
|
|
764
697
|
);
|
|
765
698
|
```
|
|
766
699
|
|
|
767
700
|
```jsx fileName="src/components/LocaleRouter.mjx" codeFormat="esm"
|
|
768
|
-
|
|
769
|
-
import {
|
|
770
|
-
|
|
771
|
-
import {
|
|
772
|
-
import {
|
|
773
|
-
BrowserRouter,
|
|
774
|
-
Routes,
|
|
775
|
-
Route,
|
|
776
|
-
Navigate,
|
|
777
|
-
useLocation,
|
|
778
|
-
} from "react-router-dom"; // Router-Komponenten zur Verwaltung der Navigation
|
|
779
|
-
|
|
780
|
-
// Destrukturierung der Konfiguration von Intlayer
|
|
781
|
-
const { internationalization, middleware } = configuration;
|
|
782
|
-
const { locales, defaultLocale } = internationalization;
|
|
783
|
-
|
|
784
|
-
/**
|
|
785
|
-
* Eine Komponente, die die Lokalisierung verwaltet und Kinder mit dem entsprechenden Locale-Kontext umschließt.
|
|
786
|
-
/**
|
|
787
|
-
* Es verwaltet die auf der URL basierende Lokalisierungserkennung und -validierung.
|
|
788
|
-
*/
|
|
789
|
-
const AppLocalized = ({ children, locale }) => {
|
|
790
|
-
const { pathname, search } = useLocation(); // Holt den aktuellen URL-Pfad
|
|
791
|
-
|
|
792
|
-
// Bestimmt die aktuelle Locale, standardmäßig die Standard-Locale, falls keine angegeben ist
|
|
793
|
-
const currentLocale = locale ?? defaultLocale;
|
|
794
|
-
|
|
795
|
-
// Entfernt das Locale-Präfix aus dem Pfad, um einen Basis-Pfad zu erstellen
|
|
796
|
-
const pathWithoutLocale = getPathWithoutLocale(
|
|
797
|
-
pathname // Aktueller URL-Pfad
|
|
798
|
-
);
|
|
799
|
-
|
|
800
|
-
/**
|
|
801
|
-
* Wenn middleware.prefixDefault true ist, sollte die Standard-Locale immer als Präfix verwendet werden.
|
|
802
|
-
*/
|
|
803
|
-
if (middleware.prefixDefault) {
|
|
804
|
-
// Validiert die Locale
|
|
805
|
-
if (!locale || !locales.includes(locale)) {
|
|
806
|
-
// Weiterleitung zur Standard-Locale mit dem aktualisierten Pfad
|
|
807
|
-
return (
|
|
808
|
-
<Navigate
|
|
809
|
-
to={`/${defaultLocale}/${pathWithoutLocale}${search}`}
|
|
810
|
-
replace // Ersetzt den aktuellen Eintrag im Verlauf durch den neuen
|
|
811
|
-
/>
|
|
812
|
-
);
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
// Umschließt die Kinder mit dem IntlayerProvider und setzt die aktuelle Locale
|
|
816
|
-
return (
|
|
817
|
-
<IntlayerProvider locale={currentLocale}>{children}</IntlayerProvider>
|
|
818
|
-
);
|
|
819
|
-
} else {
|
|
820
|
-
/**
|
|
821
|
-
* Wenn middleware.prefixDefault false ist, wird die Standard-Locale nicht vorangestellt.
|
|
822
|
-
* Stelle sicher, dass die aktuelle Locale gültig ist und nicht die Standard-Locale ist.
|
|
823
|
-
*/
|
|
824
|
-
if (
|
|
825
|
-
currentLocale.toString() !== defaultLocale.toString() &&
|
|
826
|
-
!locales
|
|
827
|
-
.filter(
|
|
828
|
-
(locale) => locale.toString() !== defaultLocale.toString() // Schließt die Standard-Locale aus
|
|
829
|
-
)
|
|
830
|
-
.includes(currentLocale) // Überprüfen, ob die aktuelle Locale in der Liste der gültigen Locales enthalten ist
|
|
831
|
-
) {
|
|
832
|
-
// Weiterleitung zum Pfad ohne Locale-Präfix
|
|
833
|
-
return <Navigate to={`${pathWithoutLocale}${search}`} replace />;
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
// Kinder mit dem IntlayerProvider umschließen und die aktuelle Locale setzen
|
|
837
|
-
return (
|
|
838
|
-
<IntlayerProvider locale={currentLocale}>{children}</IntlayerProvider>
|
|
839
|
-
);
|
|
840
|
-
}
|
|
841
|
-
};
|
|
701
|
+
import { localeMap } from 'intlayer'; // Dienstprogramme und Typen von 'intlayer'
|
|
702
|
+
import type { FC, PropsWithChildren } from 'react'; // React-Typen für funktionale Komponenten und Props
|
|
703
|
+
import { IntlayerProvider } from 'react-intlayer'; // Provider für den Internationalisierungskontext
|
|
704
|
+
import { BrowserRouter, Route, Routes } from 'react-router-dom'; // Router-Komponenten zur Verwaltung der Navigation
|
|
842
705
|
|
|
843
706
|
/**
|
|
844
707
|
* Eine Router-Komponente, die locale-spezifische Routen einrichtet.
|
|
845
708
|
* Sie verwendet React Router, um die Navigation zu verwalten und lokalisierte Komponenten zu rendern.
|
|
846
709
|
*/
|
|
847
|
-
export const LocaleRouter = ({ children }) => (
|
|
710
|
+
export const LocaleRouter: FC<PropsWithChildren> = ({ children }) => (
|
|
848
711
|
<BrowserRouter>
|
|
849
712
|
<Routes>
|
|
850
|
-
{
|
|
851
|
-
|
|
852
|
-
(
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
/>
|
|
861
|
-
))}
|
|
862
|
-
|
|
863
|
-
{
|
|
864
|
-
// Wenn das Präfix für die Standard-Locale deaktiviert ist, werden die Kinder direkt im Stammverzeichnis gerendert
|
|
865
|
-
!middleware.prefixDefault && (
|
|
866
|
-
<Route
|
|
867
|
-
path="*"
|
|
868
|
-
element={
|
|
869
|
-
<AppLocalized locale={defaultLocale}>{children}</AppLocalized>
|
|
870
|
-
} // Umschließt die Kinder mit der Locale-Verwaltung
|
|
871
|
-
/>
|
|
872
|
-
)
|
|
873
|
-
}
|
|
713
|
+
{localeMap(({ locale, urlPrefix }) => (
|
|
714
|
+
<Route
|
|
715
|
+
// Routenmuster zur Erfassung der Locale (z. B. /en/, /fr/) und zum Abgleich aller nachfolgenden Pfade
|
|
716
|
+
path={`${urlPrefix}/*`}
|
|
717
|
+
key={locale}
|
|
718
|
+
element={
|
|
719
|
+
<IntlayerProvider locale={locale}>{children}</IntlayerProvider>
|
|
720
|
+
} // Umschließt die Kinder mit der Locale-Verwaltung
|
|
721
|
+
/>
|
|
722
|
+
))}
|
|
874
723
|
</Routes>
|
|
875
724
|
</BrowserRouter>
|
|
876
725
|
);
|
|
877
726
|
```
|
|
878
727
|
|
|
879
728
|
```jsx fileName="src/components/LocaleRouter.cjx" codeFormat="commonjs"
|
|
880
|
-
|
|
881
|
-
const
|
|
882
|
-
const { IntlayerProvider
|
|
883
|
-
const {
|
|
884
|
-
BrowserRouter,
|
|
885
|
-
Routes,
|
|
886
|
-
Route,
|
|
887
|
-
Navigate,
|
|
888
|
-
useLocation,
|
|
889
|
-
} = require("react-router-dom"); // Router-Komponenten zur Verwaltung der Navigation
|
|
890
|
-
|
|
891
|
-
// Destrukturierung der Konfiguration von Intlayer
|
|
892
|
-
const { internationalization, middleware } = configuration;
|
|
893
|
-
const { locales, defaultLocale } = internationalization;
|
|
729
|
+
const { localeMap } = require("intlayer"); // Dienstprogramme und Typen von 'intlayer'
|
|
730
|
+
const React = require("react"); // React importieren
|
|
731
|
+
const { IntlayerProvider } = require("react-intlayer"); // Provider für den Internationalisierungskontext
|
|
732
|
+
const { BrowserRouter, Route, Routes } = require("react-router-dom"); // Router-Komponenten zur Verwaltung der Navigation
|
|
894
733
|
|
|
895
734
|
/**
|
|
896
|
-
* Eine Komponente, die
|
|
897
|
-
* Sie verwaltet die URL-basierte Lokalerkennung und Validierung.
|
|
898
|
-
*/
|
|
899
|
-
const AppLocalized = ({ children, locale }) => {
|
|
900
|
-
const { pathname, search } = useLocation(); // Hole den aktuellen URL-Pfad
|
|
901
|
-
|
|
902
|
-
// Bestimme die aktuelle Locale, standardmäßig auf die Default-Locale zurückfallend, falls nicht angegeben
|
|
903
|
-
const currentLocale = locale ?? defaultLocale;
|
|
904
|
-
|
|
905
|
-
// Entferne das Locale-Präfix aus dem Pfad, um einen Basis-Pfad zu erstellen
|
|
906
|
-
const pathWithoutLocale = getPathWithoutLocale(
|
|
907
|
-
pathname // Aktueller URL-Pfad
|
|
908
|
-
);
|
|
909
|
-
|
|
910
|
-
/**
|
|
911
|
-
* Wenn middleware.prefixDefault true ist, sollte die Default-Locale immer vorangestellt werden.
|
|
912
|
-
*/
|
|
913
|
-
if (middleware.prefixDefault) {
|
|
914
|
-
// Überprüfe die Locale
|
|
915
|
-
if (!locale || !locales.includes(locale)) {
|
|
916
|
-
// Weiterleitung zur Default-Locale mit dem aktualisierten Pfad
|
|
917
|
-
return (
|
|
918
|
-
<Navigate
|
|
919
|
-
to={`/${defaultLocale}/${pathWithoutLocale}${search}`}
|
|
920
|
-
replace // Ersetzt den aktuellen Eintrag in der Historie durch den neuen
|
|
921
|
-
/>
|
|
922
|
-
);
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
// Umschließt die Kinder mit dem IntlayerProvider und setzt die aktuelle Locale
|
|
926
|
-
return (
|
|
927
|
-
<IntlayerProvider locale={currentLocale}>{children}</IntlayerProvider>
|
|
928
|
-
);
|
|
929
|
-
} else {
|
|
930
|
-
/**
|
|
931
|
-
* Wenn middleware.prefixDefault false ist, wird die Standard-Locale nicht vorangestellt.
|
|
932
|
-
* Stelle sicher, dass die aktuelle Locale gültig ist und nicht die Standard-Locale ist.
|
|
933
|
-
*/
|
|
934
|
-
if (
|
|
935
|
-
currentLocale.toString() !== defaultLocale.toString() &&
|
|
936
|
-
!locales
|
|
937
|
-
.filter(
|
|
938
|
-
(locale) => locale.toString() !== defaultLocale.toString() // Schließt die Standard-Locale aus
|
|
939
|
-
)
|
|
940
|
-
.includes(currentLocale) // Prüft, ob die aktuelle Locale in der Liste der gültigen Locales ist
|
|
941
|
-
) {
|
|
942
|
-
// Weiterleitung zum Pfad ohne Sprachpräfix
|
|
943
|
-
return <Navigate to={`${pathWithoutLocale}${search}`} replace />;
|
|
944
|
-
}
|
|
945
|
-
|
|
946
|
-
// Kinder mit dem IntlayerProvider umschließen und die aktuelle Sprache setzen
|
|
947
|
-
return (
|
|
948
|
-
<IntlayerProvider locale={currentLocale}>{children}</IntlayerProvider>
|
|
949
|
-
);
|
|
950
|
-
}
|
|
951
|
-
};
|
|
952
|
-
|
|
953
|
-
/**
|
|
954
|
-
* Eine Router-Komponente, die sprachspezifische Routen einrichtet.
|
|
735
|
+
* Eine Router-Komponente, die locale-spezifische Routen einrichtet.
|
|
955
736
|
* Sie verwendet React Router, um die Navigation zu verwalten und lokalisierte Komponenten zu rendern.
|
|
956
737
|
*/
|
|
957
|
-
const LocaleRouter = ({ children }) =>
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
738
|
+
const LocaleRouter = ({ children }) =>
|
|
739
|
+
React.createElement(
|
|
740
|
+
BrowserRouter,
|
|
741
|
+
{},
|
|
742
|
+
React.createElement(
|
|
743
|
+
Routes,
|
|
744
|
+
{},
|
|
745
|
+
localeMap(({ locale, urlPrefix }) =>
|
|
746
|
+
React.createElement(Route, {
|
|
747
|
+
path: `${urlPrefix}/*`,
|
|
748
|
+
key: locale,
|
|
749
|
+
element: React.createElement(IntlayerProvider, { locale }, children),
|
|
750
|
+
})
|
|
751
|
+
)
|
|
752
|
+
)
|
|
753
|
+
);
|
|
972
754
|
|
|
973
|
-
|
|
974
|
-
// Wenn das Präfix für die Standardsprache deaktiviert ist, rendere die Kinder direkt im Stammverzeichnis
|
|
975
|
-
!middleware.prefixDefault && (
|
|
976
|
-
<Route
|
|
977
|
-
path="*"
|
|
978
|
-
element={
|
|
979
|
-
<AppLocalized locale={defaultLocale}>{children}</AppLocalized>
|
|
980
|
-
} // Umschließt Kinder mit der Sprachverwaltung
|
|
981
|
-
/>
|
|
982
|
-
)
|
|
983
|
-
}
|
|
984
|
-
</Routes>
|
|
985
|
-
</BrowserRouter>
|
|
986
|
-
);
|
|
755
|
+
exports.LocaleRouter = LocaleRouter;
|
|
987
756
|
```
|
|
988
757
|
|
|
758
|
+
> Hinweis: Wenn Sie `routing.mode: 'no-prefix' | 'search-params'` verwenden, müssen Sie die Funktion `localeMap` wahrscheinlich nicht verwenden.
|
|
759
|
+
|
|
989
760
|
Dann können Sie die Komponente `LocaleRouter` in Ihrer Anwendung verwenden:
|
|
990
761
|
|
|
991
762
|
```tsx fileName="src/App.tsx" codeFormat="typescript"
|
|
@@ -1027,6 +798,8 @@ const App = () => (
|
|
|
1027
798
|
|
|
1028
799
|
Parallel dazu können Sie auch das `intlayerProxy` verwenden, um serverseitiges Routing in Ihre Anwendung zu integrieren. Dieses Plugin erkennt automatisch die aktuelle Locale basierend auf der URL und setzt das entsprechende Locale-Cookie. Wenn keine Locale angegeben ist, bestimmt das Plugin die passendste Locale basierend auf den Spracheinstellungen des Browsers des Benutzers. Wird keine Locale erkannt, erfolgt eine Weiterleitung zur Standard-Locale.
|
|
1029
800
|
|
|
801
|
+
> Beachten Sie, dass Sie für die Verwendung von `intlayerProxy` in der Produktion das Paket `vite-intlayer` von `devDependencies` zu `dependencies` verschieben müssen.
|
|
802
|
+
|
|
1030
803
|
```typescript {3,7} fileName="vite.config.ts" codeFormat="typescript"
|
|
1031
804
|
import { defineConfig } from "vite";
|
|
1032
805
|
import react from "@vitejs/plugin-react-swc";
|
|
@@ -1062,7 +835,7 @@ module.exports = defineConfig({
|
|
|
1062
835
|
|
|
1063
836
|
### (Optional) Schritt 8: URL ändern, wenn sich die Sprache ändert
|
|
1064
837
|
|
|
1065
|
-
Um die URL zu ändern, wenn sich die
|
|
838
|
+
Um die URL zu ändern, wenn sich die Locale ändert, können Sie die `onLocaleChange`-Eigenschaft verwenden, die vom `useLocale`-Hook bereitgestellt wird. Parallel dazu können Sie die Hooks `useLocation` und `useNavigate` von `react-router-dom` verwenden, um den URL-Pfad zu aktualisieren.
|
|
1066
839
|
|
|
1067
840
|
```tsx fileName="src/components/LocaleSwitcher.tsx" codeFormat="typescript"
|
|
1068
841
|
import { useLocation, useNavigate } from "react-router-dom";
|
|
@@ -1259,10 +1032,10 @@ const LocaleSwitcher = () => {
|
|
|
1259
1032
|
|
|
1260
1033
|
> Dokumentationsreferenzen:
|
|
1261
1034
|
>
|
|
1262
|
-
> - [`useLocale` Hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/
|
|
1263
|
-
> - [`getLocaleName` Hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/
|
|
1264
|
-
> - [`getLocalizedUrl` Hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/
|
|
1265
|
-
> - [`getHTMLTextDir` hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/
|
|
1035
|
+
> - [`useLocale` Hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/react-intlayer/useLocale.md)
|
|
1036
|
+
> - [`getLocaleName` Hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/intlayer/getLocaleName.md)
|
|
1037
|
+
> - [`getLocalizedUrl` Hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/intlayer/getLocalizedUrl.md)
|
|
1038
|
+
> - [`getHTMLTextDir` hook](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en/packages/intlayer/getHTMLTextDir.md)
|
|
1266
1039
|
> - [`hrefLang` Attribut](https://developers.google.com/search/docs/specialty/international/localized-versions?hl=fr)
|
|
1267
1040
|
> - [`lang` Attribut](https://developer.mozilla.org/de/docs/Web/HTML/Global_attributes/lang)
|
|
1268
1041
|
> - [`dir` Attribut](https://developer.mozilla.org/de/docs/Web/HTML/Global_attributes/dir)
|
|
@@ -1284,7 +1057,7 @@ Indem Sie diese Attribute dynamisch aktualisieren, wenn sich die Spracheinstellu
|
|
|
1284
1057
|
|
|
1285
1058
|
#### Implementierung des Hooks
|
|
1286
1059
|
|
|
1287
|
-
Erstellen Sie einen benutzerdefinierten Hook, um die HTML-Attribute zu verwalten. Der Hook hört auf Änderungen der
|
|
1060
|
+
Erstellen Sie einen benutzerdefinierten Hook, um die HTML-Attribute zu verwalten. Der Hook hört auf Änderungen der Locale und aktualisiert die Attribute entsprechend:
|
|
1288
1061
|
|
|
1289
1062
|
```tsx fileName="src/hooks/useI18nHTMLAttributes.tsx" codeFormat="typescript"
|
|
1290
1063
|
import { useEffect } from "react";
|
|
@@ -1292,7 +1065,7 @@ import { useLocale } from "react-intlayer";
|
|
|
1292
1065
|
import { getHTMLTextDir } from "intlayer";
|
|
1293
1066
|
|
|
1294
1067
|
/**
|
|
1295
|
-
* Aktualisiert die `lang`- und `dir`-Attribute des HTML-Elements `<html>` basierend auf der aktuellen
|
|
1068
|
+
* Aktualisiert die `lang`- und `dir`-Attribute des HTML-Elements `<html>` basierend auf der aktuellen Locale.
|
|
1296
1069
|
* - `lang`: Informiert Browser und Suchmaschinen über die Sprache der Seite.
|
|
1297
1070
|
* - `dir`: Stellt die korrekte Leserichtung sicher (z.B. 'ltr' für Englisch, 'rtl' für Arabisch).
|
|
1298
1071
|
*
|
|
@@ -1365,32 +1138,6 @@ module.exports = { useI18nHTMLAttributes };
|
|
|
1365
1138
|
|
|
1366
1139
|
#### Verwendung des Hooks in Ihrer Anwendung
|
|
1367
1140
|
|
|
1368
|
-
Integrieren Sie den Hook in Ihre Hauptkomponente, damit die HTML-Attribute bei jeder Änderung der Locale aktualisiert werden:
|
|
1369
|
-
|
|
1370
|
-
```tsx fileName="src/App.tsx" codeFormat="typescript"
|
|
1371
|
-
import type { FC } from "react";
|
|
1372
|
-
import { IntlayerProvider, useIntlayer } from "react-intlayer";
|
|
1373
|
-
import { useI18nHTMLAttributes } from "./hooks/useI18nHTMLAttributes";
|
|
1374
|
-
import "./App.css";
|
|
1375
|
-
|
|
1376
|
-
const AppContent: FC = () => {
|
|
1377
|
-
// Wenden Sie den Hook an, um die lang- und dir-Attribute des <html>-Tags basierend auf der Locale zu aktualisieren.
|
|
1378
|
-
useI18nHTMLAttributes();
|
|
1379
|
-
|
|
1380
|
-
// ... Rest Ihrer Komponente
|
|
1381
|
-
};
|
|
1382
|
-
|
|
1383
|
-
const App: FC = () => (
|
|
1384
|
-
<IntlayerProvider>
|
|
1385
|
-
<AppContent />
|
|
1386
|
-
</IntlayerProvider>
|
|
1387
|
-
);
|
|
1388
|
-
|
|
1389
|
-
export default App;
|
|
1390
|
-
```
|
|
1391
|
-
|
|
1392
|
-
#### Verwendung des Hooks in Ihrer Anwendung
|
|
1393
|
-
|
|
1394
1141
|
Integrieren Sie den Hook in Ihre Hauptkomponente, damit die HTML-Attribute aktualisiert werden, sobald sich die Locale ändert:
|
|
1395
1142
|
|
|
1396
1143
|
```tsx fileName="src/App.tsx" codeFormat="typescript"
|
|
@@ -1466,14 +1213,6 @@ Durch diese Änderungen wird Ihre Anwendung:
|
|
|
1466
1213
|
|
|
1467
1214
|
### (Optional) Schritt 10: Erstellen einer lokalisierten Link-Komponente
|
|
1468
1215
|
|
|
1469
|
-
Durch die Anwendung dieser Änderungen wird Ihre Anwendung:
|
|
1470
|
-
|
|
1471
|
-
- Sicherstellen, dass das **Sprach**-Attribut (`lang`) die aktuelle Locale korrekt widerspiegelt, was wichtig für SEO und das Verhalten des Browsers ist.
|
|
1472
|
-
- Die **Schreibrichtung** (`dir`) entsprechend der Locale anpassen, um die Lesbarkeit und Benutzerfreundlichkeit für Sprachen mit unterschiedlichen Leserichtungen zu verbessern.
|
|
1473
|
-
- Eine zugänglichere **Benutzererfahrung** bieten, da unterstützende Technologien auf diese Attribute angewiesen sind, um optimal zu funktionieren.
|
|
1474
|
-
|
|
1475
|
-
### (Optional) Schritt 10: Erstellen einer lokalisierten Link-Komponente
|
|
1476
|
-
|
|
1477
1216
|
Um sicherzustellen, dass die Navigation Ihrer Anwendung die aktuelle Sprache berücksichtigt, können Sie eine benutzerdefinierte `Link`-Komponente erstellen. Diese Komponente fügt automatisch den aktuellen Sprachpräfix zu internen URLs hinzu. Zum Beispiel wird ein französischsprachiger Benutzer, der auf einen Link zur "Über uns"-Seite klickt, zu `/fr/about` statt zu `/about` weitergeleitet.
|
|
1478
1217
|
|
|
1479
1218
|
Dieses Verhalten ist aus mehreren Gründen nützlich:
|
|
@@ -1493,11 +1232,10 @@ import {
|
|
|
1493
1232
|
} from "react";
|
|
1494
1233
|
import { useLocale } from "react-intlayer";
|
|
1495
1234
|
|
|
1496
|
-
export interface LinkProps
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
> {}
|
|
1235
|
+
export interface LinkProps extends DetailedHTMLProps<
|
|
1236
|
+
AnchorHTMLAttributes<HTMLAnchorElement>,
|
|
1237
|
+
HTMLAnchorElement
|
|
1238
|
+
> {}
|
|
1501
1239
|
|
|
1502
1240
|
/**
|
|
1503
1241
|
* Hilfsfunktion, um zu prüfen, ob eine gegebene URL extern ist.
|
|
@@ -1622,7 +1360,7 @@ Indem Sie diese `Link`-Komponente in Ihrer gesamten Anwendung integrieren, gewä
|
|
|
1622
1360
|
|
|
1623
1361
|
### TypeScript konfigurieren
|
|
1624
1362
|
|
|
1625
|
-
Intlayer verwendet Module Augmentation, um die Vorteile von TypeScript zu nutzen und
|
|
1363
|
+
Intlayer verwendet Module Augmentation, um die Vorteile von TypeScript zu nutzen und Ihre Codebasis robuster zu machen.
|
|
1626
1364
|
|
|
1627
1365
|

|
|
1628
1366
|
|
|
@@ -1642,18 +1380,18 @@ Stellen Sie sicher, dass Ihre TypeScript-Konfiguration die automatisch generiert
|
|
|
1642
1380
|
|
|
1643
1381
|
### Git-Konfiguration
|
|
1644
1382
|
|
|
1645
|
-
Es wird empfohlen, die von Intlayer generierten Dateien zu ignorieren. Dadurch vermeiden Sie, diese
|
|
1383
|
+
Es wird empfohlen, die von Intlayer generierten Dateien zu ignorieren. Dadurch vermeiden Sie, diese in Ihr Git-Repository zu committen.
|
|
1646
1384
|
|
|
1647
1385
|
Fügen Sie dazu folgende Anweisungen in Ihre `.gitignore`-Datei ein:
|
|
1648
1386
|
|
|
1649
|
-
```plaintext
|
|
1650
|
-
#
|
|
1387
|
+
```plaintext fileName=".gitignore"
|
|
1388
|
+
# Ignoriere die von Intlayer generierten Dateien
|
|
1651
1389
|
.intlayer
|
|
1652
1390
|
```
|
|
1653
1391
|
|
|
1654
1392
|
### VS Code Erweiterung
|
|
1655
1393
|
|
|
1656
|
-
Um Ihre Entwicklungserfahrung mit Intlayer zu verbessern, können Sie die offizielle **Intlayer VS Code
|
|
1394
|
+
Um Ihre Entwicklungserfahrung mit Intlayer zu verbessern, können Sie die offizielle **Intlayer VS Code Extension** installieren.
|
|
1657
1395
|
|
|
1658
1396
|
[Installation aus dem VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|
|
1659
1397
|
|
|
@@ -1671,5 +1409,3 @@ Für weitere Details zur Nutzung der Erweiterung siehe die [Intlayer VS Code Ext
|
|
|
1671
1409
|
### Weiterführende Schritte
|
|
1672
1410
|
|
|
1673
1411
|
Um weiterzugehen, können Sie den [visuellen Editor](https://github.com/aymericzip/intlayer/blob/main/docs/docs/de/intlayer_visual_editor.md) implementieren oder Ihre Inhalte mit dem [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/de/intlayer_CMS.md) auslagern.
|
|
1674
|
-
|
|
1675
|
-
---
|