@intlayer/docs 7.3.10 → 7.3.12
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/dist/cjs/generated/docs.entry.cjs +19 -0
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/esm/generated/docs.entry.mjs +19 -0
- package/dist/esm/generated/docs.entry.mjs.map +1 -1
- package/dist/types/generated/docs.entry.d.ts +1 -0
- package/dist/types/generated/docs.entry.d.ts.map +1 -1
- package/docs/ar/intlayer_with_nuxt.md +305 -421
- package/docs/ar/intlayer_with_react_router_v7.md +33 -4
- package/docs/ar/intlayer_with_react_router_v7_fs_routes.md +516 -0
- package/docs/ar/intlayer_with_tanstack.md +2 -12
- package/docs/ar/intlayer_with_vite+vue.md +1 -0
- package/docs/de/intlayer_with_nuxt.md +296 -394
- package/docs/de/intlayer_with_react_router_v7.md +33 -4
- package/docs/de/intlayer_with_react_router_v7_fs_routes.md +573 -0
- package/docs/de/intlayer_with_tanstack.md +1 -0
- package/docs/de/intlayer_with_vite+vue.md +1 -0
- package/docs/en/intlayer_with_nuxt.md +242 -321
- package/docs/en/intlayer_with_react_router_v7.md +24 -0
- package/docs/en/intlayer_with_react_router_v7_fs_routes.md +570 -0
- package/docs/en/intlayer_with_tanstack.md +2 -12
- package/docs/en/intlayer_with_vite+vue.md +49 -48
- package/docs/en-GB/intlayer_with_nuxt.md +262 -358
- package/docs/en-GB/intlayer_with_react_router_v7.md +33 -4
- package/docs/en-GB/intlayer_with_react_router_v7_fs_routes.md +513 -0
- package/docs/en-GB/intlayer_with_tanstack.md +2 -12
- package/docs/en-GB/intlayer_with_vite+vue.md +1 -0
- package/docs/es/intlayer_with_nuxt.md +284 -375
- package/docs/es/intlayer_with_react_router_v7.md +33 -4
- package/docs/es/intlayer_with_react_router_v7_fs_routes.md +575 -0
- package/docs/es/intlayer_with_tanstack.md +1 -0
- package/docs/es/intlayer_with_vite+vue.md +1 -2
- package/docs/fr/intlayer_with_nuxt.md +288 -387
- package/docs/fr/intlayer_with_react_router_v7.md +34 -5
- package/docs/fr/intlayer_with_react_router_v7_fs_routes.md +574 -0
- package/docs/fr/intlayer_with_tanstack.md +1 -0
- package/docs/fr/intlayer_with_vite+vue.md +1 -0
- package/docs/hi/intlayer_with_nuxt.md +318 -434
- package/docs/hi/intlayer_with_react_router_v7.md +33 -4
- package/docs/hi/intlayer_with_react_router_v7_fs_routes.md +518 -0
- package/docs/hi/intlayer_with_tanstack.md +2 -12
- package/docs/hi/intlayer_with_vite+vue.md +1 -0
- package/docs/id/intlayer_with_nuxt.md +275 -376
- package/docs/id/intlayer_with_react_router_v7.md +29 -4
- package/docs/id/intlayer_with_react_router_v7_fs_routes.md +521 -0
- package/docs/id/intlayer_with_tanstack.md +2 -12
- package/docs/id/intlayer_with_vite+vue.md +1 -0
- package/docs/it/intlayer_with_nuxt.md +312 -408
- package/docs/it/intlayer_with_react_router_v7.md +33 -4
- package/docs/it/intlayer_with_react_router_v7_fs_routes.md +574 -0
- package/docs/it/intlayer_with_tanstack.md +1 -0
- package/docs/ja/intlayer_with_nuxt.md +319 -414
- package/docs/ja/intlayer_with_react_router_v7.md +33 -4
- package/docs/ja/intlayer_with_react_router_v7_fs_routes.md +574 -0
- package/docs/ja/intlayer_with_tanstack.md +2 -12
- package/docs/ja/intlayer_with_vite+vue.md +1 -0
- package/docs/ko/intlayer_with_nuxt.md +307 -406
- package/docs/ko/intlayer_with_react_router_v7.md +33 -4
- package/docs/ko/intlayer_with_react_router_v7_fs_routes.md +515 -0
- package/docs/ko/intlayer_with_tanstack.md +2 -12
- package/docs/ko/intlayer_with_vite+vue.md +1 -0
- package/docs/pl/intlayer_with_nuxt.md +282 -457
- package/docs/pl/intlayer_with_react_router_v7.md +32 -5
- package/docs/pl/intlayer_with_react_router_v7_fs_routes.md +615 -0
- package/docs/pl/intlayer_with_tanstack.md +2 -12
- package/docs/pl/intlayer_with_vite+vue.md +1 -0
- package/docs/pt/intlayer_with_nuxt.md +288 -403
- package/docs/pt/intlayer_with_react_router_v7.md +28 -0
- package/docs/pt/intlayer_with_tanstack.md +1 -0
- package/docs/ru/intlayer_with_nuxt.md +300 -410
- package/docs/ru/intlayer_with_react_router_v7.md +33 -4
- package/docs/ru/intlayer_with_react_router_v7_fs_routes.md +574 -0
- package/docs/ru/intlayer_with_tanstack.md +1 -0
- package/docs/ru/intlayer_with_vite+vue.md +1 -0
- package/docs/tr/intlayer_with_nuxt.md +327 -392
- package/docs/tr/intlayer_with_react_router_v7.md +33 -4
- package/docs/tr/intlayer_with_react_router_v7_fs_routes.md +572 -0
- package/docs/tr/intlayer_with_tanstack.md +2 -12
- package/docs/tr/intlayer_with_vite+vue.md +1 -0
- package/docs/vi/intlayer_with_nuxt.md +282 -399
- package/docs/vi/intlayer_with_react_router_v7.md +29 -4
- package/docs/vi/intlayer_with_react_router_v7_fs_routes.md +523 -0
- package/docs/vi/intlayer_with_tanstack.md +2 -12
- package/docs/vi/intlayer_with_vite+vue.md +1 -0
- package/docs/zh/intlayer_with_nuxt.md +311 -444
- package/docs/zh/intlayer_with_react_router_v7.md +33 -4
- package/docs/zh/intlayer_with_react_router_v7_fs_routes.md +516 -0
- package/docs/zh/intlayer_with_tanstack.md +2 -12
- package/docs/zh/intlayer_with_vite+vue.md +1 -0
- package/package.json +6 -6
- package/src/generated/docs.entry.ts +19 -0
|
@@ -18,6 +18,7 @@ slugs:
|
|
|
18
18
|
- vite-and-react
|
|
19
19
|
- react-router-v7
|
|
20
20
|
applicationTemplate: https://github.com/aymericzip/intlayer-react-router-v7-template
|
|
21
|
+
youtubeVideo: https://www.youtube.com/watch?v=dS9L7uJeak4
|
|
21
22
|
history:
|
|
22
23
|
- version: 6.1.5
|
|
23
24
|
date: 2025-10-03
|
|
@@ -31,6 +32,10 @@ history:
|
|
|
31
32
|
|
|
32
33
|
Ce guide montre comment intégrer **Intlayer** pour une internationalisation fluide dans les projets React Router v7 avec un routage sensible à la locale, la prise en charge de TypeScript, et des pratiques de développement modernes.
|
|
33
34
|
|
|
35
|
+
## Table of Contents
|
|
36
|
+
|
|
37
|
+
<TOC/>
|
|
38
|
+
|
|
34
39
|
## Qu'est-ce que Intlayer ?
|
|
35
40
|
|
|
36
41
|
**Intlayer** est une bibliothèque d'internationalisation (i18n) innovante et open-source, conçue pour simplifier la prise en charge multilingue dans les applications web modernes.
|
|
@@ -75,6 +80,29 @@ pnpm add vite-intlayer --save-dev
|
|
|
75
80
|
|
|
76
81
|
### Étape 2 : Configuration de votre projet
|
|
77
82
|
|
|
83
|
+
## Guide étape par étape pour configurer Intlayer dans une application React Router v7 avec des routes basées sur le système de fichiers
|
|
84
|
+
|
|
85
|
+
<Tab defaultTab="video">
|
|
86
|
+
<TabItem label="Video" value="video">
|
|
87
|
+
|
|
88
|
+
<iframe title="How to translate your React Router v7 app using 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?autoplay=0&origin=http://intlayer.org&controls=0&rel=1"/>
|
|
89
|
+
|
|
90
|
+
</TabItem>
|
|
91
|
+
<TabItem label="Code" value="code">
|
|
92
|
+
|
|
93
|
+
<iframe
|
|
94
|
+
src="https://stackblitz.com/github/aymericzip/intlayer-react-router-v7-template?embed=1&ctl=1&file=intlayer.config.ts"
|
|
95
|
+
className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
|
|
96
|
+
title="Demo CodeSandbox - How to Internationalize your application using Intlayer"
|
|
97
|
+
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
|
|
98
|
+
loading="lazy"
|
|
99
|
+
/>
|
|
100
|
+
|
|
101
|
+
</TabItem>
|
|
102
|
+
</Tab>
|
|
103
|
+
|
|
104
|
+
See [Application Template](https://github.com/aymericzip/intlayer-react-router-v7-template) on GitHub.
|
|
105
|
+
|
|
78
106
|
Créez un fichier de configuration pour configurer les langues de votre application :
|
|
79
107
|
|
|
80
108
|
```typescript fileName="intlayer.config.ts" codeFormat="typescript"
|
|
@@ -260,7 +288,7 @@ export const LocalizedLink: FC<LinkProps> = (props) => {
|
|
|
260
288
|
Dans le cas où vous souhaitez naviguer vers les routes localisées, vous pouvez utiliser le hook `useLocalizedNavigate` :
|
|
261
289
|
|
|
262
290
|
```tsx fileName="app/hooks/useLocalizedNavigate.ts"
|
|
263
|
-
import { useLocale } from "intlayer";
|
|
291
|
+
import { useLocale } from "react-intlayer";
|
|
264
292
|
import { type NavigateOptions, type To, useNavigate } from "react-router";
|
|
265
293
|
|
|
266
294
|
import { locacalizeTo } from "~/components/localized-link";
|
|
@@ -318,6 +346,7 @@ import {
|
|
|
318
346
|
getLocaleName,
|
|
319
347
|
getLocalizedUrl,
|
|
320
348
|
getPathWithoutLocale,
|
|
349
|
+
Locales,
|
|
321
350
|
} from "intlayer";
|
|
322
351
|
import { setLocaleInStorage, useIntlayer, useLocale } from "react-intlayer";
|
|
323
352
|
import { Link, useLocation } from "react-router";
|
|
@@ -389,7 +418,7 @@ Puis utilisez-le dans votre composant racine :
|
|
|
389
418
|
|
|
390
419
|
```tsx fileName="app/routes/layout.tsx"
|
|
391
420
|
import { Outlet } from "react-router";
|
|
392
|
-
import { IntlayerProvider } from "intlayer";
|
|
421
|
+
import { IntlayerProvider } from "react-intlayer";
|
|
393
422
|
|
|
394
423
|
import { useI18nHTMLAttributes } from "app/hooks/useI18nHTMLAttributes"; // importer le hook
|
|
395
424
|
|
|
@@ -411,13 +440,13 @@ Vous pouvez également utiliser le `intlayerProxy` pour ajouter un routage côt
|
|
|
411
440
|
> Notez que pour utiliser le `intlayerProxy` en production, vous devez déplacer le package `vite-intlayer` de `devDependencies` vers `dependencies`.
|
|
412
441
|
|
|
413
442
|
```typescript {3,7} fileName="vite.config.ts"
|
|
443
|
+
import { reactRouter } from "@react-router/dev/vite";
|
|
414
444
|
import { defineConfig } from "vite";
|
|
415
|
-
import react from "@vitejs/plugin-react-swc";
|
|
416
445
|
import { intlayer, intlayerProxy } from "vite-intlayer";
|
|
446
|
+
import tsconfigPaths from "vite-tsconfig-paths";
|
|
417
447
|
|
|
418
|
-
// https://vitejs.dev/config/
|
|
419
448
|
export default defineConfig({
|
|
420
|
-
plugins: [
|
|
449
|
+
plugins: [reactRouter(), tsconfigPaths(), intlayer(), intlayerProxy()],
|
|
421
450
|
});
|
|
422
451
|
```
|
|
423
452
|
|
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2025-12-07
|
|
3
|
+
updatedAt: 2025-12-07
|
|
4
|
+
title: Comment traduire votre React Router v7 (File-System Routes) – guide i18n 2025
|
|
5
|
+
description: Apprenez à ajouter l'internationalisation (i18n) à votre application React Router v7 en utilisant Intlayer avec un routage basé sur le système de fichiers. Suivez ce guide complet pour rendre votre application multilingue avec un routage sensible à la locale.
|
|
6
|
+
keywords:
|
|
7
|
+
- Internationalisation
|
|
8
|
+
- Documentation
|
|
9
|
+
- Intlayer
|
|
10
|
+
- React Router v7
|
|
11
|
+
- fs-routes
|
|
12
|
+
- Routes basées sur le système de fichiers
|
|
13
|
+
- React
|
|
14
|
+
- i18n
|
|
15
|
+
- TypeScript
|
|
16
|
+
- Routage par locale
|
|
17
|
+
slugs:
|
|
18
|
+
- doc
|
|
19
|
+
- environment
|
|
20
|
+
- vite-and-react
|
|
21
|
+
- react-router-v7-fs-routes
|
|
22
|
+
applicationTemplate: https://github.com/aymericzip/intlayer-react-router-v7-template-fs-routes
|
|
23
|
+
youtubeVideo: https://www.youtube.com/watch?v=dS9L7uJeak4
|
|
24
|
+
history:
|
|
25
|
+
- version: 7.3.4
|
|
26
|
+
date: 2025-12-08
|
|
27
|
+
changes: Init history
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
# Traduire votre React Router v7 (File-System Routes) avec Intlayer | Internationalisation (i18n)
|
|
31
|
+
|
|
32
|
+
Ce guide montre comment intégrer **Intlayer** pour une internationalisation fluide dans les projets React Router v7 en utilisant un **routage basé sur le système de fichiers** (`@react-router/fs-routes`) avec un routage sensible à la locale, la prise en charge de TypeScript, et des pratiques de développement modernes.
|
|
33
|
+
|
|
34
|
+
## Table of Contents
|
|
35
|
+
|
|
36
|
+
<TOC/>
|
|
37
|
+
|
|
38
|
+
## Qu'est-ce que Intlayer ?
|
|
39
|
+
|
|
40
|
+
**Intlayer** est une bibliothèque d'internationalisation (i18n) innovante et open-source, conçue pour simplifier la prise en charge multilingue dans les applications web modernes.
|
|
41
|
+
|
|
42
|
+
Avec Intlayer, vous pouvez :
|
|
43
|
+
|
|
44
|
+
- **Gérer facilement les traductions** en utilisant des dictionnaires déclaratifs au niveau des composants.
|
|
45
|
+
- **Localiser dynamiquement les métadonnées**, les routes et le contenu.
|
|
46
|
+
- **Assurer la prise en charge de TypeScript** avec des types générés automatiquement, améliorant l'autocomplétion et la détection d'erreurs.
|
|
47
|
+
- **Bénéficier de fonctionnalités avancées**, comme la détection et le changement dynamique de la locale.
|
|
48
|
+
- **Activer un routage sensible à la locale** avec le système de routage basé sur le système de fichiers de React Router v7.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Guide étape par étape pour configurer Intlayer dans une application React Router v7 avec des routes basées sur le système de fichiers
|
|
53
|
+
|
|
54
|
+
<Tab defaultTab="video">
|
|
55
|
+
<TabItem label="Video" value="video">
|
|
56
|
+
|
|
57
|
+
<iframe title="How to translate your React Router v7 (File-System Routes) app using 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?autoplay=0&origin=http://intlayer.org&controls=0&rel=1"/>
|
|
58
|
+
|
|
59
|
+
</TabItem>
|
|
60
|
+
<TabItem label="Code" value="code">
|
|
61
|
+
|
|
62
|
+
<iframe
|
|
63
|
+
src="https://stackblitz.com/github/aymericzip/intlayer-react-router-v7-template-fs-routes?embed=1&ctl=1&file=intlayer.config.ts"
|
|
64
|
+
className="m-auto overflow-hidden rounded-lg border-0 max-md:size-full max-md:h-[700px] md:aspect-16/9 md:w-full"
|
|
65
|
+
title="Demo CodeSandbox - How to Internationalize your application using Intlayer"
|
|
66
|
+
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
|
|
67
|
+
loading="lazy"
|
|
68
|
+
/>
|
|
69
|
+
|
|
70
|
+
</TabItem>
|
|
71
|
+
</Tab>
|
|
72
|
+
|
|
73
|
+
See [Application Template](https://github.com/aymericzip/intlayer-react-router-v7-template-fs-routes) on GitHub.
|
|
74
|
+
|
|
75
|
+
### Étape 1 : Installer les dépendances
|
|
76
|
+
|
|
77
|
+
Installez les paquets nécessaires en utilisant votre gestionnaire de paquets préféré :
|
|
78
|
+
|
|
79
|
+
```bash packageManager="npm"
|
|
80
|
+
npm install intlayer react-intlayer
|
|
81
|
+
npm install vite-intlayer --save-dev
|
|
82
|
+
npm install @react-router/fs-routes --save-dev
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```bash packageManager="pnpm"
|
|
86
|
+
pnpm add intlayer react-intlayer
|
|
87
|
+
pnpm add vite-intlayer --save-dev
|
|
88
|
+
pnpm add @react-router/fs-routes --save-dev
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
- **intlayer**
|
|
92
|
+
|
|
93
|
+
- **intlayer**
|
|
94
|
+
|
|
95
|
+
Le package principal qui fournit des outils d'internationalisation pour la gestion de la configuration, la traduction, la [déclaration de contenu](https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/dictionary/get_started.md), la transpilation, et les [commandes CLI](https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/intlayer_cli.md).
|
|
96
|
+
|
|
97
|
+
- **react-intlayer**
|
|
98
|
+
Le package qui intègre Intlayer avec une application React. Il fournit des fournisseurs de contexte et des hooks pour l'internationalisation dans React.
|
|
99
|
+
|
|
100
|
+
- **vite-intlayer**
|
|
101
|
+
Comprend le plugin Vite pour intégrer Intlayer avec le [bundler Vite](https://vite.dev/guide/why.html#why-bundle-for-production), ainsi que des middlewares pour détecter la locale préférée de l'utilisateur, gérer les cookies, et gérer la redirection des URL.
|
|
102
|
+
|
|
103
|
+
- **@react-router/fs-routes**
|
|
104
|
+
Le package qui active le routage basé sur le système de fichiers pour React Router v7.
|
|
105
|
+
|
|
106
|
+
### Étape 2 : Configuration de votre projet
|
|
107
|
+
|
|
108
|
+
Créez un fichier de configuration pour configurer les langues de votre application :
|
|
109
|
+
|
|
110
|
+
```typescript fileName="intlayer.config.ts" codeFormat="typescript"
|
|
111
|
+
import { type IntlayerConfig, Locales } from "intlayer";
|
|
112
|
+
|
|
113
|
+
const config: IntlayerConfig = {
|
|
114
|
+
internationalization: {
|
|
115
|
+
defaultLocale: Locales.ENGLISH,
|
|
116
|
+
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export default config;
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
```javascript fileName="intlayer.config.mjs" codeFormat="esm"
|
|
124
|
+
import { Locales } from "intlayer";
|
|
125
|
+
|
|
126
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
127
|
+
const config = {
|
|
128
|
+
internationalization: {
|
|
129
|
+
defaultLocale: Locales.ENGLISH,
|
|
130
|
+
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH],
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export default config;
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
```javascript fileName="intlayer.config.cjs" codeFormat="commonjs"
|
|
138
|
+
const { Locales } = require("intlayer");
|
|
139
|
+
|
|
140
|
+
/** @type {import('intlayer').IntlayerConfig} */
|
|
141
|
+
// Configuration pour l'internationalisation
|
|
142
|
+
const config = {
|
|
143
|
+
internationalization: {
|
|
144
|
+
defaultLocale: Locales.ENGLISH, // Langue par défaut
|
|
145
|
+
locales: [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH], // Langues supportées
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
module.exports = config;
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
> Grâce à ce fichier de configuration, vous pouvez configurer les URLs localisées, la redirection via middleware, les noms des cookies, l'emplacement et l'extension de vos déclarations de contenu, désactiver les logs Intlayer dans la console, et bien plus encore. Pour une liste complète des paramètres disponibles, consultez la [documentation de configuration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/configuration.md).
|
|
153
|
+
|
|
154
|
+
### Étape 3 : Intégrer Intlayer dans votre configuration Vite
|
|
155
|
+
|
|
156
|
+
Ajoutez le plugin intlayer dans votre configuration :
|
|
157
|
+
|
|
158
|
+
```typescript fileName="vite.config.ts"
|
|
159
|
+
import { reactRouter } from "@react-router/dev/vite";
|
|
160
|
+
import { defineConfig } from "vite";
|
|
161
|
+
import { intlayer } from "vite-intlayer";
|
|
162
|
+
import tsconfigPaths from "vite-tsconfig-paths";
|
|
163
|
+
|
|
164
|
+
export default defineConfig({
|
|
165
|
+
plugins: [reactRouter(), tsconfigPaths(), intlayer()],
|
|
166
|
+
});
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
> Le plugin Vite `intlayer()` est utilisé pour intégrer Intlayer avec Vite. Il assure la génération des fichiers de déclaration de contenu et les surveille en mode développement. Il définit les variables d'environnement Intlayer au sein de l'application Vite. De plus, il fournit des alias pour optimiser les performances.
|
|
170
|
+
|
|
171
|
+
### Étape 4 : Configurer les routes basées sur le système de fichiers de React Router v7
|
|
172
|
+
|
|
173
|
+
Configurez votre routage pour utiliser des routes basées sur le système de fichiers avec `flatRoutes` :
|
|
174
|
+
|
|
175
|
+
```typescript fileName="app/routes.ts"
|
|
176
|
+
import type { RouteConfig } from "@react-router/dev/routes";
|
|
177
|
+
import { flatRoutes } from "@react-router/fs-routes";
|
|
178
|
+
import { configuration } from "intlayer";
|
|
179
|
+
|
|
180
|
+
const routes: RouteConfig = flatRoutes({
|
|
181
|
+
// Ignorer les fichiers de déclaration de contenu pour qu'ils ne soient pas traités comme des routes
|
|
182
|
+
ignoredRouteFiles: configuration.content.fileExtensions.map(
|
|
183
|
+
(fileExtension) => `**/*${fileExtension}`
|
|
184
|
+
),
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
export default routes;
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
> La fonction `flatRoutes` de `@react-router/fs-routes` active le routage basé sur le système de fichiers, où la structure des fichiers dans le répertoire `routes/` détermine les routes de votre application. L'option `ignoredRouteFiles` garantit que les fichiers de déclaration de contenu Intlayer (`.content.ts`, etc.) ne sont pas traités comme des fichiers de route.
|
|
191
|
+
|
|
192
|
+
### Étape 5 : Créer des fichiers de route avec les conventions du système de fichiers
|
|
193
|
+
|
|
194
|
+
Avec le routage basé sur le système de fichiers, vous utilisez une convention de nommage plate où les points (`.`) représentent les segments de chemin et les parenthèses `()` désignent les segments optionnels.
|
|
195
|
+
|
|
196
|
+
Créez les fichiers suivants dans votre répertoire `app/routes/` :
|
|
197
|
+
|
|
198
|
+
#### Structure des fichiers
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
app/routes/
|
|
202
|
+
├── ($locale)._layout.tsx # Wrapper de mise en page pour les routes de locale
|
|
203
|
+
├── ($locale)._index.tsx # Page d'accueil (/:locale?)
|
|
204
|
+
├── ($locale)._index.content.ts # Contenu de la page d'accueil
|
|
205
|
+
├── ($locale).about.tsx # Page À propos (/:locale?/about)
|
|
206
|
+
└── ($locale).about.content.ts # Contenu de la page À propos
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Les conventions de nommage :
|
|
210
|
+
|
|
211
|
+
- `($locale)` - Segment dynamique optionnel pour le paramètre de locale
|
|
212
|
+
- `_layout` - Route de mise en page qui enveloppe les routes enfants
|
|
213
|
+
- `_index` - Route d'index (s'affiche au chemin parent)
|
|
214
|
+
- `.` (point) - Sépare les segments de chemin (par exemple, `($locale).about` → `/:locale?/about`)
|
|
215
|
+
|
|
216
|
+
#### Composant de mise en page
|
|
217
|
+
|
|
218
|
+
```tsx fileName="app/routes/($locale)._layout.tsx"
|
|
219
|
+
import { IntlayerProvider } from "react-intlayer";
|
|
220
|
+
import { Outlet } from "react-router";
|
|
221
|
+
|
|
222
|
+
import { useI18nHTMLAttributes } from "~/hooks/useI18nHTMLAttributes";
|
|
223
|
+
|
|
224
|
+
import type { Route } from "./+types/($locale)._layout";
|
|
225
|
+
|
|
226
|
+
export default function RootLayout({ params }: Route.ComponentProps) {
|
|
227
|
+
useI18nHTMLAttributes();
|
|
228
|
+
|
|
229
|
+
const { locale } = params;
|
|
230
|
+
|
|
231
|
+
return (
|
|
232
|
+
<IntlayerProvider locale={locale}>
|
|
233
|
+
<Outlet />
|
|
234
|
+
</IntlayerProvider>
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
#### Page d'index
|
|
240
|
+
|
|
241
|
+
```tsx fileName="app/routes/($locale)._index.tsx"
|
|
242
|
+
import { useIntlayer } from "react-intlayer";
|
|
243
|
+
import { LocalizedLink } from "~/components/localized-link";
|
|
244
|
+
|
|
245
|
+
import type { Route } from "./+types/($locale)._index";
|
|
246
|
+
|
|
247
|
+
export default function Page() {
|
|
248
|
+
const { title, description, aboutLink } = useIntlayer("page");
|
|
249
|
+
|
|
250
|
+
return (
|
|
251
|
+
<div>
|
|
252
|
+
<h1>{title}</h1>
|
|
253
|
+
<p>{description}</p>
|
|
254
|
+
<nav>
|
|
255
|
+
<LocalizedLink to="/about">{aboutLink}</LocalizedLink>
|
|
256
|
+
</nav>
|
|
257
|
+
</div>
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
#### Page À propos
|
|
263
|
+
|
|
264
|
+
```tsx fileName="app/routes/($locale).about.tsx"
|
|
265
|
+
import { useIntlayer } from "react-intlayer";
|
|
266
|
+
import { LocalizedLink } from "~/components/localized-link";
|
|
267
|
+
|
|
268
|
+
import type { Route } from "./+types/($locale).about";
|
|
269
|
+
|
|
270
|
+
export default function AboutPage() {
|
|
271
|
+
const { title, content, homeLink } = useIntlayer("about");
|
|
272
|
+
|
|
273
|
+
return (
|
|
274
|
+
<div>
|
|
275
|
+
<h1>{title}</h1>
|
|
276
|
+
<p>{content}</p>
|
|
277
|
+
<nav>
|
|
278
|
+
<LocalizedLink to="/">{homeLink}</LocalizedLink>
|
|
279
|
+
</nav>
|
|
280
|
+
</div>
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Étape 6 : Déclarez votre contenu
|
|
286
|
+
|
|
287
|
+
Créez et gérez vos déclarations de contenu pour stocker les traductions. Placez les fichiers de contenu à côté de vos fichiers de route :
|
|
288
|
+
|
|
289
|
+
```tsx fileName="app/routes/($locale)._index.content.ts"
|
|
290
|
+
import { t, type Dictionary } from "intlayer";
|
|
291
|
+
|
|
292
|
+
const pageContent = {
|
|
293
|
+
key: "page",
|
|
294
|
+
content: {
|
|
295
|
+
title: t({
|
|
296
|
+
en: "Welcome to React Router v7 + Intlayer",
|
|
297
|
+
es: "Bienvenido a React Router v7 + Intlayer",
|
|
298
|
+
fr: "Bienvenue sur React Router v7 + Intlayer",
|
|
299
|
+
}),
|
|
300
|
+
description: t({
|
|
301
|
+
en: "Build multilingual applications with ease using React Router v7 and Intlayer.",
|
|
302
|
+
es: "Cree aplicaciones multilingües fácilmente usando React Router v7 y Intlayer.",
|
|
303
|
+
fr: "Créez des applications multilingues facilement avec React Router v7 et Intlayer.",
|
|
304
|
+
}),
|
|
305
|
+
aboutLink: t({
|
|
306
|
+
en: "Learn About Us",
|
|
307
|
+
es: "Aprender Sobre Nosotros",
|
|
308
|
+
fr: "En savoir plus sur nous",
|
|
309
|
+
}),
|
|
310
|
+
},
|
|
311
|
+
} satisfies Dictionary;
|
|
312
|
+
|
|
313
|
+
export default pageContent;
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
```tsx fileName="app/routes/($locale).about.content.ts"
|
|
317
|
+
import { t, type Dictionary } from "intlayer";
|
|
318
|
+
|
|
319
|
+
const aboutContent = {
|
|
320
|
+
key: "about",
|
|
321
|
+
content: {
|
|
322
|
+
title: t({
|
|
323
|
+
en: "About Us",
|
|
324
|
+
es: "Sobre Nosotros",
|
|
325
|
+
fr: "À propos de nous",
|
|
326
|
+
}),
|
|
327
|
+
content: t({
|
|
328
|
+
en: "This is the about page content.",
|
|
329
|
+
es: "Este es el contenido de la página de información.",
|
|
330
|
+
fr: "Ceci est le contenu de la page à propos.",
|
|
331
|
+
}),
|
|
332
|
+
homeLink: t({
|
|
333
|
+
en: "Home",
|
|
334
|
+
es: "Inicio",
|
|
335
|
+
fr: "Accueil",
|
|
336
|
+
}),
|
|
337
|
+
},
|
|
338
|
+
} satisfies Dictionary;
|
|
339
|
+
|
|
340
|
+
export default aboutContent;
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
> Vos déclarations de contenu peuvent être définies n'importe où dans votre application dès qu'elles sont incluses dans le répertoire `contentDir` (par défaut, `./app`). Et correspondent à l'extension des fichiers de déclaration de contenu (par défaut, `.content.{json,ts,tsx,js,jsx,mjs,mjx,cjs,cjx}`).
|
|
344
|
+
|
|
345
|
+
> Pour plus de détails, référez-vous à la [documentation sur la déclaration de contenu](https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/dictionary/get_started.md).
|
|
346
|
+
|
|
347
|
+
### Étape 7 : Créez des composants sensibles à la locale
|
|
348
|
+
|
|
349
|
+
Créez un composant `LocalizedLink` pour la navigation sensible à la locale :
|
|
350
|
+
|
|
351
|
+
```tsx fileName="app/components/localized-link.tsx"
|
|
352
|
+
import type { FC } from "react";
|
|
353
|
+
|
|
354
|
+
import { getLocalizedUrl, type LocalesValues } from "intlayer";
|
|
355
|
+
import { useLocale } from "react-intlayer";
|
|
356
|
+
import { Link, type LinkProps, type To } from "react-router";
|
|
357
|
+
|
|
358
|
+
const isExternalLink = (to: string) => /^(https?:)?\/\//.test(to);
|
|
359
|
+
|
|
360
|
+
// Vérifie si le lien est externe
|
|
361
|
+
export const locacalizeTo = (to: To, locale: LocalesValues): To => {
|
|
362
|
+
if (typeof to === "string") {
|
|
363
|
+
if (isExternalLink(to)) {
|
|
364
|
+
return to;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
return getLocalizedUrl(to, locale);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (isExternalLink(to.pathname ?? "")) {
|
|
371
|
+
return to;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
return {
|
|
375
|
+
...to,
|
|
376
|
+
pathname: getLocalizedUrl(to.pathname ?? "", locale),
|
|
377
|
+
};
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
// Composant LocalizedLink pour la navigation locale
|
|
381
|
+
export const LocalizedLink: FC<LinkProps> = (props) => {
|
|
382
|
+
const { locale } = useLocale();
|
|
383
|
+
|
|
384
|
+
return <Link {...props} to={locacalizeTo(props.to, locale)} />;
|
|
385
|
+
};
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
Dans le cas où vous souhaitez naviguer vers les routes localisées, vous pouvez utiliser le hook `useLocalizedNavigate` :
|
|
389
|
+
|
|
390
|
+
```tsx fileName="app/hooks/useLocalizedNavigate.ts"
|
|
391
|
+
import { useLocale } from "react-intlayer";
|
|
392
|
+
import { type NavigateOptions, type To, useNavigate } from "react-router";
|
|
393
|
+
|
|
394
|
+
import { locacalizeTo } from "~/components/localized-link";
|
|
395
|
+
|
|
396
|
+
export const useLocalizedNavigate = () => {
|
|
397
|
+
const navigate = useNavigate();
|
|
398
|
+
const { locale } = useLocale();
|
|
399
|
+
|
|
400
|
+
const localizedNavigate = (to: To, options?: NavigateOptions) => {
|
|
401
|
+
const localedTo = locacalizeTo(to, locale);
|
|
402
|
+
|
|
403
|
+
navigate(localedTo, options);
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
return localizedNavigate;
|
|
407
|
+
};
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
### Étape 8 : Créer un composant de changement de langue
|
|
411
|
+
|
|
412
|
+
Créez un composant pour permettre aux utilisateurs de changer de langue :
|
|
413
|
+
|
|
414
|
+
```tsx fileName="app/components/locale-switcher.tsx"
|
|
415
|
+
import type { FC } from "react";
|
|
416
|
+
|
|
417
|
+
import {
|
|
418
|
+
getHTMLTextDir,
|
|
419
|
+
getLocaleName,
|
|
420
|
+
getLocalizedUrl,
|
|
421
|
+
getPathWithoutLocale,
|
|
422
|
+
Locales,
|
|
423
|
+
} from "intlayer";
|
|
424
|
+
import { useIntlayer, useLocale } from "react-intlayer";
|
|
425
|
+
import { Link, useLocation } from "react-router";
|
|
426
|
+
|
|
427
|
+
export const LocaleSwitcher: FC = () => {
|
|
428
|
+
const { localeSwitcherLabel } = useIntlayer("locale-switcher");
|
|
429
|
+
const { pathname } = useLocation();
|
|
430
|
+
|
|
431
|
+
const { availableLocales, locale } = useLocale();
|
|
432
|
+
|
|
433
|
+
const pathWithoutLocale = getPathWithoutLocale(pathname);
|
|
434
|
+
|
|
435
|
+
return (
|
|
436
|
+
<ol>
|
|
437
|
+
{availableLocales.map((localeItem) => (
|
|
438
|
+
<li key={localeItem}>
|
|
439
|
+
<Link
|
|
440
|
+
aria-current={localeItem === locale ? "page" : undefined}
|
|
441
|
+
aria-label={`${localeSwitcherLabel.value} ${getLocaleName(localeItem)}`}
|
|
442
|
+
reloadDocument // Recharger la page pour appliquer la nouvelle locale
|
|
443
|
+
to={getLocalizedUrl(pathWithoutLocale, localeItem)}
|
|
444
|
+
>
|
|
445
|
+
<span>
|
|
446
|
+
{/* Locale - par exemple FR */}
|
|
447
|
+
{localeItem}
|
|
448
|
+
</span>
|
|
449
|
+
<span>
|
|
450
|
+
{/* Langue dans sa propre locale - par exemple Français */}
|
|
451
|
+
{getLocaleName(localeItem, locale)}
|
|
452
|
+
</span>
|
|
453
|
+
<span dir={getHTMLTextDir(localeItem)} lang={localeItem}>
|
|
454
|
+
{/* Langue dans la locale actuelle - par exemple Francés avec la locale actuelle définie sur Locales.SPANISH */}
|
|
455
|
+
{getLocaleName(localeItem)}
|
|
456
|
+
</span>
|
|
457
|
+
<span dir="ltr" lang={Locales.ENGLISH}>
|
|
458
|
+
{/* Langue en anglais - par exemple French */}
|
|
459
|
+
{getLocaleName(localeItem, Locales.ENGLISH)}
|
|
460
|
+
</span>
|
|
461
|
+
</Link>
|
|
462
|
+
</li>
|
|
463
|
+
))}
|
|
464
|
+
</ol>
|
|
465
|
+
);
|
|
466
|
+
};
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
> Pour en savoir plus sur le hook `useLocale`, consultez la [documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/packages/react-intlayer/useLocale.md).
|
|
470
|
+
|
|
471
|
+
### Étape 9 : Ajouter la gestion des attributs HTML (optionnel)
|
|
472
|
+
|
|
473
|
+
Créez un hook pour gérer les attributs lang et dir du HTML :
|
|
474
|
+
|
|
475
|
+
```tsx fileName="app/hooks/useI18nHTMLAttributes.tsx"
|
|
476
|
+
import { getHTMLTextDir } from "intlayer";
|
|
477
|
+
import { useEffect } from "react";
|
|
478
|
+
import { useLocale } from "react-intlayer";
|
|
479
|
+
|
|
480
|
+
export const useI18nHTMLAttributes = () => {
|
|
481
|
+
const { locale } = useLocale();
|
|
482
|
+
|
|
483
|
+
useEffect(() => {
|
|
484
|
+
document.documentElement.lang = locale;
|
|
485
|
+
document.documentElement.dir = getHTMLTextDir(locale);
|
|
486
|
+
}, [locale]);
|
|
487
|
+
};
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
Ce hook est déjà utilisé dans le composant de mise en page (`($locale)._layout.tsx`) montré à l'Étape 5.
|
|
491
|
+
|
|
492
|
+
### Étape 10 : Ajouter un middleware (Optionnel)
|
|
493
|
+
|
|
494
|
+
Vous pouvez également utiliser le `intlayerProxy` pour ajouter un routage côté serveur à votre application. Ce plugin détectera automatiquement la locale actuelle en fonction de l'URL et définira le cookie de locale approprié. Si aucune locale n'est spécifiée, le plugin déterminera la locale la plus appropriée en fonction des préférences linguistiques du navigateur de l'utilisateur. Si aucune locale n'est détectée, il redirigera vers la locale par défaut.
|
|
495
|
+
|
|
496
|
+
> Notez que pour utiliser le `intlayerProxy` en production, vous devez déplacer le package `vite-intlayer` de `devDependencies` vers `dependencies`.
|
|
497
|
+
|
|
498
|
+
```typescript {3,7} fileName="vite.config.ts"
|
|
499
|
+
import { reactRouter } from "@react-router/dev/vite";
|
|
500
|
+
import { defineConfig } from "vite";
|
|
501
|
+
import { intlayer, intlayerProxy } from "vite-intlayer";
|
|
502
|
+
import tsconfigPaths from "vite-tsconfig-paths";
|
|
503
|
+
|
|
504
|
+
export default defineConfig({
|
|
505
|
+
plugins: [reactRouter(), tsconfigPaths(), intlayer(), intlayerProxy()],
|
|
506
|
+
});
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
---
|
|
510
|
+
|
|
511
|
+
## Configurer TypeScript
|
|
512
|
+
|
|
513
|
+
Intlayer utilise l'augmentation de module pour bénéficier de TypeScript et renforcer votre base de code.
|
|
514
|
+
|
|
515
|
+
Assurez-vous que votre configuration TypeScript inclut les types générés automatiquement :
|
|
516
|
+
|
|
517
|
+
```json5 fileName="tsconfig.json"
|
|
518
|
+
{
|
|
519
|
+
// ... vos configurations existantes
|
|
520
|
+
include: [
|
|
521
|
+
// ... vos inclusions existantes
|
|
522
|
+
".intlayer/**/*.ts", // Inclure les types générés automatiquement
|
|
523
|
+
],
|
|
524
|
+
}
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
---
|
|
528
|
+
|
|
529
|
+
## Configuration Git
|
|
530
|
+
|
|
531
|
+
Il est recommandé d'ignorer les fichiers générés par Intlayer. Cela vous permet d'éviter de les commettre dans votre dépôt Git.
|
|
532
|
+
|
|
533
|
+
Pour ce faire, vous pouvez ajouter les instructions suivantes à votre fichier `.gitignore` :
|
|
534
|
+
|
|
535
|
+
```plaintext fileName=".gitignore"
|
|
536
|
+
# Ignorer les fichiers générés par Intlayer
|
|
537
|
+
.intlayer
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
---
|
|
541
|
+
|
|
542
|
+
## Extension VS Code
|
|
543
|
+
|
|
544
|
+
Pour améliorer votre expérience de développement avec Intlayer, vous pouvez installer l’**extension officielle Intlayer pour VS Code**.
|
|
545
|
+
|
|
546
|
+
[Installer depuis le Marketplace VS Code](https://marketplace.visualstudio.com/items?itemName=intlayer.intlayer-vs-code-extension)
|
|
547
|
+
|
|
548
|
+
Cette extension offre :
|
|
549
|
+
|
|
550
|
+
- **L’autocomplétion** pour les clés de traduction.
|
|
551
|
+
- **La détection d’erreurs en temps réel** pour les traductions manquantes.
|
|
552
|
+
- **Des aperçus en ligne** du contenu traduit.
|
|
553
|
+
- **Des actions rapides** pour créer et mettre à jour facilement les traductions.
|
|
554
|
+
|
|
555
|
+
Pour plus de détails sur l’utilisation de l’extension, consultez la [documentation de l’extension Intlayer pour VS Code](https://intlayer.org/doc/vs-code-extension).
|
|
556
|
+
|
|
557
|
+
---
|
|
558
|
+
|
|
559
|
+
## Aller plus loin
|
|
560
|
+
|
|
561
|
+
Pour aller plus loin, vous pouvez implémenter l’[éditeur visuel](https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/intlayer_visual_editor.md) ou externaliser votre contenu en utilisant le [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/intlayer_CMS.md).
|
|
562
|
+
|
|
563
|
+
---
|
|
564
|
+
|
|
565
|
+
## Références de la documentation
|
|
566
|
+
|
|
567
|
+
- [Documentation Intlayer](https://intlayer.org)
|
|
568
|
+
- [Documentation React Router v7](https://reactrouter.com/)
|
|
569
|
+
- [Hook useIntlayer](https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/packages/react-intlayer/useIntlayer.md)
|
|
570
|
+
- [Hook useLocale](https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/packages/react-intlayer/useLocale.md)
|
|
571
|
+
- [Déclaration de contenu](https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/dictionary/get_started.md)
|
|
572
|
+
- [Configuration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/fr/configuration.md)
|
|
573
|
+
|
|
574
|
+
Ce guide complet vous fournit tout ce dont vous avez besoin pour intégrer Intlayer avec React Router v7 afin d’obtenir une application entièrement internationalisée avec un routage sensible à la locale et une prise en charge de TypeScript.
|